/** Stop managing a location. There should be no transactions running. */ public static synchronized void release(Location location) { expel(location, false); }
/** Set the {@link StoreParams} for specific Location. * This call must only be called before a dataset from Location * is created. This operation should be used with care; bad choices * of {@link StoreParams} can reduce performance. * * <a href="http://jena.apache.org/documentation/tdb/store-parameters.html">See documentation</a>. * * @param location The persistent storage location * @param params StoreParams to use * @throws IllegalStateException If the dataset has already been setup. */ public static void setup(Location location, StoreParams params) { StoreConnection sConn = StoreConnection.getExisting(location) ; if ( sConn != null ) throw new IllegalStateException("Location is already active") ; StoreConnection.make(location, params) ; } }
/** * Release any and all system resources held by TDB. This does NOT close or * release datasets or graphs held by client code. */ public static void closedown() { StoreConnection.reset() ; }
public void syncIfNotTransactional() { if ( !sConn.haveUsedInTransaction() ) sConn.getBaseDataset().sync() ; }
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(); } }
@Test public void params_reconnect_01() { // Create. StoreConnection.make(loc, null) ; // Drop. StoreConnection.expel(loc, true) ; // Reconnect StoreConnection.make(loc, null) ; StoreParams pLoc = StoreParamsCodec.read(loc) ; assertNull(pLoc) ; StoreParams pDB = StoreConnection.getExisting(loc).getBaseDataset().getConfig().params ; assertNotNull(pDB) ; // Should be the default setup. assertTrue(StoreParams.sameValues(pDft, pDB)) ; }
@Test public void store_6() { // Transaction - release - reattach // This tests that the dataset is sync'ed when going into transactional mode. StoreConnection sConn = getStoreConnection() ; Location loc = sConn.getLocation() ; DatasetGraphTxn dsgTxn = sConn.begin(TxnType.WRITE) ; dsgTxn.add(q1) ; assertTrue(dsgTxn.contains(q1)) ; dsgTxn.commit() ; dsgTxn.end() ; sConn.forceRecoverFromJournal() ; assertTrue(sConn.getBaseDataset().contains(q1)) ; StoreConnection.release(loc) ; sConn = StoreConnection.make(loc) ; DatasetGraph dsg2 = sConn.getBaseDataset() ; assertTrue(dsg2.contains(q1)) ; DatasetGraphTxn dsgTxn2 = sConn.begin(TxnType.READ) ; assertTrue(dsgTxn2.contains(q1)) ; dsgTxn2.end() ; }
@Test public void store_0() { // Expel. StoreConnection sConn = getStoreConnection() ; assertTrue(sConn.isValid()); DatasetGraphTxn dsgW1 = sConn.begin(TxnType.WRITE) ; dsgW1.commit() ; dsgW1.end() ; StoreConnection.release(sConn.getLocation()) ; StoreConnection sConn2 = getStoreConnection() ; }
@Test(expected = TDBTransactionException.class) public void store_2() { // Expel. StoreConnection sConn = getStoreConnection() ; DatasetGraphTxn dsgR1 = sConn.begin(TxnType.READ) ; StoreConnection.release(sConn.getLocation()) ; }
@Test public void store_5() { // No transaction. Make sure StoreConnection.release cleans up OK. StoreConnection sConn = getStoreConnection() ; Location loc = sConn.getLocation() ; DatasetGraph dsg = sConn.getBaseDataset() ; dsg.add(q) ; assertTrue(dsg.contains(q)) ; StoreConnection.release(loc) ; sConn = StoreConnection.make(loc) ; dsg = sConn.getBaseDataset() ; assertTrue(dsg.contains(q)) ; }
@Test public void trans_readBlock_10() { // READ(start)-WRITE(start)-WRITE(finish)-WRITE(start)-READ(finish)-WRITE(finish)-check StoreConnection sConn = getStoreConnection() ; DatasetGraphTxn dsgR1 = sConn.begin(TxnType.READ) ; DatasetGraphTxn dsgW1 = sConn.begin(TxnType.WRITE) ; dsgW1.add(q1) ; dsgW1.commit() ; dsgW1.end() ; DatasetGraphTxn dsgW2 = sConn.begin(TxnType.WRITE) ; dsgW2.add(q2) ; dsgR1.end() ; dsgW2.commit() ; dsgW2.end() ; sConn.forceRecoverFromJournal() ; DatasetGraphTDB dsg = sConn.getBaseDataset() ; assertTrue(dsg.contains(q1)) ; assertTrue(dsg.contains(q2)) ; }
@Test public void trans_readBlock_01() { // READ(start)-WRITE(commit)-READ(finish)-check StoreConnection sConn = getStoreConnection() ; DatasetGraphTxn dsgR1 = sConn.begin(TxnType.READ) ; DatasetGraphTxn dsgW = sConn.begin(TxnType.WRITE) ; dsgW.add(q) ; dsgW.commit() ; dsgW.end() ; assertFalse(dsgR1.contains(q)) ; dsgR1.end() ; DatasetGraphTxn dsgR2 = sConn.begin(TxnType.READ) ; assertTrue(dsgR2.contains(q)) ; dsgR2.end() ; sConn.flush() ; DatasetGraph dsg = sConn.getBaseDataset() ; assertTrue(dsg.contains(q)) ; }
@Test public void testTxn() { assertEquals (3, countRDFNodes()) ; StoreConnection sc = StoreConnection.make(location) ; DatasetGraphTxn dsg = sc.begin(TxnType.WRITE) ; assertTrue(dsg.contains(quad1)) ; dsg.add(quad2) ; dsg.commit() ; dsg.end() ; StoreConnection.release(location) ; assertEquals (4, countRDFNodes()) ; }
/** Make a StoreConnection based on any StoreParams at the location or the system defaults. */ public static StoreConnection make(Location location) { return make(location, null) ; }
@Override protected synchronized void _close() { if ( isClosed ) return ; if ( sConn.haveUsedInTransaction() ) { if ( isInTransaction() ) { TDB.logInfo.warn("Attempt to close a DatasetGraphTransaction while a transaction is active - ignored close (" + getLocation() + ")") ; return ; } // Otherwise ignore - close() while transactional is meaningless. return ; } synchronized(this) { if ( ! sConn.isValid() ) { // There may be another DatasetGraphTransaction using this location // and that DatasetGraphTransaction has been closed, invalidating // the StoreConnection. return ; } DatasetGraphTDB dsg = sConn.getBaseDataset() ; dsg.sync() ; dsg.close() ; StoreConnection.release(getLocation()) ; dsgtxn.remove() ; inTransaction.remove() ; isClosed = true ; return ; } }
/** * @deprecated Use {@link #begin(TxnType)} */ @Deprecated public DatasetGraphTxn begin(ReadWrite mode) { return begin(TxnType.convert(mode)); }
/** * Release a {@code Location}. * Do not use a {@code Dataset} at this location without * remaking it via {@link TDBFactory}. */ public static void releaseLocation(Location location) { StoreConnection.release(location) ; }
/** Look at a directory and see if it is a new area */ public static boolean isNewDatabaseArea(Location location) { StoreConnection sConn = StoreConnection.getExisting(location) ; if ( sConn != null ) // Already has a StoreConnection return false ; if ( location.isMem() ) return true ; File d = new File(location.getDirectoryPath()) ; if ( !d.exists() ) return true ; FileFilter ff = fileFilterNewDB ; File[] entries = d.listFiles(ff) ; return entries.length == 0 ; }
@Test public void trans_readBlock_02() { // READ(start)-WRITE(abort)-READ(finish)-check StoreConnection sConn = getStoreConnection() ; DatasetGraphTxn dsgR1 = sConn.begin(TxnType.READ) ; DatasetGraphTxn dsgW = sConn.begin(TxnType.WRITE) ; dsgW.add(q) ; dsgW.abort() ; dsgW.end() ; assertFalse(dsgR1.contains(q)) ; dsgR1.end() ; DatasetGraphTxn dsgR2 = sConn.begin(TxnType.READ) ; assertFalse(dsgR2.contains(q)) ; dsgR2.end() ; DatasetGraph dsg = sConn.getBaseDataset() ; assertFalse(dsg.contains(q)) ; }