/** * Returns existing thread session, or new one if already not exist. If session doesn't exist, it will be created * using default connection provider. */ public static DbThreadSession getThreadSession() { DbThreadSession session = (DbThreadSession) ThreadDbSessionHolder.get(); if (session == null) { session = new DbThreadSession(); } return session; }
/** * Creates DB Session. */ protected DbSession createDbSession() { return new DbThreadSession(cp); }
@Test void testEnums() { DbSession session = new DbThreadSession(cp); String sql = "create table ENUMERATOR(ID int, NAME varchar(20), STATUS int)"; DbQuery query = new DbQuery(DbOom.get(), sql); query.executeUpdate(); Enumerator e = new Enumerator(); e.id = 2; e.name = "Ikigami"; e.status = Enumerator.STATUS.ONE; query = DbOomQuery.query(dbOom.entities().insert(e)); query.executeUpdate(); session.closeSession(); }
@Test void testGroupNames() { DbSession session = new DbThreadSession(cp); // ---------------------------------------------------------------- insert assertEquals(1, dbOom.entities().insert(new Group("g1")).query().autoClose().executeUpdate()); List<Group> groups; groups = dbOom.entities().findAll(Group.class).query().list(); assertEquals(1, groups.size()); groups = dbOom.entities().findByColumn(Group.class, "column", "g1").query().list(); assertEquals(1, groups.size()); groups = dbOom.entities().findByColumn(Group.class, "column", "g1").query().list(); assertEquals(1, groups.size()); session.close(); }
@Test void testMapping() throws SQLException { DbSession session = new DbThreadSession(cp);
@Test void testHint() { DbSession dbSession = new DbThreadSession(cp);
@Test void testOrm2() { DbSession session = new DbThreadSession(cp); session = new DbThreadSession(cp); session = new DbThreadSession(cp); session = new DbThreadSession(cp); dbEntityManager.registerEntity(Girl2.class, true); Girl2 g2 = new Girl2("Gwen"); session = new DbThreadSession(cp);
@Override @BeforeEach protected void setUp() throws Exception { super.setUp(); DbEntityManager dbEntityManager = DbOom.get().entityManager(); dbEntityManager.registerEntity(User.class); dbEntityManager.registerEntity(Wizard.class); session = new DbThreadSession(cp); executeUpdate("drop table WIZARD if exists"); executeUpdate("drop table USER if exists"); DbQuery query = DbQuery.query( "create table USER (" + "USER_ID IDENTITY," + "NAME varchar(20) not null" + ')'); query.executeUpdate(); query = DbQuery.query("insert into USER values(1, 'Gandalf')"); query.executeUpdate(); query = DbQuery.query( "create table WIZARD (" + "WIZARD_ID IDENTITY," + "LEVEL INT not null" + ')'); query.executeUpdate(); query = DbQuery.query("insert into WIZARD values(1, 7);"); query.executeUpdate(); }
@Test void testOrm() { DbSession session = new DbThreadSession(cp);
DbSession dbts = new DbThreadSession(cp); DbQuery q = DbQuery.query("select count(*) from GIRL"); assertEquals(3, q.executeCount());
@Test void testMappingNoTable() { DbSession session = new DbThreadSession(cp);
@Override @BeforeEach protected void setUp() throws Exception { super.setUp(); final DbEntityManager dbEntityManager = DbOom.get().entityManager(); dbEntityManager.registerEntity(Girl2.class); dbEntityManager.registerEntity(Boy.class); dbSession = new DbThreadSession(cp); final DbEntitySql dbEntitySql = dbOom.entities(); assertEquals(1, dbEntitySql.insert(new Girl2(1, "Anna", "swim")).query().executeUpdate()); assertEquals(1, dbEntitySql.insert(new Girl2(2, "Sandra", "piano")).query().executeUpdate()); assertEquals(1, dbEntitySql.insert(new Girl2(3, "Emma", "nothing")).query().executeUpdate()); assertEquals(1, dbEntitySql.insert(new Boy(1, "Johny", 2)).query().executeUpdate()); assertEquals(1, dbEntitySql.insert(new Boy(2, "Marco", 2)).query().executeUpdate()); assertEquals(1, dbEntitySql.insert(new Boy(3, "Hugo", 1)).query().executeUpdate()); }
DbSession dbSession = new DbThreadSession();
/** * Returns existing thread session, or new one if already not exist. If session doesn't exist, it will be created * using default connection provider. */ public static DbThreadSession getThreadSession() { DbThreadSession session = (DbThreadSession) ThreadDbSessionHolder.get(); if (session == null) { session = new DbThreadSession(); } return session; }
/** * Returns existing thread session, or new one if already not exist. If session doesn't exist, it will be created * using default connection provider. */ public static DbThreadSession getThreadSession() { DbThreadSession session = (DbThreadSession) ThreadDbSessionHolder.get(); if (session == null) { session = new DbThreadSession(); } return session; }
@Test void testHint() { DbSession dbSession = new DbThreadSession(cp);
/** * {@inheritDoc} */ public DbSession getDbSession() { if (log.isDebugEnabled()) { log.debug("Requesting thread session"); } DbSession session = ThreadDbSessionHolder.get(); if (session == null) { if (createIfMissing) { return new DbThreadSession(); } throw new DbSqlException("No session associated to current thread."); } return session; }