use of org.apache.jena.query.Dataset in project jena by apache.
the class TestDatasetConnectionMetadata method getConnection.
@Override
protected JenaConnection getConnection() throws SQLException {
Dataset ds = supportsSerializable ? DatasetFactory.createTxnMem() : DatasetFactory.create();
int transactionLevelSupported = supportsSerializable ? JenaConnection.TRANSACTION_SERIALIZABLE : JenaConnection.TRANSACTION_NONE;
return new MemConnection(ds, JenaConnection.DEFAULT_HOLDABILITY, JenaConnection.DEFAULT_AUTO_COMMIT, transactionLevelSupported, JdbcCompatibility.DEFAULT);
}
use of org.apache.jena.query.Dataset in project jena by apache.
the class TDBDriver method connect.
@Override
protected JenaConnection connect(Properties props, int compatibilityLevel) throws SQLException {
String location = props.getProperty(PARAM_LOCATION);
if (location == null)
throw new SQLException("Required connection parameter " + PARAM_LOCATION + " is not present in the connection URL or the provided Properties object");
// Determine location
boolean useMem = this.isSetToValue(props, PARAM_LOCATION, LOCATION_MEM);
File loc = new File(location);
if (useMem) {
LOGGER.warn("TDB Driver connection string specifies use of a pure in-memory dataset, this is not recommended for anything other than basic testing");
} else {
if (!loc.isAbsolute()) {
LOGGER.warn("TDB Driver connection string specifies location " + loc.getAbsolutePath() + ", if this was not the expected location consider using an absolute instead of a relative path");
} else {
LOGGER.info("TDB Driver connection string specifies location " + loc.getAbsolutePath());
}
}
// Validate location if required
if (this.isTrue(props, PARAM_MUST_EXIST) && !useMem) {
if (!loc.exists()) {
throw new SQLException("TDB Driver connection string specifies location " + loc.getAbsolutePath() + " which does not exist, correct the " + PARAM_LOCATION + " parameter or set the " + PARAM_MUST_EXIST + " parameter to false");
} else if (!loc.isDirectory()) {
throw new SQLException("TDB Driver connection string specifies location " + loc.getAbsolutePath() + " which is not a directory, correct the " + PARAM_LOCATION + " parameter or set the " + PARAM_MUST_EXIST + " parameter to false");
}
}
// Open the TDB dataset
try {
Dataset tdb = useMem ? TDBFactory.createDataset() : TDBFactory.createDataset(location);
// Return a new connection for the TDB dataset
return new TDBConnection(tdb, ResultSet.HOLD_CURSORS_OVER_COMMIT, true, compatibilityLevel);
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new SQLException("Unexpected error establishing TDB driver connection, see inner exception for details", e);
}
}
use of org.apache.jena.query.Dataset in project jena by apache.
the class TestTdbDiskResultSets method results_ask_true.
/**
* Test ASK results with a true result
*
* @throws SQLException
*/
@Test
public void results_ask_true() throws SQLException {
Dataset ds = createDataset(tempDir.getRoot().getAbsolutePath());
try (DebugTdbConnection connection = new DebugTdbConnection(ds)) {
Statement stmt = connection.createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY);
ResultSet rset = stmt.executeQuery("ASK { }");
assertNotNull(rset);
assertFalse(rset.isClosed());
assertTrue(rset.isBeforeFirst());
// Try to move to the result row
assertTrue(rset.next());
// Check the boolean return value
assertTrue(rset.getBoolean(COLUMN_LABEL_ASK));
// Check no further rows
assertFalse(rset.next());
assertTrue(rset.isAfterLast());
// Close and clean up
rset.close();
assertTrue(rset.isClosed());
}
}
use of org.apache.jena.query.Dataset in project jena by apache.
the class TestTdbMemResultSets method prepareDataset.
@Override
protected Dataset prepareDataset(Dataset ds) {
if (currDataset != null) {
currDataset.close();
}
Dataset tdb = TDBFactory.createDataset();
TestUtils.copyDataset(ds, tdb, true);
currDataset = tdb;
return tdb;
}
use of org.apache.jena.query.Dataset in project jena by apache.
the class AbstractStoreConnections method store_7.
@Test
public void store_7() {
// No transaction, plain update, then transaction.
// This tests that the dataset is sync'ed when going into transactional mode.
boolean nonTxnData = true;
StoreConnection sConn = getStoreConnection();
Location loc = sConn.getLocation();
DatasetGraph dsg = sConn.getBaseDataset();
if (nonTxnData) {
dsg.add(q);
TDB.sync(dsg);
assertTrue(dsg.contains(q));
}
DatasetGraphTxn dsgTxn = sConn.begin(ReadWrite.WRITE);
if (nonTxnData)
assertTrue(dsgTxn.contains(q));
dsgTxn.add(q1);
assertTrue(dsgTxn.contains(q1));
if (nonTxnData)
assertTrue(dsgTxn.contains(q));
dsgTxn.commit();
dsgTxn.end();
// Should have flushed to disk.
if (nonTxnData) {
sConn.forceRecoverFromJournal();
assertTrue(dsg.contains(q));
}
assertTrue(dsg.contains(q1));
// release via the transactional machinery
StoreConnection.release(loc);
sConn = null;
StoreConnection sConn2 = StoreConnection.make(loc);
DatasetGraph dsg2 = sConn2.getBaseDataset();
if (nonTxnData)
assertTrue(dsg2.contains(q));
assertTrue(dsg2.contains(q1));
DatasetGraphTxn dsgTxn2 = sConn2.begin(ReadWrite.READ);
if (nonTxnData)
assertTrue(dsgTxn2.contains(q));
assertTrue(dsgTxn2.contains(q1));
dsgTxn2.end();
// Check API methods work.
Dataset ds = TDBFactory.createDataset(loc);
ds.begin(ReadWrite.READ);
Model m = (q.isDefaultGraph() ? ds.getDefaultModel() : ds.getNamedModel("g"));
assertEquals(nonTxnData ? 2 : 1, m.size());
ds.end();
}
Aggregations