@Override public void abortTx() { commitTx(true); // throw new // Error("An UnsafeSingleThreaded transaction cannot abort. I've committed it instead."); }
@Override protected void doCommit() { // the commit is already done, so create a new ActiveTransactionsRecord for (Map.Entry<PerTxBox, Object> entry : this.perTxValues.entrySet()) { entry.getKey().commit(entry.getValue()); } ActiveTransactionsRecord newRecord = new ActiveTransactionsRecord(getNumber(), WriteSet.empty()); newRecord.setCommitted(); setMostRecentCommittedRecord(newRecord); if (!this.activeTxRecord.trySetNext(newRecord)) { throw new Error("Unacceptable: UnsafeSingleThreadedTransaction in a concurrent environment"); } // we must update the activeRecords accordingly context().oldestRequiredVersion = newRecord; this.activeTxRecord = newRecord; }
@Override public void start() { // once we get here, we may already increment the transaction // number int newTxNumber = this.activeTxRecord.transactionNumber + 1; // renumber the TX to the new number setNumber(newTxNumber); super.start(); }
/** Warning: this method has limited usability. See the UnsafeSingleThreaded class for * details */ public static Transaction beginUnsafeSingleThreaded() { Transaction parent = current.get(); if (parent != null) { throw new Error("Unsafe single-threaded transactions cannot be nested"); } ActiveTransactionsRecord activeRecord = getRecordForNewTransaction(); Transaction tx = new UnsafeSingleThreadedTransaction(activeRecord); tx.start(); return tx; }
@Override protected Transaction commitAndBeginTx(boolean readOnly) { commitTx(true); return Transaction.beginUnsafeSingleThreaded(); }