use of jodd.db.oom.tst.Tester in project jodd by oblac.
the class LiveDatabaseTest method assertDb.
// ---------------------------------------------------------------- util
protected void assertDb(DbSession dbSession, String expected) {
DbOomQuery query = new DbOomQuery(dbSession, "select * from TESTER order by ID");
List<Tester> testerList = query.list(Tester.class);
StringBuilder sb = new StringBuilder();
for (Tester tester : testerList) {
sb.append(tester.toString());
}
assertEquals(expected, sb.toString());
}
use of jodd.db.oom.tst.Tester in project jodd by oblac.
the class LiveDatabaseTest method workoutEntity.
// ---------------------------------------------------------------- workout
protected void workoutEntity() {
DbSession session = new DbSession();
Tester tester = new Tester();
tester.setName("one");
tester.setValue(Integer.valueOf(7));
DbOomQuery dbOomQuery = DbOomQuery.query(session, DbEntitySql.insert(tester));
dbOomQuery.setGeneratedKey();
dbOomQuery.executeUpdate();
assertDb(session, "{1,one,7}");
long key = dbOomQuery.getGeneratedKey();
tester.setId(Long.valueOf(key));
dbOomQuery.close();
assertEquals(1, tester.getId().longValue());
tester.setName("seven");
DbOomQuery.query(session, DbEntitySql.updateAll(tester)).executeUpdate();
assertDb(session, "{1,seven,7}");
tester.setName("SEVEN");
DbOomQuery.query(session, DbEntitySql.update(tester)).executeUpdate();
assertDb(session, "{1,SEVEN,7}");
tester.setName("seven");
DbOomQuery.query(session, DbEntitySql.updateColumn(tester, "name")).executeUpdate();
assertDb(session, "{1,seven,7}");
tester = new Tester();
tester.setId(Long.valueOf(2));
tester.setName("two");
tester.setValue(Integer.valueOf(2));
DbOomQuery.query(session, DbEntitySql.insert(tester)).executeUpdate();
assertDb(session, "{1,seven,7}{2,two,2}");
long count = DbOomQuery.query(session, DbEntitySql.count(Tester.class)).executeCount();
assertEquals(2, count);
tester = DbOomQuery.query(session, DbEntitySql.findById(Tester.class, 2)).find(Tester.class);
assertNotNull(tester);
assertEquals("{2,two,2}", tester.toString());
tester = DbOomQuery.query(session, DbEntitySql.findById(Tester.class, 2).aliasColumnsAs(ColumnAliasType.COLUMN_CODE)).find(Tester.class);
assertNotNull(tester);
assertEquals("{2,two,2}", tester.toString());
tester = DbOomQuery.query(session, DbEntitySql.findById(Tester.class, 2).aliasColumnsAs(ColumnAliasType.TABLE_REFERENCE)).find(Tester.class);
assertNotNull(tester);
assertEquals("{2,two,2}", tester.toString());
tester = DbOomQuery.query(session, DbEntitySql.findById(Tester.class, 2).aliasColumnsAs(ColumnAliasType.TABLE_NAME)).find(Tester.class);
assertNotNull(tester);
assertEquals("{2,two,2}", tester.toString());
tester = DbOomQuery.query(session, DbEntitySql.findById(Tester.class, 2).aliasColumnsAs(// fixes POSTGRESQL
ColumnAliasType.COLUMN_CODE)).find();
assertEquals("{2,two,2}", tester.toString());
tester = new Tester();
tester.setName("seven");
tester = DbOomQuery.query(session, DbEntitySql.find(tester)).find(Tester.class);
assertEquals("{1,seven,7}", tester.toString());
DbOomQuery.query(session, DbEntitySql.findByColumn(Tester.class, "name", "seven")).find(Tester.class);
assertEquals("{1,seven,7}", tester.toString());
DbOomQuery.query(session, DbEntitySql.deleteById(Tester.class, 1)).executeUpdate();
count = DbOomQuery.query(session, DbEntitySql.count(Tester.class)).executeCount();
assertEquals(1, count);
session.closeSession();
}