List of usage examples for javax.transaction UserTransaction rollback
void rollback() throws IllegalStateException, SecurityException, SystemException;
From source file:org.spring.data.gemfire.app.service.vendor.GemFireGemstoneService.java
protected static void rollback(final UserTransaction tx) { try {// w w w . ja v a 2s . co m if (tx != null) { tx.rollback(); } } catch (SystemException e) { throw new RuntimeException("Failed to rollback the UserTransaction!", e); } }
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 ww. j ava2 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.netpace.cms.sso.filter.TransactionalHelper.java
public Object doInTransaction(Transactionable callback) { UserTransaction tx = transactionService.getUserTransaction(); Object result;/*from ww w . j a v a 2 s . c o m*/ 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 av a 2s . 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: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 {//from ww w.ja v a2 s . co 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 {/* w ww. jav a 2 s.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:org.alfresco.trashcan.TrashcanCleanerTest.java
/** * /*from www . jav 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; } }
From source file:com.someco.servlets.AuthenticationFilter.java
/** * Set the authenticated user./*from ww w . ja v a2 s . co m*/ * * It does not check that the user exists at the moment. * * @param req * @param httpSess * @param userName */ private void setAuthenticatedUser(HttpServletRequest req, HttpSession httpSess, String userName) { // Set the authentication authComponent.setCurrentUser(userName); // Set up the user information UserTransaction tx = transactionService.getUserTransaction(); NodeRef homeSpaceRef = null; User user; try { tx.begin(); user = new User(userName, authService.getCurrentTicket(), personService.getPerson(userName)); homeSpaceRef = (NodeRef) nodeService.getProperty(personService.getPerson(userName), ContentModel.PROP_HOMEFOLDER); if (homeSpaceRef == null) { logger.warn("Home Folder is null for user '" + userName + "', using company_home."); homeSpaceRef = (NodeRef) nodeService.getRootNode(Repository.getStoreRef()); } user.setHomeSpaceId(homeSpaceRef.getId()); 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 set authenticated user", ex); } } // Store the user httpSess.setAttribute(AuthenticationHelper.AUTHENTICATION_USER, user); httpSess.setAttribute(LoginBean.LOGIN_EXTERNAL_AUTH, Boolean.TRUE); // Set the current locale from the Accept-Lanaguage header if available Locale userLocale = parseAcceptLanguageHeader(req, m_languages); if (userLocale != null) { httpSess.setAttribute(LOCALE, userLocale); httpSess.removeAttribute(MESSAGE_BUNDLE); } // Set the locale using the session I18NUtil.setLocale(Application.getLanguage(httpSess)); }
From source file:com.zaizi.alfresco.crowd.sso.filter.CrowdSSOAuthenticationFilter.java
/** * <p>Sets the username passed as parameter as current user, trying to create the user and home if possible, using person service</p> * @param request The {@code HttpServletRequest} request * @param httpSession the {@code HttpSession} session * @param userName The username//w ww . j ava 2 s . co m */ private void setAuthenticatedUser(HttpServletRequest request, HttpSession httpSession, String userName) { this.authenticationComponent.setCurrentUser(userName); UserTransaction tx = this.transactionService.getUserTransaction(); NodeRef homeSpaceRef = null; User user; try { tx.begin(); user = new User(userName, this.authenticationService.getCurrentTicket(), this.personService.getPerson(userName)); homeSpaceRef = (NodeRef) this.nodeService.getProperty(this.personService.getPerson(userName), ContentModel.PROP_HOMEFOLDER); if (homeSpaceRef == null) { this.logger.warn("Home Folder is null for user '" + userName + "', using company_home."); homeSpaceRef = this.nodeService.getRootNode(Repository.getStoreRef()); } user.setHomeSpaceId(homeSpaceRef.getId()); tx.commit(); } catch (Throwable ex) { this.logger.error(ex); try { tx.rollback(); } catch (Exception ex2) { this.logger.error("Failed to rollback transaction", ex2); } if ((ex instanceof RuntimeException)) { throw ((RuntimeException) ex); } throw new RuntimeException("Failed to set authenticated user", ex); } /* Setting the user as current user in the session */ httpSession.setAttribute(AuthenticationHelper.AUTHENTICATION_USER, user); /* Sets Login external auth */ httpSession.setAttribute(ALF_LOGIN_EXTERNAL_AUTH, true); }
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; }/* w ww .j a va2s. 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; }