use of org.beetl.sql.core.SQLManager in project nutzboot by nutzam.
the class BeetlSqlStarter method creatSQLManager.
@IocBean(name = "beetlsqlManager")
public SQLManager creatSQLManager(@Inject("refer:beetlsqlDBStyle") DBStyle dbStyle, @Inject("beetlsqlConnectionSource") ConnectionSource ds) {
// BeetlSql默认/sql/,但NutzBoot的约定是/sqls/,入乡随俗吧
SQLLoader loader = new ClasspathLoader(conf.get(PROP_PATH, "/sqls/"));
// TODO 支持更多种类的NameConversion
NameConversion nameconv = "default".equals(conf.get(PROP_NAME_CONVERSION, "default")) ? new DefaultNameConversion() : new UnderlinedNameConversion();
// 是否插入debug拦截器呢? 默认启用好了
if (conf.getBoolean(PROP_DEBUG, true))
return new SQLManager(dbStyle, loader, ds, nameconv, new Interceptor[] { new DebugInterceptor() });
return new SQLManager(dbStyle, loader, ds, nameconv);
}
use of org.beetl.sql.core.SQLManager 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