List of usage examples for javax.transaction Status STATUS_ACTIVE
int STATUS_ACTIVE
To view the source code for javax.transaction Status STATUS_ACTIVE.
Click Source Link
From source file:org.ms123.common.ea.BaseEAServiceImpl.java
private Map importCommunications(String storeId, String basedir) { StoreDesc sdesc = StoreDesc.get(storeId); PersistenceManager pm = m_nucleusService.getPersistenceManagerFactory(sdesc).getPersistenceManager(); UserTransaction ut = m_nucleusService.getUserTransaction(); Map mapping = initCommunication(); try {//from w ww . j a v a 2 s .com LabeledCSVParser lp = new LabeledCSVParser( new ExcelCSVParser(new FileInputStream(new File(basedir, "Kommunikation.csv")))); System.out.println("Persisting communication"); int num = 0; Class _contact = m_nucleusService.getClass(sdesc, "Contact"); Class _company = m_nucleusService.getClass(sdesc, "Company"); while (lp.getLine() != null) { String nummer = lp.getValueByLabel("Nummer"); Object c = getObject(pm, _contact, nummer); if (c == null) { c = getObject(pm, _company, nummer); if (c == null) { continue; } } if (ut.getStatus() != Status.STATUS_ACTIVE) { ut.begin(); } String typ = lp.getValueByLabel("Typ"); typ = typ.toLowerCase(); String adresse = lp.getValueByLabel("Adresse"); Object comm = PropertyUtils.getProperty(c, "communication"); if (comm == null) { comm = m_nucleusService.getClass(sdesc, "Communication").newInstance(); PropertyUtils.setProperty(c, "communication", comm); pm.makePersistent(comm); } String[] m1 = (String[]) mapping.get(typ); if (m1 == null) { System.out.println("typ(" + typ + "): not found"); continue; } String field = m1[0]; BeanUtils.setProperty(comm, field, adresse); pm.makePersistent(comm); if ((num % 1000) == 1) { System.out.println(num + ":\t" + new Date().getTime()); ut.commit(); } num++; } if (ut.getStatus() == Status.STATUS_ACTIVE) { ut.commit(); } System.out.println("Communication have been persisted"); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { pm.close(); } return null; }
From source file:org.ms123.common.ea.BaseEAServiceImpl.java
private Map importZipcodes(String storeId, String basedir) { StoreDesc sdesc = StoreDesc.get(storeId); PersistenceManager pm = m_nucleusService.getPersistenceManagerFactory(sdesc).getPersistenceManager(); UserTransaction ut = m_nucleusService.getUserTransaction(); Class _company = m_nucleusService.getClass(sdesc, "Company"); Class _contact = m_nucleusService.getClass(sdesc, "Contact"); Map mapping = initZipcodes(); try {/* w w w . j a v a 2 s . c o m*/ LabeledCSVParser lp = new LabeledCSVParser( getCSVParser(new FileInputStream(new File(basedir, "zipcodes.csv")))); System.out.println("Persisting zipcodes"); int num = 0; while (lp.getLine() != null) { if (ut.getStatus() != Status.STATUS_ACTIVE) { ut.begin(); } // Zipcode zipcode = new Zipcode(); Object zipcode = m_nucleusService.getClass(sdesc, "Zipcode").newInstance(); String gemeindekennziffer = lp.getValueByLabel("Gemeindekennziffer"); String ortname = lp.getValueByLabel("ORTNAME"); String plz = lp.getValueByLabel("PLZ"); String lkz = lp.getValueByLabel("LKZ"); PropertyUtils.setProperty(zipcode, "lkz", lkz); PropertyUtils.setProperty(zipcode, "plz", plz); PropertyUtils.setProperty(zipcode, "ortname", ortname); PropertyUtils.setProperty(zipcode, "gemeindekennziffer", gemeindekennziffer); Collection cl = getContactList(pm, _company, plz); if (cl != null) { for (Object cx : cl) { PropertyUtils.setProperty(cx, "zipcode", zipcode); PropertyUtils.setProperty(cx, "lkz", lkz); } } cl = getContactList(pm, _contact, plz); if (cl != null) { for (Object cx : cl) { PropertyUtils.setProperty(cx, "zipcode", zipcode); PropertyUtils.setProperty(cx, "lkz", lkz); } } pm.makePersistent(zipcode); if ((num % 1000) == 1) { System.out.println(num + ":\t" + new Date().getTime()); ut.commit(); } num++; } if (ut.getStatus() == Status.STATUS_ACTIVE) { ut.commit(); } System.out.println("Contact and Book have been persisted"); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { pm.close(); } return null; }
From source file:org.ms123.common.ea.EACompanyContactImporter.java
private void doImport() throws Exception { LabeledCSVParser lp = new LabeledCSVParser( new ExcelCSVParser(new FileInputStream(new File(m_basedir, "ea.csv")))); int status;/* ww w . j a v a2 s. c om*/ PersistenceManager pm = m_nucleusService.getPersistenceManagerFactory(m_storeDesc).getPersistenceManager(); UserTransaction ut = m_nucleusService.getUserTransaction(); int num = 0; Object company = null; String lastCompanyId = null; while (lp.getLine() != null) { String type = lp.getValueByLabel("type"); String companyId = lp.getValueByLabel("companyId"); if (type.startsWith("nok")) continue; if (ut.getStatus() != Status.STATUS_ACTIVE) { ut.begin(); } String s[] = getStateAndEntity(type); Object obj = populate(lp, s[0], s[1]); if (!isEmpty(companyId)) { if (!companyId.equals(lastCompanyId)) { company = obj; lastCompanyId = companyId; } if (s[0].equals("contact")) { Set cl = (Set) PropertyUtils.getProperty(company, "contact_list"); if (cl == null) { cl = new HashSet(); PropertyUtils.setProperty(company, "contact_list", cl); } cl.add(obj); } } pm.makePersistent(obj); if ((num % 1000) == 1) { System.out.println(num + ":\t" + new Date().getTime()); ut.commit(); } num++; } if (ut.getStatus() == Status.STATUS_ACTIVE) { ut.commit(); } }
From source file:org.ms123.common.nucleus.NucleusServiceImpl.java
private void _close(StoreDesc sdesc) { debug("Nucleus._close:" + sdesc); AbstractPersistenceManagerLoader pml = m_loaders.get(sdesc); if (pml != null) { try {/*from w ww.j a va2s . c o m*/ int count = 0; while (true) { debug("NucleusServiceImpl._close:status:" + getUserTransaction().getStatus() + "/" + count); if (getUserTransaction().getStatus() != Status.STATUS_ACTIVE) { pml.close(); pml = null; break; } count++; Thread.sleep(2000L); if (count > 20) break; } if (pml != null) { m_openList.add(pml); m_loaders.put(sdesc, null); debug("close:in tx:" + m_openList); } } catch (Exception e) { e.printStackTrace(); } finally { m_loaders.put(sdesc, null); } } }
From source file:org.mule.util.xa.AbstractResourceManager.java
public void beginTransaction(AbstractTransactionContext context) throws ResourceManagerException { // can only start a new transaction when not already stopping assureStarted();/*w w w . jav a 2 s . co m*/ synchronized (context) { if (logger.isDebugEnabled()) { logger.debug("Beginning transaction " + context); } doBegin(context); context.status = Status.STATUS_ACTIVE; if (logger.isDebugEnabled()) { logger.debug("Began transaction " + context); } } globalTransactions.add(context); }
From source file:org.nuxeo.ecm.core.api.TransactionalCoreSessionWrapper.java
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Transaction main = threadBound.get(); if (main == null) { // first call in thread try {/*from w ww .jav a 2s.c om*/ main = TransactionHelper.lookupTransactionManager().getTransaction(); if (main != null) { if (main.getStatus() == Status.STATUS_ACTIVE) { // register last, we want post-commit stuff to be // executed after everything else is committed ConnectionHelper.registerSynchronizationLast(this); threadBound.set(main); } } } catch (NamingException e) { // no transaction manager, ignore } catch (Exception e) { log.error("Error on transaction synchronizer registration", e); } checkTxActiveRequired(method); } try { return method.invoke(session, args); } catch (Throwable t) { if (t instanceof InvocationTargetException) { Throwable tt = ((InvocationTargetException) t).getTargetException(); if (tt != null) { t = tt; } } if (TransactionHelper.isTransactionActive() && needsRollback(method, t)) { TransactionHelper.setTransactionRollbackOnly(); if (!(t instanceof ConcurrentUpdateException)) { // don't log a WARN for ConcurrentUpdateException // because often this will be retried by the Work framework // log is still available at DEBUG level log.warn("Setting transaction ROLLBACK ONLY due to exception" + " (check DEBUG logs for stacktrace): " + t); } if (log.isDebugEnabled()) { log.debug("Setting transaction ROLLBACK ONLY due to exception: " + t, t); } } throw t; } }
From source file:org.nuxeo.ecm.core.storage.dbs.DBSRepositoryBase.java
@Override public Session getSession() { Transaction transaction;/*from www . j a va 2 s. c o m*/ try { transaction = TransactionHelper.lookupTransactionManager().getTransaction(); if (transaction == null) { throw new NuxeoException("Missing transaction"); } int status = transaction.getStatus(); if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) { throw new NuxeoException("Transaction in invalid state: " + status); } } catch (SystemException | NamingException e) { throw new NuxeoException("Failed to get transaction", e); } TransactionContext context = transactionContexts.get(transaction); if (context == null) { context = new TransactionContext(transaction, newSession()); context.init(); } return context.newSession(); }
From source file:org.nuxeo.ecm.core.work.WorkManagerImpl.java
/** * Schedule after commit. Returns {@code false} if impossible (no * transaction or transaction manager)./*from www. j a v a 2 s.c om*/ * * @since 5.8 */ protected boolean scheduleAfterCommit(Work work, Scheduling scheduling) { TransactionManager transactionManager; try { transactionManager = TransactionHelper.lookupTransactionManager(); } catch (NamingException e) { transactionManager = null; } if (transactionManager == null) { if (log.isDebugEnabled()) { log.debug("Not scheduling work after commit because of missing transaction manager: " + work); } return false; } try { Transaction transaction = transactionManager.getTransaction(); if (transaction == null) { if (log.isDebugEnabled()) { log.debug("Not scheduling work after commit because of missing transaction: " + work); } return false; } int status = transaction.getStatus(); if (status == Status.STATUS_ACTIVE) { if (log.isDebugEnabled()) { log.debug("Scheduling work after commit: " + work); } transaction.registerSynchronization(new WorkScheduling(work, scheduling)); return true; } else { if (log.isDebugEnabled()) { log.debug("Not scheduling work after commit because transaction is in status " + status + ": " + work); } return false; } } catch (SystemException | RollbackException e) { log.error("Cannot schedule after commit", e); return false; } }
From source file:org.nuxeo.runtime.transaction.TransactionHelper.java
/** * Checks if the current User Transaction is active. *//*from w w w .j a v a 2 s. c o m*/ public static boolean isTransactionActive() { int status = getTransactionStatus(); return status == Status.STATUS_ACTIVE; }
From source file:org.nuxeo.runtime.transaction.TransactionHelper.java
/** * Checks if the current User Transaction is active or marked rollback only. */// www .j ava 2 s . com public static boolean isTransactionActiveOrMarkedRollback() { int status = getTransactionStatus(); return status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK; }