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.hibernate.transaction.JTATransaction.java
public boolean isActive() throws TransactionException { if (!begun || commitFailed || commitSucceeded) { return false; }//from w w w .ja v a 2 s . c o m final int status; try { status = userTransaction.getStatus(); } catch (SystemException se) { log.error("Could not determine transaction status", se); throw new TransactionException("Could not determine transaction status: ", se); } if (status == Status.STATUS_UNKNOWN) { throw new TransactionException("Could not determine transaction status"); } else { return status == Status.STATUS_ACTIVE; } }
From source file:org.j2free.jpa.Controller.java
/** * Begins the container managed <tt>UserTransaction</tt> and clears fields used to * store problems / errors./*from w ww. java 2 s. c o m*/ * * @throws NotSupportedException * @throws SystemException */ public void begin() throws NotSupportedException, SystemException { // Make sure a transaction isn't already in progress if (tx.getStatus() == Status.STATUS_ACTIVE) return; // Start the transaction tx.begin(); // make sure the entity manager knows the transaction has begun em.joinTransaction(); // make sure that a transaction always starts clean problem = null; errors = null; }
From source file:org.j2free.jpa.Controller.java
/** * Ends the contatiner managed <tt>UserTransaction</tt>, committing * or rolling back as necessary./*from w w w .j av a2s . c o m*/ * * @throws SystemException * @throws RollbackException * @throws HeuristicMixedException * @throws HeuristicRollbackException */ public void end() throws SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException { try { switch (tx.getStatus()) { case Status.STATUS_MARKED_ROLLBACK: tx.rollback(); break; case Status.STATUS_ACTIVE: tx.commit(); break; case Status.STATUS_COMMITTED: // somebody called end() twice break; case Status.STATUS_COMMITTING: log.warn("uh oh, concurrency problem! end() called when transaction already committing"); break; case Status.STATUS_ROLLEDBACK: // somebody called end() twice break; case Status.STATUS_ROLLING_BACK: log.warn("uh oh, concurrency problem! end() called when transaction already rolling back"); break; default: throw new IllegalStateException("Unknown status in endTransaction: " + getTransactionStatus()); } problem = null; errors = null; } catch (InvalidStateException ise) { problem = ise; this.errors = ise.getInvalidValues(); } }
From source file:org.j2free.jpa.Controller.java
/** * @return true if <tt>begin</tt> has been called, otherwise false */// w w w.j av a2 s. c o m public boolean isTransactionOpen() { try { return tx.getStatus() == Status.STATUS_ACTIVE; } catch (SystemException ex) { return false; } }
From source file:org.j2free.jpa.Controller.java
/** * //from w w w.j a va 2 s . c o m * @return * @throws SystemException */ public String getTransactionStatus() throws SystemException { if (tx == null) { return "Null transaction"; } switch (tx.getStatus()) { case Status.STATUS_ACTIVE: return "Active"; case Status.STATUS_COMMITTED: return "Committed"; case Status.STATUS_COMMITTING: return "Committing"; case Status.STATUS_MARKED_ROLLBACK: return "Marked for rollback"; case Status.STATUS_NO_TRANSACTION: return "No Transaction"; case Status.STATUS_PREPARED: return "Prepared"; case Status.STATUS_ROLLEDBACK: return "Rolledback"; case Status.STATUS_ROLLING_BACK: return "Rolling back"; case Status.STATUS_UNKNOWN: return "Declared Unknown"; default: return "Undeclared Unknown Status"; } }
From source file:org.milyn.db.JndiDataSourceTest.java
public void test_jta_existing_transaction() throws Exception { when(connection.getAutoCommit()).thenReturn(false); when(transaction.getStatus()).thenReturn(Status.STATUS_ACTIVE); executeSmooks("jta", "test_jta_existing_transaction", REPORT); verify(dataSource, atLeastOnce()).getConnection(); verify(connection).close();//from w w w.jav a 2 s .com verify(transaction, never()).begin(); verify(transaction, never()).commit(); verify(transaction, never()).rollback(); verify(connection, never()).setAutoCommit(false); verify(connection, never()).commit(); verify(connection, never()).rollback(); }
From source file:org.milyn.db.JndiDataSourceTest.java
public void test_jta_existing_transaction_exception() throws Exception { when(connection.getAutoCommit()).thenReturn(false); when(transaction.getStatus()).thenReturn(Status.STATUS_ACTIVE); executeSmooksWithException("jta_exception", "test_jta_existing_transaction_exception", REPORT); verify(dataSource, atLeastOnce()).getConnection(); verify(transaction).setRollbackOnly(); verify(connection).close();/* ww w . ja v a 2 s.c om*/ verify(transaction, never()).begin(); verify(transaction, never()).commit(); verify(transaction, never()).rollback(); verify(connection, never()).setAutoCommit(false); verify(connection, never()).commit(); verify(connection, never()).rollback(); }
From source file:org.milyn.db.JndiDataSourceTest.java
public void test_jta_set_autocommit_not_allowed() throws Exception { when(transaction.getStatus()).thenReturn(Status.STATUS_ACTIVE); executeSmooks("jta_set_autocommit_not_allowed", "test_jta_set_autocommit_not_allowed", REPORT); verify(dataSource, atLeastOnce()).getConnection(); verify(connection).close();//from w w w . java2 s . c o m verify(connection, never()).setAutoCommit(false); verify(connection, never()).getAutoCommit(); }
From source file:org.ms123.common.ea.BaseEAServiceImpl.java
private Map importActivities(String storeId, String basedir) throws Exception { String json = readFileToString(new File(basedir, "idmap.map")); Map<String, String> idmap = (Map) m_ds.deserialize(json); Calendar high_cal = Calendar.getInstance(); high_cal.set(Calendar.YEAR, 2050); high_cal.set(Calendar.MONTH, 11); high_cal.set(Calendar.DAY_OF_MONTH, 31); Calendar low_cal = Calendar.getInstance(); low_cal.set(Calendar.YEAR, 2012); low_cal.set(Calendar.MONTH, 11); low_cal.set(Calendar.DAY_OF_MONTH, 12); StoreDesc sdesc = StoreDesc.get(storeId); PersistenceManager pm = m_nucleusService.getPersistenceManagerFactory(sdesc).getPersistenceManager(); UserTransaction ut = m_nucleusService.getUserTransaction(); Map mapping = initActivities(); try {/*from ww w . ja va 2s . com*/ LabeledCSVParser lp = new LabeledCSVParser( new ExcelCSVParser(new FileInputStream(new File(basedir, "Kontakte.csv")))); System.out.println("Persisting activities"); int num = 0; Class _contact = m_nucleusService.getClass(sdesc, "Contact"); Class _teamIntern = m_nucleusService.getClass(sdesc, "Teamintern"); while (lp.getLine() != null) { String nummer = lp.getValueByLabel("Nummer"); String merkmal = lp.getValueByLabel("Merkmal"); Object c = getObject(pm, _contact, nummer); if (c == null) { continue; } if (ut.getStatus() != Status.STATUS_ACTIVE) { ut.begin(); } String teamid = idmap.get(merkmal); Object activity = m_nucleusService.getClass(sdesc, "Activity").newInstance(); if (teamid != null) { Object team = m_nucleusService.getClass(sdesc, "Team").newInstance(); Object teamintern = getTeamintern(pm, _teamIntern, teamid); PropertyUtils.setProperty(team, "teamintern", teamintern); PropertyUtils.setProperty(team, "teamid", teamid); PropertyUtils.setProperty(team, "description", PropertyUtils.getProperty(teamintern, "description")); PropertyUtils.setProperty(team, "validFrom", low_cal.getTime()); PropertyUtils.setProperty(team, "validTo", high_cal.getTime()); PropertyUtils.setProperty(team, "disabled", false); Collection l = (Collection) PropertyUtils.getProperty(activity, "_team_list"); if (l == null) { l = new HashSet(); PropertyUtils.setProperty(activity, "_team_list", l); } l.add(team); } Iterator it = mapping.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); if (key.equals("traits")) { continue; } String[] m1 = (String[]) mapping.get(key); String field = m1[0]; String type = m1[1]; String val = lp.getValueByLabel(key).trim(); if (type.equals("date")) { Date d = getDate(val); if (d != null) { BeanUtils.setProperty(activity, field, d); } } else if (type.equals("boolean")) { Boolean b = false; if ("J".equals(val)) { b = true; } BeanUtils.setProperty(activity, field, b); } else { if (val != null) { BeanUtils.setProperty(activity, field, val); } } } Collection l = (Collection) PropertyUtils.getProperty(c, "activity_list"); l.add(activity); PropertyUtils.setProperty(activity, "contact", c); pm.makePersistent(activity); //LuceneSession luceneSession = m_luceneService.createSession(sdesc); //m_luceneService.addToIndex(luceneSession, activity); //m_luceneService.commit(luceneSession); 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.BaseEAServiceImpl.java
private Map importTeams(String storeId, String basedir) throws Exception { Calendar high_cal = Calendar.getInstance(); high_cal.set(Calendar.YEAR, 2050); high_cal.set(Calendar.MONTH, 11); high_cal.set(Calendar.DAY_OF_MONTH, 31); Calendar low_cal = Calendar.getInstance(); low_cal.set(Calendar.YEAR, 2012); low_cal.set(Calendar.MONTH, 11); low_cal.set(Calendar.DAY_OF_MONTH, 12); String json = readFileToString(new File(basedir, "idmap.map")); Map<String, String> idmap = (Map) m_ds.deserialize(json); StoreDesc sdesc = StoreDesc.get(storeId); PersistenceManager pm = m_nucleusService.getPersistenceManagerFactory(sdesc).getPersistenceManager(); UserTransaction ut = m_nucleusService.getUserTransaction(); try {//from ww w. j a va2s .c o m LabeledCSVParser lp = new LabeledCSVParser( new ExcelCSVParser(new FileInputStream(new File(basedir, "Merkmale.csv")))); System.out.println("Persisting teams"); int num = 0; Class _contact = m_nucleusService.getClass(sdesc, "Contact"); Class _company = m_nucleusService.getClass(sdesc, "Company"); Class _teamIntern = m_nucleusService.getClass(sdesc, "Teamintern"); while (lp.getLine() != null) { String nummer = lp.getValueByLabel("Nummer"); String merkmal = lp.getValueByLabel("Merkmal"); String beginn = lp.getValueByLabel("Beginn"); String ende = lp.getValueByLabel("Ende"); String status = lp.getValueByLabel("Status"); String teamid = idmap.get(merkmal); if (teamid == null) { System.out.println("Teamid not found:" + merkmal); continue; } Object c = getObject(pm, _contact, _company, nummer); if (c == null) { System.out.println("No contact/company:" + nummer); continue; } if (ut.getStatus() != Status.STATUS_ACTIVE) { ut.begin(); } Object team = m_nucleusService.getClass(sdesc, "Team").newInstance(); Object teamintern = getTeamintern(pm, _teamIntern, teamid); PropertyUtils.setProperty(team, "teamintern", teamintern); PropertyUtils.setProperty(team, "teamid", teamid); PropertyUtils.setProperty(team, "description", PropertyUtils.getProperty(teamintern, "description")); Boolean active = isActive(status); Date validFrom = getTeamDate(beginn); Date validTo = getTeamDate(ende); if (active != null && validFrom != null && validTo != null) { PropertyUtils.setProperty(team, "validFrom", validFrom); PropertyUtils.setProperty(team, "validTo", validTo); PropertyUtils.setProperty(team, "disabled", !active); } if (active == null && validFrom == null && validTo == null) { PropertyUtils.setProperty(team, "validFrom", low_cal.getTime()); PropertyUtils.setProperty(team, "validTo", high_cal.getTime()); PropertyUtils.setProperty(team, "disabled", false); } if (active != null && validFrom != null && validTo == null) { PropertyUtils.setProperty(team, "validFrom", validFrom); PropertyUtils.setProperty(team, "validTo", high_cal.getTime()); PropertyUtils.setProperty(team, "disabled", !active); } PropertyUtils.setProperty(team, "property1", lp.getValueByLabel("Nutzer")); PropertyUtils.setProperty(team, "property2", lp.getValueByLabel("Passwort")); Collection l = (Collection) PropertyUtils.getProperty(c, "_team_list"); if (l == null) { l = new HashSet(); PropertyUtils.setProperty(c, "_team_list", l); } l.add(team); pm.makePersistent(team); 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; }