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);
}
}
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);
}
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();
}
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());
}
Aggregations