@AfterClass public static void tearDownAfterClass() throws Exception { final Transaction transaction = session.getTransaction(); if (transaction.isActive()) transaction.commit(); if (session != null) session.close(); }
private void commitTransaction(Session session, UnitOfWork uow) { if (uow.transactional()) { Transaction txn = session.getTransaction(); if (txn != null && txn.isActive()) { txn.commit(); } } }
private void rollbackTransaction(Session session, boolean readOnly) { if (!readOnly) { final Transaction txn = session.getTransaction(); if (txn != null && txn.isActive()) { txn.rollback(); } } }
/** * Rolls back hibernate session. * * @param ses Hibernate session. * @param tx Cache ongoing transaction. */ private void rollback(SharedSessionContract ses, GridCacheTx tx) { // Rollback only if there is no cache transaction, // otherwise txEnd() will do all required work. if (tx == null) { Transaction hTx = ses.getTransaction(); if (hTx != null && hTx.isActive()) hTx.rollback(); } }
/** * Ends hibernate session. * * @param ses Hibernate session. * @param tx Cache ongoing transaction. */ private void end(Session ses, GridCacheTx tx) { // Commit only if there is no cache transaction, // otherwise txEnd() will do all required work. if (tx == null) { Transaction hTx = ses.getTransaction(); if (hTx != null && hTx.isActive()) hTx.commit(); ses.close(); } }
/** {@inheritDoc} */ @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) { Session hibSes = ses.attach(null); if (hibSes != null) { try { Transaction tx = hibSes.getTransaction(); if (commit) { hibSes.flush(); if (tx.isActive()) tx.commit(); } else if (tx.isActive()) tx.rollback(); } catch (HibernateException e) { throw new CacheWriterException( "Failed to end store session [tx=" + ses.transaction() + ']', e); } finally { hibSes.close(); } } }