@Override public void filter(ContainerRequestContext requestContext) throws IOException { if (MCRSessionMgr.isLocked()) { return; } MCRSession mcrSession = MCRSessionMgr.getCurrentSession(); if (mcrSession.isTransactionActive()) { LogManager.getLogger().info("Filter scoped JPA transaction is active."); if (mcrSession.transactionRequiresRollback()) { try { mcrSession.rollbackTransaction(); } finally { throw new InternalServerErrorException("Transaction rollback was required."); } } mcrSession.commitTransaction(); } if (Boolean.TRUE.equals(requestContext.getProperty(PROP_REQUIRE_TRANSACTION))) { LogManager.getLogger().info("Starting user JPA transaction."); mcrSession.beginTransaction(); } } }
private static void closeSessionIfNeeded() { if (MCRSessionMgr.hasCurrentSession()) { MCRSession currentSession = MCRSessionMgr.getCurrentSession(); try { if (currentSession.isTransactionActive()) { LOGGER.debug("Active MCRSession and JPA-Transaction found. Clearing up"); if (currentSession.transactionRequiresRollback()) { currentSession.rollbackTransaction(); } else { currentSession.commitTransaction(); } } else { LOGGER.debug("Active MCRSession found. Clearing up"); } } finally { MCRSessionMgr.releaseCurrentSession(); currentSession.close(); MCRSessionMgr.lock(); LOGGER.debug("Session closed."); } } }
private static void doWithinTransaction(IOOperation op) throws IOException { MCRSession mcrSession = MCRSessionMgr.getCurrentSession(); try { mcrSession.beginTransaction(); op.run(); } finally { if (mcrSession.transactionRequiresRollback()) { mcrSession.rollbackTransaction(); } else { mcrSession.commitTransaction(); } } }
LOGGER.error("Command '{}' failed. Performing transaction rollback...", command, ex); try { session.rollbackTransaction(); } catch (Exception ex2) { LOGGER.error("Error while perfoming rollback for command '{}'!", command, ex2);