/** * @param <ReturnType> object type to return from the transaction * @param requestedRO hint as whether to use the read-only connection * @param entitySqlDaoTransactionWrapper transaction to execute * @return result from the transaction fo type ReturnType */ public <ReturnType> ReturnType execute(final boolean requestedRO, final EntitySqlDaoTransactionWrapper<ReturnType> entitySqlDaoTransactionWrapper) { final String debugInfo = logger.isDebugEnabled() ? getDebugInfo() : null; final Handle handle = dbRouter.getHandle(requestedRO); logger.debug("DBI handle created, transaction: {}", debugInfo); try { final EntitySqlDao<EntityModelDao<Entity>, Entity> entitySqlDao = handle.attach(InitialEntitySqlDao.class); // The transaction isolation level is now set at the pool level: this avoids 3 roundtrips for each transaction // Note that if the pool isn't used (tests or PostgreSQL), the transaction level will depend on the DB configuration //return entitySqlDao.inTransaction(TransactionIsolationLevel.READ_COMMITTED, new JdbiTransaction<ReturnType, EntityModelDao<Entity>, Entity>(handle, entitySqlDaoTransactionWrapper)); logger.debug("Starting transaction {}", debugInfo); final ReturnType returnType = entitySqlDao.inTransaction(new JdbiTransaction<ReturnType, EntityModelDao<Entity>, Entity>(handle, entitySqlDaoTransactionWrapper)); logger.debug("Exiting transaction {}, returning {}", debugInfo, returnType); return returnType; } finally { handle.close(); logger.debug("DBI handle closed, transaction: {}", debugInfo); } }
/** * @param <ReturnType> object type to return from the transaction * @param requestedRO hint as whether to use the read-only connection * @param entitySqlDaoTransactionWrapper transaction to execute * @return result from the transaction fo type ReturnType */ public <ReturnType> ReturnType execute(final boolean requestedRO, final EntitySqlDaoTransactionWrapper<ReturnType> entitySqlDaoTransactionWrapper) { final String debugInfo = logger.isDebugEnabled() ? getDebugInfo() : null; final Handle handle = dbRouter.getHandle(requestedRO); logger.debug("DBI handle created, transaction: {}", debugInfo); try { final EntitySqlDao<EntityModelDao<Entity>, Entity> entitySqlDao = handle.attach(InitialEntitySqlDao.class); // The transaction isolation level is now set at the pool level: this avoids 3 roundtrips for each transaction // Note that if the pool isn't used (tests or PostgreSQL), the transaction level will depend on the DB configuration //return entitySqlDao.inTransaction(TransactionIsolationLevel.READ_COMMITTED, new JdbiTransaction<ReturnType, EntityModelDao<Entity>, Entity>(handle, entitySqlDaoTransactionWrapper)); logger.debug("Starting transaction {}", debugInfo); final ReturnType returnType = entitySqlDao.inTransaction(new JdbiTransaction<ReturnType, EntityModelDao<Entity>, Entity>(handle, entitySqlDaoTransactionWrapper)); logger.debug("Exiting transaction {}, returning {}", debugInfo, returnType); return returnType; } finally { handle.close(); logger.debug("DBI handle closed, transaction: {}", debugInfo); } }