@Override protected void _abort() { checkNotClosed() ; dsgtxn.get().abort() ; inTransaction.set(false) ; }
private DatasetGraphTxn createDSGTxn(DatasetGraphTDB dsg, Transaction txn, ReadWrite mode) { // A read transaction (if it has no lifecycle components) can be shared over all // read transactions at the same commit level. // lastreader if ( mode == ReadWrite.READ ) { // If a READ transaction, and a previously built one is cached, use it. DatasetGraphTDB dsgCached = currentReaderView.get() ; if ( dsgCached != null ) { // No components so we don't need to notify them. // We can just reuse the storage dataset. return new DatasetGraphTxn(dsgCached, txn) ; } } DatasetGraphTxn dsgTxn = new DatasetBuilderTxn(this, dsg).build(txn, mode); if ( mode == ReadWrite.READ ) { // If a READ transaction, cache the storage view. // This is cleared when a WRITE commits currentReaderView.set(dsgTxn.getView()) ; } return dsgTxn ; }
DatasetGraphTxn build(Transaction txn, ReadWrite mode) { this.txn = txn; DatasetGraphTDB dsgTDB ; switch(mode) { case READ : dsgTDB = buildReadonly() ; break ; case WRITE : dsgTDB = buildWritable() ; break ; default: dsgTDB = null ; } DatasetGraphTxn dsgTxn = new DatasetGraphTxn(dsgTDB, txn) ; // Copy context. Changes not propagated back to the base dataset. dsgTxn.getContext().putAll(dsg.getContext()) ; return dsgTxn ; }
@Test public void store_4() { StoreConnection sConn = getStoreConnection() ; DatasetGraphTxn dsgR1 = sConn.begin(TxnType.READ) ; DatasetGraphTxn dsgW1 = sConn.begin(TxnType.WRITE) ; dsgW1.add(q1) ; dsgW1.commit() ; dsgW1.end() ; dsgR1.end() ; StoreConnection.release(sConn.getLocation()) ; sConn = null ; StoreConnection sConn2 = getStoreConnection() ; DatasetGraphTxn dsgW2 = sConn2.begin(TxnType.WRITE) ; dsgW2.add(q2) ; dsgW2.commit() ; dsgW2.end() ; DatasetGraphTxn dsgR2 = sConn2.begin(TxnType.READ) ; long x = Iter.count(dsgR2.find()) ; assertEquals(2, x) ; }
@Override protected void _end() { checkNotClosed() ; DatasetGraphTxn dsg = dsgtxn.get() ; // It's null if end() already called. if ( dsg == null ) { TDB.logInfo.warn("Transaction already ended") ; return ; } try { // begin(W)..end() throws an exception. dsgtxn.get().end() ; } finally { // May already be false due to .commit/.abort. inTransaction.set(false) ; dsgtxn.set(null) ; } }
/*package*/ void setActiveDataset(DatasetGraphTxn activedsg) { this.activedsg = activedsg ; if ( activedsg.getTransaction() != this ) Log.warn(this, "Active DSG does not point to this transaction; "+this) ; }
@Override protected void _commit() { checkNotClosed() ; dsgtxn.get().commit() ; inTransaction.set(false) ; }
@Test (expected=TDBException.class) public void trans_21() { // READ-add StoreConnection sConn = getStoreConnection() ; DatasetGraphTxn dsg = sConn.begin(TxnType.READ) ; dsg.add(q) ; }
private DatasetGraphTDB determineBaseDataset() { // if ( DEBUG ) { // if ( !commitedAwaitingFlush.isEmpty() ) // System.out.print(commitedAwaitingFlush.size()) ; // } else { // System.out.print('_') ; // } DatasetGraphTDB dsg = baseDataset ; // But, if there are pending, committed transactions, use latest. if ( !commitedAwaitingFlush.isEmpty() ) dsg = commitedAwaitingFlush.get(commitedAwaitingFlush.size() - 1).getActiveDataset().getView() ; return dsg ; } private Transaction createTransaction(DatasetGraphTDB dsg, TxnType txnType, TxnType originalTxnType, String label) {
@Test public void store_4() { StoreConnection sConn = getStoreConnection() ; DatasetGraphTxn dsgR1 = sConn.begin(TxnType.READ) ; DatasetGraphTxn dsgW1 = sConn.begin(TxnType.WRITE) ; dsgW1.add(q1) ; dsgW1.commit() ; dsgW1.end() ; dsgR1.end() ; StoreConnection.release(sConn.getLocation()) ; sConn = null ; StoreConnection sConn2 = getStoreConnection() ; DatasetGraphTxn dsgW2 = sConn2.begin(TxnType.WRITE) ; dsgW2.add(q2) ; dsgW2.commit() ; dsgW2.end() ; DatasetGraphTxn dsgR2 = sConn2.begin(TxnType.READ) ; long x = Iter.count(dsgR2.find()) ; assertEquals(2, x) ; }
public static void backup(Location location, OutputStream backupfile) { Dataset ds = TDBFactory.createDataset(location) ; StoreConnection sConn = StoreConnection.make(location) ; DatasetGraphTxn dsg = sConn.begin(TxnType.READ, "backup") ; RDFDataMgr.write(backupfile, dsg, Lang.NQUADS) ; dsg.end(); } }
private DatasetGraphTxn promoteExec$(DatasetGraphTxn dsgtxn, TxnType originalTxnType) { // Use begin$ (not beginInternal) // We have the writers lock. // We keep the exclusivity lock. Transaction txn = dsgtxn.getTransaction() ; DatasetGraphTxn dsgtxn2 = begin$(TxnType.WRITE, originalTxnType, txn.getLabel()) ; noteTxnPromote(txn, dsgtxn2.getTransaction()); return dsgtxn2 ; }
@Test (expected=TDBException.class) public void trans_21() { // READ-add StoreConnection sConn = getStoreConnection() ; DatasetGraphTxn dsg = sConn.begin(TxnType.READ) ; dsg.add(q) ; }