use of org.beetl.sql.core.db.H2Style in project jSqlBox by drinkjava2.
the class BeetlSqlTemplateDemo method doTest.
@Test
public void doTest() {
HikariDataSource ds = new HikariDataSource();
// H2 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("");
ConnectionSource source = ConnectionSourceHelper.getSingle(ds);
DBStyle dbstyle = new H2Style();
SQLLoader loader = new ClasspathLoader("/sql");
UnderlinedNameConversion nc = new UnderlinedNameConversion();
SQLManager sqlManager = new SQLManager(dbstyle, loader, source, nc, new Interceptor[] {});
// Done BeetlSQL engine
SqlBoxContext.setGlobalTemplateEngine(new BeetlSqlTempalte(sqlManager));
// Log output
SqlBoxContext.setGlobalAllowShowSql(true);
SqlBoxContext ctx = new SqlBoxContext(ds);
SqlBoxContext.setGlobalSqlBoxContext(ctx);
String[] ddlArray = ctx.toDropAndCreateDDL(User.class);
for (String ddl : ddlArray) ctx.quiteExecute(ddl);
for (int i = 1; i <= 100; i++) {
User u = new User();
u.setName("Foo" + i);
u.setAge(i);
u.insert();
}
Assert.assertEquals(100, ctx.nQueryForLongValue("select count(*) from users"));
Map<String, Object> params = new HashMap<>();
params.put("age", 50);
List<Map<String, Object>> result = ctx.tQueryForMapList("user.select", params);
Assert.assertEquals(50, result.size());
ds.close();
}
Aggregations