@GET public Blob convert( @QueryParam("converter") String converter, @QueryParam("type") String type, @QueryParam("format") String format, @Context UriInfo uriInfo) { BlobHolder bh = getBlobHolderToConvert(); boolean txWasActive = false; try { if (TransactionHelper.isTransactionActive()) { txWasActive = true; TransactionHelper.commitOrRollbackTransaction(); } if (StringUtils.isNotBlank(converter)) { return convertWithConverter(bh, converter, uriInfo); } else if (StringUtils.isNotBlank(type)) { return convertWithMimeType(bh, type, uriInfo); } else if (StringUtils.isNotBlank(format)) { return convertWithFormat(bh, format, uriInfo); } else { throw new IllegalParameterException("No converter, type or format parameter specified"); } } finally { if (txWasActive && !TransactionHelper.isTransactionActiveOrMarkedRollback()) { TransactionHelper.startTransaction(); } } }
protected void triggerReloadWithNewTransaction(String id) { if (TransactionHelper.isTransactionMarkedRollback()) { throw new AssertionError("The calling transaction is marked rollback"); } else if (TransactionHelper.isTransactionActive()) { // should flush // the calling // transaction TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); } try { try { triggerReload(id); } catch (RuntimeException cause) { TransactionHelper.setTransactionRollbackOnly(); throw cause; } } finally { if (TransactionHelper.isTransactionActiveOrMarkedRollback()) { boolean wasRollbacked = TransactionHelper.isTransactionMarkedRollback(); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); if (wasRollbacked) { TransactionHelper.setTransactionRollbackOnly(); } } } }
protected void doTestMultipleRepositoriesPerTransaction(CoreSession session2) throws Exception { assertEquals(database.getRepositoryName(), session.getRepositoryName()); assertEquals(database.getRepositoryName() + "2", session2.getRepositoryName()); assertTrue(TransactionHelper.isTransactionActive()); assertNotSame( "Sessions from two different repos", session.getRootDocument().getId(), session2.getRootDocument().getId()); }
public void startTransaction() { if (syncMode) { ElasticSearchInlineListener.useSyncIndexing.set(true); } if (!TransactionHelper.isTransactionActive()) { TransactionHelper.startTransaction(); } Assert.assertEquals(0, esa.getPendingWorkerCount()); commandProcessed = esa.getTotalCommandProcessed(); }
@Override public Session getSession() { SessionInfo si = sessionHolder.get(); if (si == null || !si.session.isLive()) { // close old one, previously completed closeInThisThread(); if (!TransactionHelper.isTransactionActive()) { throw new LocalException("No transaction active, cannot reconnect: " + sessionId); } if (log.isDebugEnabled()) { log.debug("Reconnecting CoreSession: " + sessionId); } si = createSession(); } return si.session; }
@Override public void handleEvent(Event event) { if (!Framework.isDevModeSet()) { log.info("Do not flush the directory caches: dev mode is not set"); return; } if (!ReloadEventNames.RELOAD_EVENT_ID.equals(event.getId())) { return; } try { RepositoryManager rm = Framework.getService(RepositoryManager.class); // Transaction management final boolean txStarted = !TransactionHelper.isTransactionActive() && TransactionHelper.startTransaction(); boolean txSucceed = false; try { new UnrestrictedSessionRunner(rm.getDefaultRepositoryName()) { @Override public void run() { DocumentRoutingService service = Framework.getLocalService(DocumentRoutingService.class); service.importAllRouteModels(session); } }.runUnrestricted(); txSucceed = true; } finally { if (txStarted) { if (!txSucceed) { TransactionHelper.setTransactionRollbackOnly(); log.warn("Rollbacking import of route models"); } TransactionHelper.commitOrRollbackTransaction(); } } } catch (NuxeoException e) { log.error("Error while reloading the route models", e); } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Transaction main = threadBound.get(); if (main == null) { // first call in thread try { main = TransactionHelper.lookupTransactionManager().getTransaction(); if (main != null) { if (main.getStatus() != Status.STATUS_MARKED_ROLLBACK) { main.registerSynchronization(this); session.afterBegin(); threadBound.set(main); } } } catch (NamingException e) { // no transaction manager, ignore } catch (Exception e) { log.error("Error on transaction synchronizer registration", e); } checkTxActiveRequired(method); } try { return method.invoke(session, args); } catch (Throwable t) { if (TransactionHelper.isTransactionActive() && needsRollback(method, t)) { TransactionHelper.setTransactionRollbackOnly(); } if (t instanceof InvocationTargetException) { Throwable tt = ((InvocationTargetException) t).getTargetException(); if (tt != null) { throw tt; } } throw t; } }
public void initTx(Config config, HttpServletRequest req) { if (!config.isStatic && config.autoTx && !TransactionHelper.isTransactionActive()) { config.txStarted = ServletHelper.startTransaction(req); } }