use of com.zaxxer.hikari.HikariDataSource in project jDialects by drinkjava2.
the class DialectTest method buildH2Datasource.
// =======test guess dialects=======
private static HikariDataSource buildH2Datasource() {
HikariDataSource ds = new HikariDataSource();
ds.addDataSourceProperty("cachePrepStmts", true);
ds.addDataSourceProperty("prepStmtCacheSize", 250);
ds.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
ds.addDataSourceProperty("useServerPrepStmts", true);
ds.setMaximumPoolSize(3);
ds.setConnectionTimeout(5000);
ds.setJdbcUrl("jdbc:h2:mem:DBName;MODE=MYSQL;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=0");
ds.setDriverClassName("org.h2.Driver");
ds.setUsername("sa");
ds.setPassword("");
return ds;
}
use of com.zaxxer.hikari.HikariDataSource in project jDialects by drinkjava2.
the class TestDemo method doTest.
@Test
public void doTest() {
// DataSource
HikariDataSource ds = new HikariDataSource();
// H2 is a memory database
ds.setDriverClassName("org.h2.Driver");
ds.setJdbcUrl("jdbc:h2:mem:DBName;MODE=MYSQL;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=0");
ds.setUsername("sa");
ds.setPassword("");
// MySQL
// ds.setDriverClassName("com.mysql.jdbc.Driver");
// ds.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?rewriteBatchedStatements=true&useSSL=false");
// ds.setUsername("root");
// ds.setPassword("root888");
// MS-SqlServer
// ds.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// ds.setJdbcUrl("jdbc:sqlserver://localhost:1433;databaseName=test");
// ds.setUsername("sa");
// ds.setPassword("root888");
// ORACLE
// ds.setDriverClassName("oracle.jdbc.OracleDriver");
// ds.setJdbcUrl("jdbc:oracle:thin:@127.0.0.1:1521:XE");
// ds.setUsername("root");
// ds.setPassword("root888");
Dialect dialect = Dialect.guessDialect(ds);
// Dialect.setAllowShowDialectLog(true);
Connection conn = null;
try {
conn = ds.getConnection();
TableModel t = new TableModel("users");
t.column("firstName").VARCHAR(20).pkey();
t.column("lastName").VARCHAR(20).pkey();
t.column("age").INTEGER();
String[] ddlArray = dialect.toDropAndCreateDDL(t);
for (String ddl : ddlArray) try {
execute(conn, ddl);
} catch (Exception e) {
}
for (int i = 1; i <= 100; i++) execute(conn, "insert into users (firstName, lastName, age) values(?,?,?)", "Foo" + i, "Bar" + i, i);
Assert.assertEquals(100L, ((Number) queryForObject(conn, "select count(*) from users")).longValue());
List<Map<String, Object>> users = queryForMapList(conn, dialect.paginAndTrans(2, 10, "select concat(firstName, ' ', lastName) as UserName, age from users where age>?"), 50);
Assert.assertEquals(10, users.size());
for (Map<String, Object> map : users) System.out.println("UserName=" + map.get("USERNAME") + ", age=" + map.get("AGE"));
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
ds.close();
}
use of com.zaxxer.hikari.HikariDataSource in project HikariCP by brettwooldridge.
the class TestSealedConfig method testSealedAccessibleMethods.
@Test
public void testSealedAccessibleMethods() throws SQLException {
HikariConfig config = newHikariConfig();
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
ds.setConnectionTimeout(5000);
ds.setValidationTimeout(5000);
ds.setIdleTimeout(30000);
ds.setLeakDetectionThreshold(60000);
ds.setMaxLifetime(1800000);
ds.setMinimumIdle(5);
ds.setMaximumPoolSize(8);
ds.setPassword("password");
ds.setUsername("username");
}
}
use of com.zaxxer.hikari.HikariDataSource in project HikariCP by brettwooldridge.
the class TestSealedConfig method testSealed2.
@Test(expected = IllegalStateException.class)
public void testSealed2() throws SQLException {
HikariDataSource ds = new HikariDataSource();
ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource closeable = ds) {
try (Connection connection = ds.getConnection()) {
ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
fail("Exception should have been thrown");
}
}
}
use of com.zaxxer.hikari.HikariDataSource in project HikariCP by brettwooldridge.
the class TestSealedConfig method testSealed3.
@Test(expected = IllegalStateException.class)
public void testSealed3() throws SQLException {
HikariDataSource ds = new HikariDataSource();
ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource closeable = ds) {
try (Connection connection = ds.getConnection()) {
ds.setAutoCommit(false);
fail("Exception should have been thrown");
}
}
}
Aggregations