List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition setName
public final void setName(String name)
From source file:org.broadleafcommerce.openadmin.server.service.persistence.entitymanager.BroadleafEntityManagerInvocationHandler.java
protected Object executeInTransaction(Executable executable, PlatformTransactionManager txManager) throws Throwable { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("SandBoxTx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); Object response;// w w w. j a v a2 s .c om TransactionStatus status = txManager.getTransaction(def); try { response = executable.execute(); } catch (Throwable ex) { txManager.rollback(status); throw ex; } txManager.commit(status); return response; }
From source file:org.collectionspace.services.authorization.spring.SpringAuthorizationProvider.java
TransactionStatus beginTransaction(String name) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); // explicitly setting the transaction name is something that can only be done programmatically def.setName(name); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); return getTxManager().getTransaction(def); }
From source file:org.craftercms.studio.impl.v1.service.dependency.DependencyServiceImpl.java
@Override public Set<String> upsertDependencies(String site, String path) throws SiteNotFoundException, ContentNotFoundException, ServiceException { Set<String> toRet = new HashSet<String>(); logger.debug("Resolving dependencies for content site: " + site + " path: " + path); Map<String, Set<String>> dependencies = dependencyResolver.resolve(site, path); List<DependencyEntity> dependencyEntities = new ArrayList<>(); if (dependencies != null) { logger.debug(/*from ww w . ja v a2 s . com*/ "Found " + dependencies.size() + " dependencies. Create entities to insert into database."); for (String type : dependencies.keySet()) { dependencyEntities .addAll(createDependencyEntities(site, path, dependencies.get(type), type, toRet)); } logger.debug("Preparing transaction for database updates."); DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition(); defaultTransactionDefinition.setName("upsertDependencies"); logger.debug("Starting transaction."); TransactionStatus txStatus = transactionManager.getTransaction(defaultTransactionDefinition); try { logger.debug("Delete all source dependencies for site: " + site + " path: " + path); deleteAllSourceDependencies(site, path); logger.debug("Insert all extracted dependencies entries for site: " + site + " path: " + path); insertDependenciesIntoDatabase(dependencyEntities); logger.debug("Committing transaction."); transactionManager.commit(txStatus); } catch (Exception e) { logger.debug("Rolling back transaction."); transactionManager.rollback(txStatus); throw new ServiceException("Failed to upsert dependencies for site: " + site + " path: " + path, e); } } return toRet; }
From source file:org.craftercms.studio.impl.v1.service.dependency.DependencyServiceImpl.java
@Override public Set<String> upsertDependencies(String site, List<String> paths) throws SiteNotFoundException, ContentNotFoundException, ServiceException { Set<String> toRet = new HashSet<String>(); List<DependencyEntity> dependencyEntities = new ArrayList<>(); StringBuilder sbPaths = new StringBuilder(); logger.debug("Resolving dependencies for list of paths."); for (String path : paths) { sbPaths.append("\n").append(path); logger.debug("Resolving dependencies for content site: " + site + " path: " + path); Map<String, Set<String>> dependencies = dependencyResolver.resolve(site, path); if (dependencies != null) { logger.debug("Found " + dependencies.size() + " dependencies. " + "Create entities to insert into database."); for (String type : dependencies.keySet()) { dependencyEntities//from w w w. jav a 2 s . c o m .addAll(createDependencyEntities(site, path, dependencies.get(type), type, toRet)); } } } logger.debug("Preparing transaction for database updates."); DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition(); defaultTransactionDefinition.setName("upsertDependencies"); logger.debug("Starting transaction."); TransactionStatus txStatus = transactionManager.getTransaction(defaultTransactionDefinition); try { logger.debug("Delete all source dependencies for list of paths site: " + site); for (String path : paths) { deleteAllSourceDependencies(site, path); } logger.debug("Insert all extracted dependencies entries lof list of paths for site: " + site); insertDependenciesIntoDatabase(dependencyEntities); logger.debug("Committing transaction."); transactionManager.commit(txStatus); } catch (Exception e) { logger.debug("Rolling back transaction."); transactionManager.rollback(txStatus); throw new ServiceException( "Failed to upsert dependencies for site: " + site + " paths: " + sbPaths.toString(), e); } return toRet; }
From source file:org.ednovo.gooru.domain.service.storage.S3ResourceHandler.java
protected TransactionStatus initTransaction(String name, boolean isReadOnly) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName(AUTHENTICATE_USER); if (isReadOnly) { def.setReadOnly(isReadOnly);/* w ww . j ava 2s . c om*/ } else { def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); } return getTransactionManager().getTransaction(def); }
From source file:org.eurekastreams.commons.server.async.AsyncActionController.java
/** * Execute the supplied {@link AsyncAction} with the given {@link AsyncActionContext}. * /*from w ww.j av a 2s. c o m*/ * @param inAsyncActionContext * - instance of the {@link AsyncActionContext} with which to execution the {@link AsyncAction}. * @param inAsyncAction * - instance of the {@link AsyncAction} to execute. * @return - results from the execution of the AsyncAction. * * - GeneralException - when an unexpected error occurs. - ValidationException - when a * {@link ValidationException} occurs. - ExecutionException - when an {@link ExecutionException} occurs. */ public Serializable execute(final AsyncActionContext inAsyncActionContext, final AsyncAction inAsyncAction) { Serializable results = null; DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName(inAsyncAction.toString()); transDef.setReadOnly(inAsyncAction.isReadOnly()); TransactionStatus transStatus = transMgr.getTransaction(transDef); try { inAsyncAction.getValidationStrategy().validate(inAsyncActionContext); results = inAsyncAction.getExecutionStrategy().execute(inAsyncActionContext); transMgr.commit(transStatus); } catch (ValidationException vex) { onException(transStatus); logger.warn("Validation failed for the current action.", vex); for (Entry<String, String> currentError : vex.getErrors().entrySet()) { logger.warn("Validation key: " + currentError.getKey() + ", value: " + currentError.getValue()); } throw vex; } catch (ExecutionException eex) { onException(transStatus); logger.error("Error occurred during execution.", eex); throw eex; } catch (Exception ex) { onException(transStatus); logger.error("Error occurred performing transaction.", ex); throw new GeneralException(ex); } return results; }
From source file:org.eurekastreams.commons.server.async.AsyncActionController.java
/** * This method executes a {@link TaskHandlerAction} with the supplied {@link AsyncActionContext}. * /* w ww. j ava 2 s . c om*/ * @param inAsyncActionContext * - instance of the {@link AsyncActionContext} associated with this request. * @param inTaskHandlerAction * - instance of the {@link TaskHandlerAction}. * @return - results of the execution. * * - GeneralException - when an unexpected error occurs. - ValidationException - when a * {@link ValidationException} occurs. - ExecutionException - when an {@link ExecutionException} occurs. */ @SuppressWarnings("unchecked") public Serializable execute(final AsyncActionContext inAsyncActionContext, final TaskHandlerAction inTaskHandlerAction) { Serializable results = null; DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName(inTaskHandlerAction.toString()); transDef.setReadOnly(inTaskHandlerAction.isReadOnly()); TransactionStatus transStatus = transMgr.getTransaction(transDef); // Assemble special context for TaskHandler actions. TaskHandlerActionContext<ActionContext> taskHandlerContext = new TaskHandlerActionContext<ActionContext>( inAsyncActionContext, new ArrayList<UserActionRequest>()); try { inTaskHandlerAction.getValidationStrategy().validate(inAsyncActionContext); results = inTaskHandlerAction.getExecutionStrategy().execute(taskHandlerContext); transMgr.commit(transStatus); } catch (ValidationException vex) { onException(transStatus); logger.warn("Validation failed for the current action.", vex); for (Entry<String, String> currentError : vex.getErrors().entrySet()) { logger.warn("Validation key: " + currentError.getKey() + ", value: " + currentError.getValue()); } throw vex; } catch (ExecutionException eex) { onException(transStatus); logger.error("Error occurred during execution.", eex); throw eex; } catch (Exception ex) { onException(transStatus); logger.error("Error occurred performing transaction.", ex); throw new GeneralException(ex); } // Submit the TaskRequests gathered from the execution strategy into the TaskHandlerContext to the TaskHandler. try { TaskHandler currentTaskHandler = inTaskHandlerAction.getTaskHandler(); for (UserActionRequest currentRequest : taskHandlerContext.getUserActionRequests()) { currentTaskHandler.handleTask(currentRequest); } } catch (Exception ex) { logger.error("Error occurred posting UserActionRequests to the queue.", ex); throw (new GeneralException("Error occurred posting UserActionRequests to the queue.", ex)); } return results; }
From source file:org.eurekastreams.commons.server.service.ServiceActionController.java
/** * Execute the supplied {@link ServiceAction} with the given {@link PrincipalActionContext}. * * @param inServiceActionContext/*from ww w . j a va2s .c o m*/ * - instance of the {@link PrincipalActionContext} with which to execution the {@link ServiceAction}. * @param inServiceAction * - instance of the {@link ServiceAction} to execute. * @return - results from the execution of the ServiceAction. * * - GeneralException - when an unexpected error occurs. - ValidationException - when a * {@link ValidationException} occurs. - AuthorizationException - when an {@link AuthorizationException} * occurs. - ExecutionException - when an {@link ExecutionException} occurs. */ public Serializable execute(final PrincipalActionContext inServiceActionContext, final ServiceAction inServiceAction) { Serializable results = null; DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName(inServiceAction.toString()); transDef.setReadOnly(inServiceAction.isReadOnly()); TransactionStatus transStatus = transMgr.getTransaction(transDef); try { inServiceAction.getValidationStrategy().validate(inServiceActionContext); inServiceAction.getAuthorizationStrategy().authorize(inServiceActionContext); results = inServiceAction.getExecutionStrategy().execute(inServiceActionContext); transMgr.commit(transStatus); } catch (ValidationException vex) { onException(transStatus); logger.warn("Validation failed for the current action.", vex); for (Entry<String, String> currentError : vex.getErrors().entrySet()) { logger.warn("Validation key: " + currentError.getKey() + ", value: " + currentError.getValue()); } throw vex; } catch (AuthorizationException aex) { onException(transStatus); logger.warn("Authorization failed for the current action.", aex); throw aex; } catch (ExecutionException eex) { onException(transStatus); logger.error("Error occurred during execution.", eex); throw eex; } catch (Exception ex) { onException(transStatus); logger.error("Error occurred performing transaction.", ex); throw new GeneralException(ex); } return results; }
From source file:org.eurekastreams.commons.server.service.ServiceActionController.java
/** * This method executes a {@link TaskHandlerAction} with the supplied {@link PrincipalActionContext}. * * @param inServiceActionContext/* ww w. j a v a 2 s.c o m*/ * - instance of the {@link PrincipalActionContext} associated with this request. * @param inTaskHandlerAction * - instance of the {@link TaskHandlerAction}. * @return - results of the execution. * * - GeneralException - when an unexpected error occurs. - ValidationException - when a * {@link ValidationException} occurs. - AuthorizationException - when an {@link AuthorizationException} * occurs. - ExecutionException - when an {@link ExecutionException} occurs. */ public Serializable execute(final PrincipalActionContext inServiceActionContext, final TaskHandlerAction inTaskHandlerAction) { Serializable results = null; DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName(inTaskHandlerAction.toString()); transDef.setReadOnly(inTaskHandlerAction.isReadOnly()); TransactionStatus transStatus = transMgr.getTransaction(transDef); TaskHandlerActionContext<PrincipalActionContext> taskHandlerContext = // \n new TaskHandlerActionContext<PrincipalActionContext>(inServiceActionContext, new ArrayList<UserActionRequest>()); try { inTaskHandlerAction.getValidationStrategy().validate(inServiceActionContext); inTaskHandlerAction.getAuthorizationStrategy().authorize(inServiceActionContext); results = inTaskHandlerAction.getExecutionStrategy().execute(taskHandlerContext); transMgr.commit(transStatus); } catch (ValidationException vex) { onException(transStatus); logger.warn("Validation failed for the current action.", vex); for (Entry<String, String> currentError : vex.getErrors().entrySet()) { logger.warn("Validation key: " + currentError.getKey() + ", value: " + currentError.getValue()); } throw vex; } catch (AuthorizationException aex) { onException(transStatus); logger.warn("Authorization failed for the current action.", aex); throw aex; } catch (ExecutionException eex) { onException(transStatus); logger.error("Error occurred during execution.", eex); throw eex; } catch (Exception ex) { onException(transStatus); logger.error("Error occurred performing transaction.", ex); throw new GeneralException(ex); } // Submit the TaskRequests gathered from the execution strategy into the TaskHandlerContext to the TaskHandler. try { TaskHandler currentTaskHandler = inTaskHandlerAction.getTaskHandler(); for (UserActionRequest currentRequest : taskHandlerContext.getUserActionRequests()) { currentTaskHandler.handleTask(currentRequest); } } catch (Exception ex) { logger.error("Error occurred posting UserActionRequests to the queue.", ex); throw (new GeneralException("Error occurred posting UserActionRequests to the queue.", ex)); } return results; }
From source file:org.eurekastreams.server.service.servlets.UploadBannerServlet.java
/** * Gets the domain entity.//from www. jav a 2 s. c om * * @param inName * the name used to find the domain entity * @param request * the http request object. * @return the domain entity * @throws ServletException * when anything goes wrong */ @SuppressWarnings("deprecation") @Override protected DomainEntity getDomainEntity(final String inName, final HttpServletRequest request) throws ServletException { PlatformTransactionManager transMgr = (PlatformTransactionManager) getSpringContext() .getBean("transactionManager"); DefaultTransactionDefinition transDef = new DefaultTransactionDefinition(); transDef.setName("getOrg"); transDef.setReadOnly(true); TransactionStatus transStatus = transMgr.getTransaction(transDef); String type = request.getParameter("type"); GetAllPersonIdsWhoHaveGroupCoordinatorAccess groupCoordinatorMapper = // (GetAllPersonIdsWhoHaveGroupCoordinatorAccess) getSpringContext() .getBean("getAllPersonIdsWhoHaveGroupCoordinatorAccess"); DomainGroupMapper groupMapper = (DomainGroupMapper) getSpringContext().getBean("jpaGroupMapper"); String entityName = request.getParameter("entityName"); if (type.equals("DomainGroup")) { DomainGroup group = groupMapper.findByShortName(entityName); if (group == null) { throw new ServletException("Group: " + entityName + " not found"); } if (groupCoordinatorMapper.hasGroupCoordinatorAccessRecursively(inName, group.getId())) { transMgr.commit(transStatus); return group; } throw new ServletException("User " + inName + " is not a coordinator of group: " + group.getName()); } else { throw new ServletException("Type of object is " + type + " is not supported"); } }