Search in sources :

Example 16 with DbSession

use of jodd.db.DbSession in project jodd by oblac.

the class DbIdGeneratorTest method testIdGen.

@Test
public void testIdGen() throws Exception {
    DbSession session = new DbSession(cp);
    ThreadDbSessionHolder.set(session);
    AppDao appDao = new AppDao();
    appDao.setKeysGeneratedByDatabase(false);
    appDao.dbIdGenerator = new DbIdGenerator();
    Girl girl = new Girl();
    girl.name = "One";
    girl.speciality = "Code";
    appDao.store(girl);
    assertEquals(1, girl.getId().longValue());
    girl = new Girl();
    girl.name = "Two";
    girl.speciality = "Dddd";
    appDao.store(girl);
    assertEquals(2, girl.getId().longValue());
    appDao.dbIdGenerator.reset();
    girl = new Girl();
    girl.name = "Three";
    girl.speciality = "Ssss";
    appDao.store(girl);
    assertEquals(3, girl.getId().longValue());
    assertEquals(3, appDao.count(Girl.class));
    assertNotNull(appDao.findById(Girl.class, 1));
    assertNotNull(appDao.findById(Girl.class, 2));
    assertNotNull(appDao.findById(Girl.class, 3));
    session.closeSession();
    ThreadDbSessionHolder.remove();
}
Also used : DbSession(jodd.db.DbSession) Test(org.junit.Test)

Aggregations

DbSession (jodd.db.DbSession)16 Test (org.junit.Test)10 DbThreadSession (jodd.db.DbThreadSession)7 DbQuery (jodd.db.DbQuery)3 Girl (jodd.db.oom.tst.Girl)3 ResultSet (java.sql.ResultSet)2 JDateTime (jodd.datetime.JDateTime)2 DbSqlBuilder (jodd.db.oom.sqlgen.DbSqlBuilder)2 BigDecimal (java.math.BigDecimal)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 QueryMapper (jodd.db.QueryMapper)1 DbJtxTransactionManager (jodd.db.jtx.DbJtxTransactionManager)1 Boy2 (jodd.db.oom.tst.Boy2)1 Boy4 (jodd.db.oom.tst.Boy4)1 Enumerator (jodd.db.oom.tst.Enumerator)1 Girl2 (jodd.db.oom.tst.Girl2)1