List of usage examples for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED
int PROPAGATION_REQUIRED
To view the source code for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED.
Click Source Link
From source file:com.wlami.mibox.server.util.SpringTxHelper.java
/** * Start a spring transaction.//from w ww. ja va2 s .c o m * * @param transactionName * @return */ public static TransactionStatus startTransaction(String transactionName, JpaTransactionManager jpaTransactionManager) { DefaultTransactionDefinition definition = new DefaultTransactionDefinition(); definition.setName(transactionName); definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus transactionStatus = jpaTransactionManager.getTransaction(definition); return transactionStatus; }
From source file:com.thinkenterprise.domain.BoundedContextInitializer.java
@PostConstruct public void init() { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("InitTx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = txManager.getTransaction(def); try {//from ww w .j ava 2s . com initRoutes(); } catch (Exception ex) { txManager.rollback(status); throw ex; } txManager.commit(status); }
From source file:com.example.switchyard.idempotent.jpa.IdempotentJpaConsumer.java
private static TransactionTemplate transactionTemplate() { TransactionTemplate transactionTemplate = new TransactionTemplate(); transactionTemplate.setTransactionManager(new JtaTransactionManager(getTransactionManager())); transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); return transactionTemplate; }
From source file:localdomain.localhost.service.SampleDataCreatorInitializer.java
@Override public void afterPropertiesSet() throws Exception { TransactionStatus status = transactionManager .getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED)); try {//from w w w. j a v a 2 s .c o m Query query = em.createQuery("select count(p) from Product p"); long count = (Long) query.getSingleResult(); if (count == 0) { logger.info("Database is empty, insert demo products"); em.persist(new Product("Long Island Iced Tea", "Type of alcoholic mixed drink made with, among other ingredients, vodka, gin, tequila, and rum")); em.persist(new Product("Sex on the beach", "Made from vodka, peach schnapps, orange juice, and cranberry juice")); logger.info("Demo products inserted in the database"); } else { logger.info("Products found in the database, don't insert new ones"); } transactionManager.commit(status); } catch (RuntimeException e) { try { transactionManager.rollback(status); } catch (Exception rollbackException) { logger.warn("Silently ignore", rollbackException); } throw e; } }
From source file:com.cloudbees.demo.beesshop.service.BeesShopInitializer.java
@Override public void afterPropertiesSet() { TransactionStatus status = transactionManager .getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED)); try {//w ww. java 2s .c o m Query query = em.createQuery("select count(p) from Product p"); long count = (Long) query.getSingleResult(); if (count == 0) { logger.info("Database is empty, insert demo products"); em.persist(new Product().withName("Buckwheat Honey - One pint").withDescription( "Dark, full-bodied honey from New York state. Mildly sweet, with flavors of molasses, caramel, and smoke. Buckwheat honey is high in minerals and antioxidant compounds, and rumored to help ease coughing from upper respiratory infections.") .withPriceInCents(1199).withProductUrl("http://www.huney.net/gourmet-honey/") .withPhotoUrl("/img/buckwheat-honey.jpg") .withPhotoCredit("http://huneynet.fatcow.com/store/media/BuckwheatHoney.jpg") .withTags("honey")); em.persist(new Product().withName("Cotton Honey - One Pint").withDescription( "Cotton honey from west Texas. This unique honey is naturally crystallized and spreadable like butter. It is very sweet with a mild creamy flavor and a clean, fresh smell. Our cotton honey is unstrained and contains pollen and small flecks of beeswax. ") .withPriceInCents(1199).withProductUrl("http://www.huney.net/gourmet-honey/") .withPhotoUrl("/img/cotton-honey.jpg") .withPhotoCredit("http://huneynet.fatcow.com/store/media/West_Texas_Cotton.jpg") .withTags("honey")); em.persist(new Product().withName("Honey Shot- 5g sachet Eucalyptus Honey (100%)").withDescription( "Honey 'Shots' is a product developed on the basis of an athletes needs to maintain energy levels when training it then moved to mountain biking as cyclists wanted an alternative to synthesised sports energy bars and sweets. ...") .withPriceInCents(100).withPhotoUrl("/img/Sports-Energy-Shot-web.png") .withPhotoCredit( "http://www.thehivehoneyshop.co.uk/product_images/thumbs/t_Sports-Energy-Shot-web.jpg") .withProductUrl("http://www.thehivehoneyshop.co.uk/itemdetail.asp?itemid=770") .withTags("honey", "beverage")); } else { logger.info("Products found in the database, don't insert new ones"); } transactionManager.commit(status); } catch (RuntimeException e) { try { transactionManager.rollback(status); } catch (Exception rollbackException) { logger.warn("Silently ignore", rollbackException); } throw e; } }
From source file:org.codehaus.cargo.sample.testdata.jdbc.TestServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("cargotest"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = txManager.getTransaction(def); try {//from w ww.j av a 2 s . c om dao.create("Adrian", "Cole"); } catch (RuntimeException ex) { txManager.rollback(status); throw ex; } txManager.commit(status); if (dao.selectAll().size() != 1) throw new RuntimeException("Commit didn't work"); PrintWriter out = response.getWriter(); out.print("all good!"); out.close(); }
From source file:org.caratarse.auth.services.plugins.transactions.OpenTransactionPlugin.java
@Override public void process(Request request) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = transactionManager.getTransaction(def); transaction.set(status);/*ww w . j a v a 2s. c o m*/ }
From source file:org.alfresco.util.transaction.SpringAwareUserTransactionTest.java
private UserTransaction getTxn() { return new SpringAwareUserTransaction(transactionManager, false, TransactionDefinition.ISOLATION_DEFAULT, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.TIMEOUT_DEFAULT); }
From source file:org.rivu.image.web.servlet.ServletInterceptor.java
@Override public String intercept(ActionInvocation ai) throws Exception { Object o = ai.getAction();// ww w .j a va 2s. c o m /** * ? */ if (o instanceof ServletHandler) { /** * Request */ ((ServletHandler) o).setServletRequest(ServletActionContext.getRequest()); /** * Response */ ((ServletHandler) o).setServletResponse(ServletActionContext.getResponse()); ((ServletHandler) o).setAction(ai.getProxy().getNamespace(), ai.getProxy().getActionName()); ServletActionContext.getResponse().setHeader("Pragma", "No-cache"); ServletActionContext.getResponse().setHeader("Cache-Control", "no-cache"); ServletActionContext.getResponse().setHeader("Cache-Control", "no-store"); ServletActionContext.getResponse().setDateHeader("Expires", 0); } def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); try { ret = ai.invoke(); } catch (Exception e) { e.printStackTrace(); ServletActionContext.getResponse().addHeader("emsg", e.getMessage()); ServletActionContext.getResponse().sendError(400); return null; } return ret; }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.migration.FixCoreferenceFeatures.java
private void doMigration() { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("migrationRoot"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = null;/*from w w w .jav a2 s . c om*/ try { status = txManager.getTransaction(def); Query q = entityManager.createQuery("UPDATE AnnotationFeature \n" + "SET type = :fixedType \n" + "WHERE type = :oldType \n" + "AND name in (:featureNames)"); // This condition cannot be applied: // "AND layer.type = :layerType" // q.setParameter("layerType", CHAIN_TYPE); // http://stackoverflow.com/questions/16506759/hql-is-generating-incomplete-cross-join-on-executeupdate // However, the risk that the migration upgrades the wrong featuers is still very low // even without this additional condition q.setParameter("featureNames", Arrays.asList(COREFERENCE_RELATION_FEATURE, COREFERENCE_TYPE_FEATURE)); q.setParameter("oldType", "de.tudarmstadt.ukp.dkpro.core.api.coref.type.Coreference"); q.setParameter("fixedType", CAS.TYPE_NAME_STRING); int changed = q.executeUpdate(); if (changed > 0) { log.info("DATABASE UPGRADE PERFORMED: [" + changed + "] coref chain features had their type fixed"); } txManager.commit(status); } finally { if (status != null && !status.isCompleted()) { txManager.rollback(status); } } }