void commitSession(final DelegatedWriteSession session) { logLifecycleMessage("Commiting session..."); UnitOfWork.getCurrent().accept(new ResourceProcessor(session)); this.transactionManager.currentTransaction().commit(); }
protected final void withinTransaction(Task<T> task) throws Exception{ Transaction tx = txManager.currentTransaction(); tx.begin(); boolean failed=false; try { this.logger.info(">> Started '{}'...",task.title); task.execute(this.sut); tx.commit(); this.logger.info(">> Completed '{}'.",task.title); } catch(Exception e) { this.logger.info(">> Failed '{}': {}.",task.title,e.getMessage()); failed=true; throw e; } finally { if(failed) { this.logger.debug("Transaction failed [active: {}]",tx.isActive()); } if(tx.isActive()) { this.logger.info("Attempting rollback..."); try { tx.rollback(); } catch (Exception e) { this.logger.error("Rollback failed",e); } } } }
private <T extends Resource> T publishResource(Class<? extends T> clazz, String templateId, Name<?> resourceName, String path) { Transaction transaction = RuntimeDelegate.getInstance().getTransactionManager().currentTransaction(); transaction.begin(); Resource newResource=this.modelFactory.createResource(this.tms.templateOfId(templateId),resourceName); T resource=clazz.cast(newResource); RuntimeDelegate.getInstance().getResourceRepository().add(resource); Endpoint endpoint=this.modelFactory.createEndpoint(path,resource,new Date(),EntityTag.createStrong(path)); RuntimeDelegate.getInstance().getEndpointRepository().add(endpoint); transaction.commit(); return resource; }
private Resource initialize(final String id, final String path) { final Transaction transaction= RuntimeDelegate. getInstance(). getTransactionManager(). currentTransaction(); transaction.begin(); try { this.uow = UnitOfWork.newCurrent(); final Resource resource= this.modelFactory.createResource( this.templateManagementService.templateOfId("personTemplate"), name(id)); final Endpoint endpoint=this.modelFactory.createEndpoint(path,resource,new Date(),EntityTag.createStrong(path)); RuntimeDelegate.getInstance().getResourceRepository().add(resource); RuntimeDelegate.getInstance().getEndpointRepository().add(endpoint); UnitOfWork.setCurrent(null); transaction.commit(); return resource; } finally { if(transaction.isActive()) { transaction.rollback(); } } }