Search in sources :

Example 1 with SQLiteConnectionPoolDataSource

use of org.sqlite.javax.SQLiteConnectionPoolDataSource in project formplayer by dimagi.

the class SqlSandboxUtils method getDataSource.

public static SQLiteConnectionPoolDataSource getDataSource(File databasePath) {
    try {
        Class.forName("org.sqlite.JDBC");
        SQLiteConnectionPoolDataSource dataSource = new SQLiteConnectionPoolDataSource();
        dataSource.setUrl("jdbc:sqlite:" + databasePath.getPath() + "?journal_mode=MEMORY");
        return dataSource;
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : SQLiteConnectionPoolDataSource(org.sqlite.javax.SQLiteConnectionPoolDataSource)

Example 2 with SQLiteConnectionPoolDataSource

use of org.sqlite.javax.SQLiteConnectionPoolDataSource in project atlasdb by palantir.

the class SqliteConnections method getPooledDataSource.

public static HikariDataSource getPooledDataSource(Path path, SqliteConnectionConfig sqliteConnectionConfig) {
    createDirectoryIfNotExists(path);
    String target = String.format("jdbc:sqlite:%s", path.resolve(DEFAULT_SQLITE_DATABASE_NAME).toString());
    SQLiteConfig config = new SQLiteConfig();
    config.setPragma(SQLiteConfig.Pragma.JOURNAL_MODE, SQLiteConfig.JournalMode.WAL.getValue());
    config.setPragma(SQLiteConfig.Pragma.LOCKING_MODE, SQLiteConfig.LockingMode.EXCLUSIVE.getValue());
    config.setPragma(SQLiteConfig.Pragma.SYNCHRONOUS, "EXTRA");
    SQLiteConnectionPoolDataSource dataSource = new SQLiteConnectionPoolDataSource();
    dataSource.setUrl(target);
    dataSource.setConfig(config);
    HikariConfig hikariConfig = sqliteConnectionConfig.getHikariConfig();
    hikariConfig.setDataSource(dataSource);
    return new HikariDataSource(hikariConfig);
}
Also used : SQLiteConnectionPoolDataSource(org.sqlite.javax.SQLiteConnectionPoolDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) SQLiteConfig(org.sqlite.SQLiteConfig) HikariConfig(com.zaxxer.hikari.HikariConfig)

Example 3 with SQLiteConnectionPoolDataSource

use of org.sqlite.javax.SQLiteConnectionPoolDataSource in project sqlite-jdbc by xerial.

the class SQLiteConnectionPoolDataSourceTest method proxyConnectionCloseTest.

@Disabled
@Test
public void proxyConnectionCloseTest() throws SQLException {
    ConnectionPoolDataSource ds = new SQLiteConnectionPoolDataSource();
    PooledConnection pooledConn = ds.getPooledConnection();
    System.out.println("pooledConn: " + pooledConn.getClass());
    Connection handle = pooledConn.getConnection();
    System.out.println("pooledConn.getConnection: " + handle.getClass());
    Statement st = handle.createStatement();
    System.out.println("statement: " + st.getClass());
    Connection stConn = handle.createStatement().getConnection();
    System.out.println("statement connection:" + stConn.getClass());
    // This closes the physical connection, not the proxy
    stConn.close();
    Connection handle2 = pooledConn.getConnection();
}
Also used : SQLiteConnectionPoolDataSource(org.sqlite.javax.SQLiteConnectionPoolDataSource) ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) SQLiteConnectionPoolDataSource(org.sqlite.javax.SQLiteConnectionPoolDataSource) Statement(java.sql.Statement) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 4 with SQLiteConnectionPoolDataSource

use of org.sqlite.javax.SQLiteConnectionPoolDataSource in project sqlite-jdbc by xerial.

the class SQLiteConnectionPoolDataSourceTest method connectionTest.

@Test
public void connectionTest() throws SQLException {
    ConnectionPoolDataSource ds = new SQLiteConnectionPoolDataSource();
    PooledConnection pooledConn = ds.getPooledConnection();
    Connection handle = pooledConn.getConnection();
    assertFalse(handle.isClosed());
    assertTrue(handle.createStatement().execute("select 1"));
    Connection handle2 = pooledConn.getConnection();
    assertTrue(handle.isClosed());
    try {
        handle.createStatement().execute("select 1");
        fail();
    } catch (SQLException e) {
        assertEquals("Connection is closed", e.getMessage());
    }
    assertTrue(handle2.createStatement().execute("select 1"));
    handle2.close();
    handle = pooledConn.getConnection();
    assertTrue(handle.createStatement().execute("select 1"));
    pooledConn.close();
    assertTrue(handle.isClosed());
}
Also used : SQLiteConnectionPoolDataSource(org.sqlite.javax.SQLiteConnectionPoolDataSource) ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) SQLiteConnectionPoolDataSource(org.sqlite.javax.SQLiteConnectionPoolDataSource) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) Test(org.junit.jupiter.api.Test)

Aggregations

SQLiteConnectionPoolDataSource (org.sqlite.javax.SQLiteConnectionPoolDataSource)4 Connection (java.sql.Connection)2 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)2 PooledConnection (javax.sql.PooledConnection)2 Test (org.junit.jupiter.api.Test)2 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Disabled (org.junit.jupiter.api.Disabled)1 SQLiteConfig (org.sqlite.SQLiteConfig)1