Java Code Examples for org.springframework.transaction.interceptor.TransactionAspectSupport#currentTransactionStatus()
The following examples show how to use
org.springframework.transaction.interceptor.TransactionAspectSupport#currentTransactionStatus() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultPersonService.java From openregistry with Apache License 2.0 | 6 votes |
public ServiceExecutionResult<ReconciliationResult> reconcile(final ReconciliationCriteria reconciliationCriteria) throws IllegalArgumentException { Assert.notNull(reconciliationCriteria, "reconciliationCriteria cannot be null"); logger.info("reconcile start"); final Set validationErrors = this.validator.validate(reconciliationCriteria); if (!validationErrors.isEmpty()) { Iterator iter = validationErrors.iterator(); while (iter.hasNext()) { logger.info("validation errors: " + iter.next()); } logger.info("reconcile start"); //since because of existing design we cannot raise exception, we can only rollback the transaction through code //OR-384 if( TransactionAspectSupport.currentTransactionStatus()!=null){ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } return new GeneralServiceExecutionResult<ReconciliationResult>(validationErrors); } final ReconciliationResult result = this.reconciler.reconcile(reconciliationCriteria); //(reconciliationCriteria, result); return new GeneralServiceExecutionResult<ReconciliationResult>(result); }
Example 2
Source File: SpringAwareUserTransactionTest.java From alfresco-core with GNU Lesser General Public License v3.0 | 5 votes |
private void checkNoStatusOnThread() { try { TransactionAspectSupport.currentTransactionStatus(); fail("Spring transaction info is present outside of transaction boundaries"); } catch (NoTransactionException e) { // expected } }
Example 3
Source File: PlatformTransactionManagerAdapter.java From teiid-spring-boot with Apache License 2.0 | 5 votes |
public TransactionHolder getOrCreateTransaction(boolean start) { TransactionStatus status = null; try { //Spring managed transaction status = TransactionAspectSupport.currentTransactionStatus(); } catch (NoTransactionException e) { //Teiid programatically managed transaction if (start) { status = platformTransactionManager.getTransaction(NEW_TRANSACTION_DEFINITION); TransactionHolder holder = new TransactionHolder(status, new PlatformTransactionAdapter(status)); TRANSACTION_HOLDERS.set(holder); return holder; } else { try { status = platformTransactionManager.getTransaction(EXISTING_TRANSACTION_DEFINITION); //success means that there is one defined/associated, so we are safe to use //the thread local return TRANSACTION_HOLDERS.get(); } catch (TransactionException e1) { TRANSACTION_HOLDERS.remove(); } } } if (status == null) { return null; } synchronized (transactions) { PlatformTransactionAdapter adapter = transactions.get(status); if (adapter == null) { adapter = new PlatformTransactionAdapter(status); transactions.put(status, adapter); } return new TransactionHolder(status, adapter); } }
Example 4
Source File: TransactionUtils.java From spring-boot-start-current with Apache License 2.0 | 5 votes |
/** * 手动进行回滚事务. * 接口中如果 try catch 异常无法回滚时,这手动调用回滚处理 */ public static void rollback () { TransactionStatus transactionStatus = TransactionAspectSupport.currentTransactionStatus(); if ( null != transactionStatus ) { transactionStatus.setRollbackOnly(); } }
Example 5
Source File: DefaultPersonService.java From openregistry with Apache License 2.0 | 5 votes |
@PreAuthorize("hasPermission(#sorRole, 'admin')") public ServiceExecutionResult<SorRole> validateAndSaveRoleForSorPerson(final SorPerson sorPerson, final SorRole sorRole) { logger.info(" validateAndSaveRoleForSorPerson start"); Assert.notNull(sorPerson, "SorPerson cannot be null."); Assert.notNull(sorRole, "SorRole cannot be null."); // check if the SoR Role has an ID assigned to it already and assign source sor setRoleIdAndSource(sorRole, sorPerson.getSourceSor()); final Set validationErrors = this.validator.validate(sorRole); if (!validationErrors.isEmpty()) { //since because of existing design we cannot raise exception, we can only rollback the transaction through code //OR-384 if( TransactionAspectSupport.currentTransactionStatus()!=null){ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } return new GeneralServiceExecutionResult<SorRole>(validationErrors); } final SorPerson newSorPerson = this.personRepository.saveSorPerson(sorPerson); Person person = this.personRepository.findByInternalId(newSorPerson.getPersonId()); final SorRole newSorRole = newSorPerson.findSorRoleBySorRoleId(sorRole.getSorId()); //let sor role elector decide if this new role can be converted to calculated one sorRoleElector.addSorRole(newSorRole,person); person = recalculatePersonBiodemInfo(person, newSorPerson, RecalculationType.UPDATE, false); this.personRepository.savePerson(person); logger.info("validateAndSaveRoleForSorPerson end"); return new GeneralServiceExecutionResult<SorRole>(newSorRole); }
Example 6
Source File: DefaultPersonService.java From openregistry with Apache License 2.0 | 5 votes |
public ServiceExecutionResult<Person> addPerson(final ReconciliationCriteria reconciliationCriteria) throws ReconciliationException, IllegalArgumentException, SorPersonAlreadyExistsException { Assert.notNull(reconciliationCriteria, "reconciliationCriteria cannot be null"); logger.info("addPerson start"); if (reconciliationCriteria.getSorPerson().getSorId() != null && this.findBySorIdentifierAndSource(reconciliationCriteria.getSorPerson().getSourceSor(), reconciliationCriteria.getSorPerson().getSorId()) != null) { //throw new IllegalStateException("CANNOT ADD SAME SOR RECORD."); throw new SorPersonAlreadyExistsException(this.findBySorIdentifierAndSource(reconciliationCriteria.getSorPerson().getSourceSor(), reconciliationCriteria.getSorPerson().getSorId())); } final Set validationErrors = this.validator.validate(reconciliationCriteria); if (!validationErrors.isEmpty()) { Iterator iter = validationErrors.iterator(); while (iter.hasNext()) { logger.info("validation errors: " + iter.next()); } //since because of existing design we cannot raise exception, we can only rollback the transaction through code //OR-384 if( TransactionAspectSupport.currentTransactionStatus()!=null){ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } return new GeneralServiceExecutionResult<Person>(validationErrors); } final ReconciliationResult result = this.reconciler.reconcile(reconciliationCriteria); switch (result.getReconciliationType()) { case NONE: return new GeneralServiceExecutionResult<Person>(saveSorPersonAndConvertToCalculatedPerson(reconciliationCriteria)); case EXACT: return new GeneralServiceExecutionResult<Person>(addNewSorPersonAndLinkWithMatchedCalculatedPerson(reconciliationCriteria, result)); } this.criteriaCache.put(reconciliationCriteria, result); logger.info("addPerson start"); throw new ReconciliationException(result); }
Example 7
Source File: DefaultPersonService.java From openregistry with Apache License 2.0 | 5 votes |
public ServiceExecutionResult<SorRole> updateSorRole(final SorPerson sorPerson, final SorRole sorRole) { Assert.notNull(sorPerson, "sorPerson cannot be null."); Assert.notNull(sorRole, "sorRole cannot be null."); final Set validationErrors = this.validator.validate(sorRole); if (!validationErrors.isEmpty()) { //since because of existing design we cannot raise exception, we can only rollback the transaction through code //OR-384 if( TransactionAspectSupport.currentTransactionStatus()!=null){ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } return new GeneralServiceExecutionResult<SorRole>(validationErrors); } final SorRole savedSorRole = this.personRepository.saveSorRole(sorRole); final Person person = this.personRepository.findByInternalId(sorPerson.getPersonId()); final Role role = person.findRoleBySoRRoleId(savedSorRole.getId()); if(role!=null){ //update calculated role only if that role was previously converted to calculated one by sorRoleElector role.recalculate(savedSorRole); this.personRepository.savePerson(person); } //else //do nothing i.e. don't update the calculated role if SorRoleElector Previously decided not to convert this sor role to calculated role return new GeneralServiceExecutionResult<SorRole>(savedSorRole); }
Example 8
Source File: MetaTransactionalBean.java From micronaut-spring with Apache License 2.0 | 4 votes |
public String doSomething() { // should not throw final TransactionStatus transactionStatus = TransactionAspectSupport.currentTransactionStatus(); Assert.assertNotNull(transactionStatus); return "foo"; }
Example 9
Source File: TransactionalBean.java From micronaut-spring with Apache License 2.0 | 4 votes |
public String doSomething() { // should not throw final TransactionStatus transactionStatus = TransactionAspectSupport.currentTransactionStatus(); Assert.assertNotNull(transactionStatus); return "foo"; }
Example 10
Source File: DefaultPersonService.java From openregistry with Apache License 2.0 | 4 votes |
public ServiceExecutionResult<Person> validateAndSavePersonAndRole(final ReconciliationCriteria reconciliationCriteria) { logger.info(" validateAndSavePersonAndRole start"); SorPerson sorPerson = reconciliationCriteria.getSorPerson(); if (sorPerson == null || sorPerson.getRoles() == null) throw new IllegalArgumentException("Sor Person not found in provided criteria."); SorRole sorRole = reconciliationCriteria.getSorPerson().getRoles().get(0); if (sorRole == null) throw new IllegalArgumentException("Sor Role not found for provided criteria."); setRoleIdAndSource(sorRole, sorPerson.getSourceSor()); final Set validationErrors = this.validator.validate(sorRole); if (!validationErrors.isEmpty()) { //since because of existing design we cannot raise exception, we can only rollback the transaction through code //OR-384 if( TransactionAspectSupport.currentTransactionStatus()!=null){ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } return new GeneralServiceExecutionResult<Person>(validationErrors); } Long personId = sorPerson.getPersonId(); if (personId == null) { logger.info("calling saveSorPersonAndConvertToCalculatedPerson"); // add new Sor Person and roles, create calculated person return new GeneralServiceExecutionResult<Person>(saveSorPersonAndConvertToCalculatedPerson(reconciliationCriteria)); } else { // Add new Sor Person and role and link to the existing person Person thisPerson = this.personRepository.findByInternalId(personId); try { logger.info("calling addSorPersonAndLink"); Person savedPerson = this.addSorPersonAndLink(reconciliationCriteria, thisPerson); return new GeneralServiceExecutionResult<Person>(savedPerson); } catch (SorPersonAlreadyExistsException sorE) { throw new IllegalArgumentException("If a sor Person of the same source already exists, should call the other method to add the role only"); } } }
Example 11
Source File: DefaultPersonService.java From openregistry with Apache License 2.0 | 4 votes |
/** * Persists an SorPerson on update. * * @param sorPerson the person to update. * @return serviceExecutionResult. */ public ServiceExecutionResult<SorPerson> updateSorPerson(final SorPerson sorPerson) { final Set validationErrors = this.validator.validate(sorPerson); if (!validationErrors.isEmpty()) { Iterator iter = validationErrors.iterator(); while (iter.hasNext()) { logger.info("validation errors: " + iter.next()); } //since because of existing design we cannot raise exception, we can only rollback the transaction through code //OR-384 if( TransactionAspectSupport.currentTransactionStatus()!=null){ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } return new GeneralServiceExecutionResult<SorPerson>(validationErrors); } //do reconciliationCheck to make sure that modifications do not cause person to reconcile to a different person if (!this.reconciler.reconcilesToSamePerson(sorPerson)) { throw new IllegalStateException(); } // Iterate over any sorRoles setting sorid and source id if not specified by SoR. for (final SorRole sorRole : sorPerson.getRoles()){ setRoleIdAndSource(sorRole, sorPerson.getSourceSor()); } // Save Sor Person final SorPerson savedSorPerson = this.personRepository.saveSorPerson(sorPerson); Person person = this.findPersonById(savedSorPerson.getPersonId()); Assert.notNull(person, "person cannot be null."); logger.info("Verifying Number of calculated Roles before the calculate: "+ person.getRoles().size()); // Iterate over sorRoles. SorRoles may be new or updated. for (final SorRole savedSorRole:savedSorPerson.getRoles()){ logger.info("DefaultPersonService: savedSorPersonRole Found, savedSorRoleID: "+ savedSorRole.getId()); logger.info("DefaultPersonService: savedSorPersonRole Found, Role Must be newly added."); //let sor role elector decide if this new role can be converted to calculated one sorRoleElector.addSorRole(savedSorRole,person); logger.info("Verifying Number of calculated Roles after calculate: "+ person.getRoles().size()); } for (final IdentifierAssigner ia : this.identifierAssigners) { ia.addIdentifierTo(sorPerson, person); } person = recalculatePersonBiodemInfo(person, savedSorPerson, RecalculationType.UPDATE, false); person =this.personRepository.savePerson(person); return new GeneralServiceExecutionResult<SorPerson>(savedSorPerson); }
Example 12
Source File: TransactionManual.java From rebuild with GNU General Public License v3.0 | 2 votes |
/** * Shadow for TransactionAspectSupport#currentTransactionStatus * * @return */ public static TransactionStatus currentTransactionStatus() { return TransactionAspectSupport.currentTransactionStatus(); }