use of org.apache.jena.query.Dataset in project jena by apache.
the class TestTdbMemConnection method getConnection.
@Override
protected JenaConnection getConnection(Dataset ds) throws SQLException {
Dataset tdb = TDBFactory.createDataset();
TestUtils.copyDataset(ds, tdb, true);
return new TDBConnection(tdb, ResultSet.HOLD_CURSORS_OVER_COMMIT, JenaConnection.DEFAULT_AUTO_COMMIT, JdbcCompatibility.DEFAULT);
}
use of org.apache.jena.query.Dataset in project jena by apache.
the class TestTdbDiskResultSets method results_ask_false.
/**
* Test ASK results with a false result
*
* @throws SQLException
*/
@Test
public void results_ask_false() 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 { FILTER(false) }");
assertNotNull(rset);
assertFalse(rset.isClosed());
assertTrue(rset.isBeforeFirst());
// Try to move to the result row
assertTrue(rset.next());
// Check the boolean return value
assertFalse(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 TestTdbDiskConnection method getConnection.
@Override
protected JenaConnection getConnection(Dataset ds) throws SQLException {
Dataset tdb = TDBFactory.createDataset(tempDir.getRoot().getAbsolutePath());
TestUtils.copyDataset(ds, tdb, true);
return new TDBConnection(tdb, ResultSet.HOLD_CURSORS_OVER_COMMIT, JenaConnection.DEFAULT_AUTO_COMMIT, JdbcCompatibility.DEFAULT);
}
use of org.apache.jena.query.Dataset in project jena by apache.
the class TestUtils method generateDataset.
/**
* Generates a synthetic dataset for testing
*
* @param numGraphs
* Number of graphs to generate
* @param triplesPerGraph
* Triples per graph
* @param createDefaultGraph
* Whether to generate a default graph
* @return Synthetic dataset
*/
public static Dataset generateDataset(int numGraphs, int triplesPerGraph, boolean createDefaultGraph) {
if (numGraphs <= 0)
throw new IllegalArgumentException("Number of graphs must be >= 1");
if (triplesPerGraph <= 0)
throw new IllegalArgumentException("Number of triples per graph must be >= 1");
Dataset ds = DatasetFactory.createTxnMem();
if (createDefaultGraph) {
numGraphs--;
Model def = ModelFactory.createDefaultModel();
for (int i = 1; i <= triplesPerGraph; i++) {
def.add(def.createStatement(def.createResource("http://default/subject/" + i), def.createProperty("http://default/predicate"), def.createTypedLiteral(i)));
}
ds.setDefaultModel(def);
}
for (int g = 1; g < numGraphs; g++) {
Model named = ModelFactory.createDefaultModel();
for (int i = 1; i <= triplesPerGraph; i++) {
named.add(named.createStatement(named.createResource("http://named/subject/" + i), named.createProperty("http://named/predicate"), named.createTypedLiteral(i)));
}
ds.addNamedModel("http://named/" + g, named);
}
return ds;
}
use of org.apache.jena.query.Dataset in project jena by apache.
the class MemDriver method connect.
@Override
protected JenaConnection connect(Properties props, int compatibilityLevel) throws SQLException {
Object dsObj = props.get(PARAM_DATASET);
String empty = props.getProperty(PARAM_EMPTY);
if (dsObj == null && empty == null)
throw new SQLException("Neither one of the " + PARAM_DATASET + " or " + PARAM_EMPTY + " connection parameters is present in the JDBC Connection URL or the provided Properties object");
if (dsObj != null) {
if (dsObj instanceof Dataset) {
// Dataset provided directly
return new MemConnection((Dataset) dsObj, JenaConnection.DEFAULT_HOLDABILITY, JenaConnection.DEFAULT_AUTO_COMMIT, JenaConnection.DEFAULT_ISOLATION_LEVEL, compatibilityLevel);
} else {
// Load dataset from a file
try {
Dataset ds = DatasetFactory.createMem();
RDFDataMgr.read(ds, dsObj.toString());
return new MemConnection(ds, JenaConnection.DEFAULT_HOLDABILITY, JenaConnection.DEFAULT_AUTO_COMMIT, JenaConnection.DEFAULT_ISOLATION_LEVEL, compatibilityLevel);
} catch (Exception e) {
throw new SQLException("Error occurred while reading from the specified RDF dataset file - " + dsObj.toString(), e);
}
}
} else if (this.isTrue(props, PARAM_EMPTY)) {
// Use an empty dataset
return new MemConnection(DatasetFactory.createMem(), JenaConnection.DEFAULT_HOLDABILITY, JenaConnection.DEFAULT_AUTO_COMMIT, JenaConnection.DEFAULT_ISOLATION_LEVEL, compatibilityLevel);
} else {
throw new SQLException("Insufficient parameters to create a Jena JDBC in-memory connection, please supply a Dataset file/instance via the " + PARAM_DATASET + " parameter or supply " + PARAM_EMPTY + "=true to connect to a new empty dataset");
}
}
Aggregations