Search in sources :

Example 56 with Dataset

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

Example 57 with Dataset

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

Example 58 with Dataset

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());
    }
}
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 59 with Dataset

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

Example 60 with Dataset

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();
}
Also used : StoreConnection(org.apache.jena.tdb.StoreConnection) Dataset(org.apache.jena.query.Dataset) DatasetGraphTxn(org.apache.jena.tdb.transaction.DatasetGraphTxn) Model(org.apache.jena.rdf.model.Model) Location(org.apache.jena.tdb.base.file.Location) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) ConfigTest(org.apache.jena.tdb.ConfigTest) BaseTest(org.apache.jena.atlas.junit.BaseTest)

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