Search in sources :

Example 1 with TDBConnection

use of org.apache.jena.jdbc.tdb.connections.TDBConnection 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 2 with TDBConnection

use of org.apache.jena.jdbc.tdb.connections.TDBConnection 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 3 with TDBConnection

use of org.apache.jena.jdbc.tdb.connections.TDBConnection 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)

Aggregations

TDBConnection (org.apache.jena.jdbc.tdb.connections.TDBConnection)3 Dataset (org.apache.jena.query.Dataset)3 File (java.io.File)1 SQLException (java.sql.SQLException)1