@Override protected void doDelete(final Session session) { jdbcSessionSqlDao.delete(new SessionModelDao(session)); }
@Override protected void doUpdate(final Session session) { jdbcSessionSqlDao.update(new SessionModelDao(session)); }
@Override public Long inTransaction(final JDBCSessionSqlDao transactional, final TransactionStatus status) throws Exception { transactional.create(new SessionModelDao(session)); return transactional.getLastInsertId(); } });
@Override protected Serializable doCreate(final Session session) { final Serializable sessionId = jdbcSessionSqlDao.inTransaction(new Transaction<Long, JDBCSessionSqlDao>() { @Override public Long inTransaction(final JDBCSessionSqlDao transactional, final TransactionStatus status) throws Exception { transactional.create(new SessionModelDao(session)); return transactional.getLastInsertId(); } }); assignSessionId(session, sessionId); return sessionId; }
@Test(groups = "fast") public void testRoundTrip() throws Exception { final SimpleSession simpleSession = new SimpleSession(); simpleSession.setStartTimestamp(new Date(System.currentTimeMillis() - 5000)); simpleSession.setLastAccessTime(new Date(System.currentTimeMillis())); simpleSession.setTimeout(493934L); simpleSession.setHost(UUID.randomUUID().toString()); simpleSession.setAttribute(UUID.randomUUID(), Short.MIN_VALUE); simpleSession.setAttribute(UUID.randomUUID(), Integer.MIN_VALUE); simpleSession.setAttribute(UUID.randomUUID(), Long.MIN_VALUE); simpleSession.setAttribute(UUID.randomUUID().toString(), UUID.randomUUID().toString()); // Test with Serializable objects simpleSession.setAttribute(UUID.randomUUID().toString(), UUID.randomUUID()); simpleSession.setAttribute(UUID.randomUUID().toString(), new Date(1242)); final SessionModelDao sessionModelDao = new SessionModelDao(simpleSession); Assert.assertEquals(sessionModelDao.getTimeout(), simpleSession.getTimeout()); Assert.assertEquals(sessionModelDao.getHost(), simpleSession.getHost()); Assert.assertTrue(sessionModelDao.getSessionData().length > 0); final Session retrievedSession = sessionModelDao.toSimpleSession(); Assert.assertEquals(retrievedSession, simpleSession); } }