Search in sources :

Example 76 with Dataset

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);
}
Also used : Dataset(org.apache.jena.query.Dataset) TDBConnection(org.apache.jena.jdbc.tdb.connections.TDBConnection)

Example 77 with Dataset

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());
    }
}
Also used : TDBFactory.createDataset(org.apache.jena.tdb.TDBFactory.createDataset) Dataset(org.apache.jena.query.Dataset) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) DebugTdbConnection(org.apache.jena.jdbc.tdb.connections.DebugTdbConnection) Test(org.junit.Test)

Example 78 with Dataset

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);
}
Also used : Dataset(org.apache.jena.query.Dataset) TDBConnection(org.apache.jena.jdbc.tdb.connections.TDBConnection)

Example 79 with Dataset

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;
}
Also used : Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model)

Example 80 with Dataset

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");
    }
}
Also used : SQLException(java.sql.SQLException) Dataset(org.apache.jena.query.Dataset) MemConnection(org.apache.jena.jdbc.mem.connections.MemConnection) SQLException(java.sql.SQLException)

Aggregations

Dataset (org.apache.jena.query.Dataset)138 Test (org.junit.Test)63 BaseTest (org.apache.jena.atlas.junit.BaseTest)39 Model (org.apache.jena.rdf.model.Model)31 Resource (org.apache.jena.rdf.model.Resource)20 Node (org.apache.jena.graph.Node)13 RDFNode (org.apache.jena.rdf.model.RDFNode)8 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)7 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)7 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)7 ConfigTest (org.apache.jena.tdb.ConfigTest)7 CmdException (jena.cmd.CmdException)6 Graph (org.apache.jena.graph.Graph)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5 JenaTransactionException (org.apache.jena.sparql.JenaTransactionException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Path (java.nio.file.Path)4 Property (org.apache.jena.rdf.model.Property)4 OutputStream (java.io.OutputStream)3 Triple (org.apache.jena.graph.Triple)3