List of usage examples for javax.transaction UserTransaction commit
void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException;
From source file:com.webbfontaine.valuewebb.gtns.TTGTNSSynchronizer.java
protected static void updateTT(TtGen ttGen, String operation) { LOGGER.debug("Going to execute {0} operation on TT with id {1}.", operation, ttGen.getId()); assert !StringUtils.isEmpty(operation) && ttGen != null : "ttGen and requestedOperation must not be null"; UserTransaction utx = null; try {/*from w w w.jav a2 s.c o m*/ utx = Transaction.instance(); utx.begin(); TtGenHome ttGenHome = createTTHomeInstance(ttGen); if (ttGenHome.performDirectTaskWithoutDocumentCheck(operation).equals(UPDATED)) { if (RESPONSE_OK.equals(operation)) { utx.commit(); utx = Transaction.instance(); utx.begin(); ttGenHome.pickUp(); } utx.commit(); } else { LOGGER.error("Failed to execute {0} operation for TT with id {1}. Will continue with next TTs", operation, ttGen.getId()); utx.rollback(); } } catch (Exception e) { LOGGER.error("Exception on updating TT with id: {0} for operation: {1} fails", e, ttGen.getId(), operation); if (utx != null) { try { utx.rollback(); } catch (SystemException sex) { LOGGER.error("", sex); } } } }
From source file:com.autentia.common.util.ejb.web.jsf.OpenTransactionInViewPatternJSFAfterRenderResponseListener.java
public void afterPhase(PhaseEvent phaseEvent) { final UserTransaction utx; try {/* w w w .ja v a 2s . c o m*/ utx = (UserTransaction) JndiUtils.jndiLookup("UserTransaction"); utx.commit(); log.debug("Transaction committed"); } catch (Exception e) { log.fatal("Cannot commit the active transaction.", e); } }
From source file:com.netpace.cms.sso.filter.TransactionalHelper.java
public Object doInTransaction(Transactionable callback) { UserTransaction tx = transactionService.getUserTransaction(); Object result;/*w ww .ja v a 2 s . c om*/ try { tx.begin(); result = callback.execute(); tx.commit(); } catch (Throwable ex) { logger.error(ex); try { tx.rollback(); } catch (Exception ex2) { logger.error("Failed to rollback transaction", ex2); } if (ex instanceof RuntimeException) { throw (RuntimeException) ex; } else { throw new RuntimeException("Failed to execute transactional method", ex); } } return result; }
From source file:fr.openwide.talendalfresco.rest.server.CommandAuthenticationFilter.java
/** * /* ww w . j a v a 2 s. c o m*/ * @param httpReq * @param httpRes * @return processor which can output to the res * @throws Throwable if error in txn */ private RestCommandProcessor login(HttpServletRequest httpReq, HttpServletResponse httpRes) throws Throwable { // getting login parameters Map<String, String> args = new HashMap<String, String>(3, 1.0f); args.put(RestConstants.PROP_LOGIN_USERNAME, httpReq.getParameter("username")); args.put(RestConstants.PROP_LOGIN_PASSWORD, httpReq.getParameter("password")); RestCommandProcessor processor = new RestCommandProcessor(); // validate that the processor has everything it needs to run the command if (!processor.validateArguments(this.context, LOGIN_COMMAND_NAME, args, null)) { // returning processor with error state return processor; } ServiceRegistry serviceRegistry = getServiceRegistry(this.context); UserTransaction txn = null; try { txn = serviceRegistry.getTransactionService().getUserTransaction(); txn.begin(); processor.process(serviceRegistry, httpReq, httpRes, LOGIN_COMMAND_NAME); txn.commit(); return processor; } catch (Throwable txnErr) { try { if (txn != null) { txn.rollback(); } } catch (Exception tex) { } throw txnErr; } }
From source file:org.spring.data.gemfire.app.service.vendor.GemFireGemstoneService.java
protected <IN, OUT> OUT doInTransaction(final TransactionCallback<IN, OUT> callback, IN parameter) { UserTransaction userTransaction = null; try {//from www. jav a2s. co m userTransaction = (UserTransaction) getCache().getJNDIContext().lookup(USER_TRANSACTION_JNDI_LOCATION); userTransaction.begin(); OUT returnValue = callback.doInTransaction(parameter); userTransaction.commit(); return returnValue; } catch (Exception e) { e.printStackTrace(System.err); rollback(userTransaction); if (e instanceof IllegalGemstoneException) { throw (IllegalGemstoneException) e; } else { throw new RuntimeException( String.format("Transaction failed due to unexpected Exception: %1$s!", e.getMessage()), e); } } }
From source file:org.alfresco.util.transaction.SpringAwareUserTransactionTest.java
public void testMismatchedBeginCommit() throws Exception { UserTransaction txn1 = getTxn();/*from w w w .j a v a 2 s . c om*/ UserTransaction txn2 = getTxn(); testNoTxnStatus(); txn1.begin(); txn2.begin(); txn2.commit(); txn1.commit(); checkNoStatusOnThread(); txn1 = getTxn(); txn2 = getTxn(); txn1.begin(); txn2.begin(); try { txn1.commit(); fail("Failure to detect mismatched transaction begin/commit"); } catch (RuntimeException e) { // expected } txn2.commit(); txn1.commit(); checkNoStatusOnThread(); }
From source file:com.webbfontaine.valuewebb.action.fcvr.FCVRSendScheduler.java
protected void updateTT(TtGen ttGen, String operation) { LOGGER.debug("Going to execute {0} operation on TT with id {1}.", operation, ttGen.getId()); UserTransaction utx = null; try {// www.ja v a 2 s. c o m utx = Transaction.instance(); utx.begin(); TtGenHome ttGenHome = createTTHomeInstance(ttGen); if (ttGenHome.performDirectTaskWithoutDocumentCheck(operation).equals(UPDATED)) { utx.commit(); } else { LOGGER.error("Failed to execute {0} operation for TT with id {1}. Will continue with next TTs", operation, ttGen.getId()); utx.rollback(); } } catch (Exception e) { LOGGER.error("Exception on updating TT with id: {0} for operation: {1} fails", e, ttGen.getId(), operation); if (utx != null) { try { utx.rollback(); } catch (SystemException sex) { LOGGER.error("", sex); } } } }
From source file:com.bluexml.side.Integration.alfresco.sql.synchronization.schemaManagement.SchemaCreation.java
private boolean doExecuteReplication(QName modelName) { boolean success = true; UserTransaction userTransaction = transactionService.getUserTransaction(); try {//from w w w. j av a2s. c o m userTransaction.begin(); contentReplication.addExistingData(modelName); userTransaction.commit(); } catch (Exception e) { success = false; try { userTransaction.rollback(); } catch (Exception e1) { logger.error("Cannot rollback transaction !"); e1.printStackTrace(); } e.printStackTrace(); } return success; }
From source file:nc.noumea.mairie.alfresco.webScript.SynchroniseAgentWebScript.java
@Override public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { logger.info("DEBUT Web Script SynchroniseAgentWebScript"); Map<String, Object> model = new HashMap<String, Object>(); model.put("nomWebScript", "SynchroniseAgentWebScript"); long startTime = System.currentTimeMillis(); if (!isSiteSirhExist()) { logger.debug("Site SIRH not exist"); long endTime = System.currentTimeMillis(); model.put("nbrAgentCree", "Site SIRH not exist"); model.put("tempsExecution", endTime - startTime); return model; }//ww w.j av a 2s. c o m List<AgentWithServiceDto> listAgentsSIRH = sirhWsConsumer.getListeAgentsMairie(); List<String> listEmployeeNumber = new ArrayList<String>(); for (AgentWithServiceDto agent : listAgentsSIRH) { if (!listEmployeeNumber.contains(getEmployeeNumberFromIdAgent(agent.getIdAgent()))) { listEmployeeNumber.add(getEmployeeNumberFromIdAgent(agent.getIdAgent())); } } logger.info("Nombre d'agents retournes par SIRH : " + listAgentsSIRH.size()); List<LightUserDto> listUsersRadi = radiWsConsumer.getListAgentCompteAD(listEmployeeNumber); logger.info("Nombre d'agents retournes par RADI : " + listUsersRadi.size()); int nbrAgentCree = 0; for (AgentWithServiceDto agent : listAgentsSIRH) { LightUserDto userRadi = getLightUserRadiDto(listUsersRadi, agent); if (null == userRadi) { logger.debug("User not exist in RADI : " + agent.getIdAgent()); continue; } logger.debug("User find in RADI : " + agent.getIdAgent()); // nous gerons nous meme les transactions // car nous avons eu "TransactionalCache' is full" // cela ralentit fortement Alfresco UserTransaction trx = serviceRegistry.getTransactionService().getNonPropagatingUserTransaction(false); try { if (!personService.personExists(userRadi.getsAMAccountName())) { trx.begin(); personService.setCreateMissingPeople(true); NodeRef person = personService .createPerson(createDefaultProperties(userRadi.getsAMAccountName(), agent.getPrenom(), agent.getNom(), userRadi.getMail(), agent.getIdAgent())); trx.commit(); if (null != person) { nbrAgentCree++; } } else { logger.debug("User already exist in alfresco : " + agent.getIdAgent() + " " + userRadi.getsAMAccountName()); } } catch (Throwable e) { try { trx.rollback(); logger.error(e.getMessage()); } catch (IllegalStateException | SecurityException | SystemException e1) { logger.error(e1.getMessage()); } } } long endTime = System.currentTimeMillis(); model.put("nbrAgentCree", nbrAgentCree); model.put("tempsExecution", endTime - startTime); logger.debug(nbrAgentCree + " users crs."); logger.info("FIN Web Script SynchroniseAgentWebScript"); return model; }
From source file:org.alfresco.trashcan.TrashcanCleanerTest.java
/** * /*w w w . j a v a2 s. c om*/ * Generic method that asserts that for the <b>nodesCreate</b> existing on * archive store the execution of trashcan clean will leave remaining * undeleted <b>nodesRemain</b>. * * @param nodesCreate * @param nodesRemain * @throws Throwable */ private void cleanBatchTest(int nodesCreate, int nodesRemain) throws Throwable { UserTransaction userTransaction1 = transactionService.getUserTransaction(); try { userTransaction1.begin(); TrashcanCleaner cleaner = new TrashcanCleaner(nodeService, BATCH_SIZE, -1); createAndDeleteNodes(nodesCreate); long nodesToDelete = cleaner.getNumberOfNodesInTrashcan(); System.out.println(String.format("Existing nodes to delete: %s", nodesToDelete)); cleaner.clean(); nodesToDelete = cleaner.getNumberOfNodesInTrashcan(); System.out.println(String.format("Existing nodes to delete after: %s", nodesToDelete)); assertEquals(nodesRemain, nodesToDelete); System.out.println("Clean trashcan..."); cleaner.clean(); userTransaction1.commit(); } catch (Throwable e) { try { userTransaction1.rollback(); } catch (IllegalStateException ee) { } throw e; } }