use of com.github.drinkjava2.jsqlbox.SqlBoxContext in project jSqlBox by drinkjava2.
the class UsuageAndSpeedTest method activeRecordDefaultContext.
@Test
public void activeRecordDefaultContext() {
SqlBoxContext ctx = new SqlBoxContext(dataSource);
// use global default context
SqlBoxContext.setGlobalSqlBoxContext(ctx);
UserAR user = new UserAR();
for (int i = 0; i < REPEAT_TIMES; i++) {
user.setName("Sam");
user.setAddress("Canada");
user.insert();
user.setAddress("China");
user.update();
UserAR user2 = ctx.load(UserAR.class, "Sam");
user2.delete();
}
}
use of com.github.drinkjava2.jsqlbox.SqlBoxContext in project jSqlBox by drinkjava2.
the class UsuageAndSpeedTest method init.
@Before
public void init() {
dataSource = new HikariDataSource();
dataSource.setJdbcUrl("jdbc:h2:mem:DBName;MODE=MYSQL;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=0");
dataSource.setDriverClassName("org.h2.Driver");
// change to your user & password
dataSource.setUsername("sa");
dataSource.setPassword("");
SqlBoxContext ctx = new SqlBoxContext(dataSource);
SqlBoxContext.setGlobalSqlBoxContext(null);
for (String ddl : ctx.getDialect().toDropAndCreateDDL(UserAR.class)) try {
ctx.nExecute(ddl);
} catch (Exception e) {
}
}
use of com.github.drinkjava2.jsqlbox.SqlBoxContext in project jSqlBox by drinkjava2.
the class UsuageAndSpeedTest method dataMapperStyle.
@Test
public void dataMapperStyle() {
SqlBoxContext ctx = new SqlBoxContext(dataSource);
for (int i = 0; i < REPEAT_TIMES; i++) {
UserPOJO user = new UserPOJO();
user.setName("Sam");
user.setAddress("Canada");
ctx.insert(user);
user.setAddress("China");
ctx.update(user);
UserPOJO sam2 = ctx.load(UserPOJO.class, "Sam");
ctx.delete(sam2);
}
}
use of com.github.drinkjava2.jsqlbox.SqlBoxContext in project jSqlBox by drinkjava2.
the class UsuageAndSpeedTest method dbUtilsNoConnMethod.
@Test
public void dbUtilsNoConnMethod() {
SqlBoxContext ctx = new SqlBoxContext(dataSource);
for (int i = 0; i < REPEAT_TIMES; i++) {
try {
ctx.execute("insert into users (name,address) values(?,?)", "Sam", "Canada");
ctx.execute("update users set name=?, address=?", "Tom", "China");
Assert.assertEquals(1L, ctx.queryForObject("select count(*) from users where name=? and address=?", "Tom", "China"));
ctx.execute("delete from users where name=? or address=?", "Tom", "China");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
use of com.github.drinkjava2.jsqlbox.SqlBoxContext in project jSqlBox by drinkjava2.
the class UsuageAndSpeedTest method tXxxStyle.
@Test
public void tXxxStyle() {
SqlBoxContext ctx2 = new SqlBoxContext(dataSource);
Map<String, Object> params = new HashMap<String, Object>();
for (int i = 0; i < REPEAT_TIMES; i++) {
UserAR sam = new UserAR("Sam", "Canada");
UserAR tom = new UserAR("Tom", "China");
params.put("user", sam);
ctx2.tExecute("insert into users (name, address) values(#{user.name},:user.address)", params);
params.put("user", tom);
ctx2.tExecute("update users set name=#{user.name}, address=:user.address", params);
params.clear();
params.put("name", "Tom");
params.put("addr", "China");
Assert.assertEquals(1L, ctx2.tQueryForObject("select count(*) from users where name=#{name} and address=:addr", params));
params.put("u", tom);
ctx2.tExecute("delete from users where name=:u.name or address=#{u.address}", params);
}
}
Aggregations