List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition setName
public final void setName(String name)
From source file:com.wlami.mibox.server.util.SpringTxHelper.java
/** * Start a spring transaction.// ww w .ja va 2 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: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 w w. j a va2s . co m*/ 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: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 w ww .ja v a 2s . c o m initRoutes(); } catch (Exception ex) { txManager.rollback(status); throw ex; } txManager.commit(status); }
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;// ww w . j a va 2 s.com 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); } } }
From source file:com.devicehive.service.IdentityProviderServiceTest.java
private IdentityProviderVO createIdentityProvider() { IdentityProviderVO identityProvider = new IdentityProviderVO(); identityProvider.setName(RandomStringUtils.randomAlphabetic(10)); identityProvider.setTokenEndpoint(RandomStringUtils.randomAlphabetic(10)); identityProvider.setApiEndpoint(RandomStringUtils.randomAlphabetic(10)); identityProvider.setVerificationEndpoint(RandomStringUtils.randomAlphabetic(10)); DefaultTransactionDefinition tx = new DefaultTransactionDefinition(); tx.setName("CreateTx"); tx.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = txManager.getTransaction(tx); try {/* w w w . j ava 2 s . c o m*/ providerDao.persist(identityProvider); } catch (Exception ex) { txManager.rollback(status); throw ex; } finally { try { txManager.commit(status); } catch (Exception ex) { txManager.rollback(status); } } return identityProvider; }
From source file:com.krawler.spring.crm.spreadSheet.spreadSheetController.java
public ModelAndView saveModuleRecordStyle(HttpServletRequest request, HttpServletResponse response) throws ServletException { boolean success = false; //Create transaction DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("JE_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txnManager.getTransaction(def); try {/*from www .j a va2 s . c o m*/ if (StringUtil.bNull(request.getParameter("jsondata"))) { String jsondata = request.getParameter("jsondata"); JSONArray jarr = new JSONArray(jsondata); String classname = "com.krawler.crm.database.tables.Crm" + request.getParameter("module"); for (int i = 0; i < jarr.length(); i++) { JSONObject jo = jarr.getJSONObject(i); spreadsheetService.saveModuleRecordStyle(jo.getString("id"), classname, jo.getString("cellStyle")); } } txnManager.commit(status); success = true; } catch (Exception e) { LOG.warn(e.getMessage()); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", "{success:" + success + "}"); }
From source file:es.urjc.mctwp.service.ServiceDelegate.java
private TransactionStatus getTxStatus(String action, boolean readOnly, String isolation, String propagation) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName(action); //Set readOnly configuration def.setReadOnly(readOnly);/*from w w w . j a v a 2 s . c om*/ //Set isolation configuration if (isolation.equals(Command.ISOLATION_DEFAULT)) { def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_DEFAULT); } //Set propagation configuration if (propagation.equals(Command.PROPAGATION_REQUIRED)) { def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRED); } return txManager.getTransaction(def); }
From source file:com.krawler.spring.common.CommonFnController.java
public ModelAndView changeUserPassword(HttpServletRequest request, HttpServletResponse response) { JSONObject jobj = new JSONObject(); KwlReturnObject kmsg = null;//w w w . ja va2s . c om //Create transaction DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("CF_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = txnManager.getTransaction(def); try { String platformURL = this.getServletContext().getInitParameter("platformURL"); HashMap<String, Object> requestParams = new HashMap<String, Object>(); requestParams.put("currentpassword", StringUtil.checkForNull(request.getParameter("currentpassword"))); requestParams.put("changepassword", StringUtil.checkForNull(request.getParameter("changepassword"))); requestParams.put("userid", sessionHandlerImpl.getUserid(request)); requestParams.put("companyid", sessionHandlerImpl.getCompanyid(request)); requestParams.put("remoteapikey", ConfigReader.getinstance().get("remoteapikey")); kmsg = profileHandlerDAOObj.changeUserPassword(platformURL, requestParams); jobj = (JSONObject) kmsg.getEntityList().get(0); txnManager.commit(status); jobj.put("success", true); } catch (Exception e) { System.out.println(e.getMessage()); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", jobj.toString()); }
From source file:nz.co.senanque.functions.CustomerDAOImpl.java
@SuppressWarnings({ "unused", "unchecked" }) public void transactionTester() { final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); // explicitly setting the transaction name is something that can only be done programmatically def.setName("SomeTxName"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setReadOnly(true);//from w ww .ja v a 2 s .c om final TransactionStatus status = m_txManager.getTransaction(def); Session session = getSessionFactory().getCurrentSession(); final Transaction transaction = session.getTransaction(); Query query = session.createQuery("select p from nz.co.senanque.madura.sandbox.Customer p"); List<Customer> customers = query.list(); for (Customer customer : customers) { final Session session1 = getSessionFactory().openSession(); final Session currentSession = getSessionFactory().getCurrentSession(); final Transaction transaction1 = currentSession.getTransaction(); getSubTransaction().process(customer); } }
From source file:nz.co.senanque.base.CustomerDAOImpl.java
@SuppressWarnings("unused") public void transactionTester() { final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); // explicitly setting the transaction name is something that can only be done programmatically def.setName("SomeTxName"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setReadOnly(true);/*from w w w.j a v a 2s . c o m*/ final TransactionStatus status = m_txManager.getTransaction(def); Session session = getSessionFactory().getCurrentSession(); final Transaction transaction = session.getTransaction(); Query query = session.createQuery("select p from nz.co.senanque.madura.sandbox.Customer p"); @SuppressWarnings("unchecked") List<Customer> customers = query.list(); for (Customer customer : customers) { final Session session1 = getSessionFactory().openSession(); final Session currentSession = getSessionFactory().getCurrentSession(); final Transaction transaction1 = currentSession.getTransaction(); getSubTransaction().process(customer); } }