List of usage examples for javax.transaction Status STATUS_NO_TRANSACTION
int STATUS_NO_TRANSACTION
To view the source code for javax.transaction Status STATUS_NO_TRANSACTION.
Click Source Link
From source file:org.dhatim.db.JndiDataSourceTest.java
@Test public void test_jta_exception() throws Exception { when(connection.getAutoCommit()).thenReturn(false); when(transaction.getStatus()).thenReturn(Status.STATUS_NO_TRANSACTION); executeSmooksWithException("jta_exception", "test_jta_exception", REPORT); verify(dataSource, atLeastOnce()).getConnection(); verify(transaction).begin();/*from w w w . jav a 2s. c o m*/ verify(transaction).rollback(); verify(connection).close(); verify(transaction, never()).commit(); verify(transaction, never()).setRollbackOnly(); verify(connection, never()).setAutoCommit(false); verify(connection, never()).commit(); verify(connection, never()).rollback(); }
From source file:org.eclipse.ecr.core.event.tx.EventBundleTransactionHandler.java
protected UserTransaction createUT(Integer transactionTimeout, boolean retry) { try {/*from w w w . java 2 s . c o m*/ new InitialContext(); } catch (Exception e) { disabled = true; return null; } UserTransaction ut; try { ut = TransactionHelper.lookupUserTransaction(); } catch (NamingException e) { disabled = true; return null; } try { int txStatus = ut.getStatus(); if (txStatus != Status.STATUS_NO_TRANSACTION && !retry) { // if previous tx in this thread aborted in TimeOut // Ajuna may have failed to dissociate tx from thread context // => force rollback to avoid reusing a dead tx log.warn( "Transaction was not properly cleanup up from thread context, rolling back before getting a new tx"); try { ut.rollback(); } catch (Throwable t) { log.warn("error during tx rollback", t); } return createUT(transactionTimeout, true); } } catch (Exception se) { log.warn("Error while getting TX status", se); } if (transactionTimeout != null) { try { ut.setTransactionTimeout(transactionTimeout); } catch (SystemException e) { log.error("Error while setting transaction timeout to " + transactionTimeout, e); } } return ut; }
From source file:org.efaps.db.Context.java
/** * Is a transaction associated with a target object for transaction manager? * * @return <i>true</i> if a transaction associated, otherwise <i>false</i> * @throws EFapsException if the status of the transaction manager could not * be evaluated/* w ww. jav a 2 s. c om*/ * @see #TRANSMANAG */ public static boolean isTMNoTransaction() throws EFapsException { try { return Context.TRANSMANAG.getStatus() == Status.STATUS_NO_TRANSACTION; } catch (final SystemException e) { throw new EFapsException(Context.class, "isTMNoTransaction.SystemException", e); } }
From source file:org.enhydra.jdbc.standard.StandardXADataSource.java
/** * Frees a connection to make it eligible for reuse. The free list * is normally a last in, first out list (LIFO). This is efficient. * However, timed out connections are nice to hang onto for error * reporting, so they can be placed at the start. This is less * efficient, but hopefully is a rare occurence. * * Here, no need to verify the number of connections, we remove an * object from the xidConnections to put it in th freeConnections * *//*ww w . j a va 2s.c om*/ public synchronized void freeConnection(Xid id, boolean placeAtStart) { log.debug("StandardXADataSource:freeConnection"); Object o = xidConnections.get(id); // lookup the connection by XID StandardXAStatefulConnection cur = (StandardXAStatefulConnection) o; // cast to something more convenient xidConnections.remove(id); // remove connection from in use list log.debug("StandardXADataSource:freeConnection remove id from xidConnections"); if (!deadConnections.containsKey(id)) { // if this isn't to be discarded /* try { log.debug("StandardXADataSource:freeConnection setAutoCommit(true):" + cur.id); log.debug("con='"+cur.con.toString()+"'"); cur.con.setAutoCommit(acommit); } catch(SQLException e) { log.error("ERROR: Failed while autocommiting a connection: "+e); } */ cur.setState(Status.STATUS_NO_TRANSACTION); // set its new internal state if (!freeConnections.contains(cur)) { if (placeAtStart) { // if we want to keep for as long as possible freeConnections.insertElementAt(cur, 0); // then place it at the start of the list } else { freeConnections.addElement(cur); // otherwise it's a LIFO list } } } else { deadConnections.remove(id); try { cur.con.close(); } catch (SQLException e) { //ignore } } notify(); }
From source file:org.etk.entity.engine.plugins.transaction.TransactionUtil.java
public static String getTransactionStateString(int state) { /*/* ww w.java2 s .c om*/ * javax.transaction.Status STATUS_ACTIVE 0 STATUS_MARKED_ROLLBACK 1 * STATUS_PREPARED 2 STATUS_COMMITTED 3 STATUS_ROLLEDBACK 4 STATUS_UNKNOWN 5 * STATUS_NO_TRANSACTION 6 STATUS_PREPARING 7 STATUS_COMMITTING 8 * STATUS_ROLLING_BACK 9 */ switch (state) { case Status.STATUS_ACTIVE: return "Transaction Active (" + state + ")"; case Status.STATUS_COMMITTED: return "Transaction Committed (" + state + ")"; case Status.STATUS_COMMITTING: return "Transaction Committing (" + state + ")"; case Status.STATUS_MARKED_ROLLBACK: return "Transaction Marked Rollback (" + state + ")"; case Status.STATUS_NO_TRANSACTION: return "No Transaction (" + state + ")"; case Status.STATUS_PREPARED: return "Transaction Prepared (" + state + ")"; case Status.STATUS_PREPARING: return "Transaction Preparing (" + state + ")"; case Status.STATUS_ROLLEDBACK: return "Transaction Rolledback (" + state + ")"; case Status.STATUS_ROLLING_BACK: return "Transaction Rolling Back (" + state + ")"; case Status.STATUS_UNKNOWN: return "Transaction Status Unknown (" + state + ")"; default: return "Not a valid state code (" + state + ")"; } }
From source file:org.firstopen.singularity.util.TransactionManager.java
/** * //ww w. j a v a 2 s.co m * */ public void begin() { log.debug("begin"); try { UserTransaction userTransaction = TransactionUtil.getUserTransaction(); if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) { userTransaction.begin(); log.debug("JTA transaction started"); } } catch (Exception e) { log.error("cannot begin transaction"); throw new InfrastructureException(e); } }
From source file:org.fusesource.jms.pool.XaConnectionPool.java
public Session createSession(boolean transacted, int ackMode) throws JMSException { PooledSession session = null;/*ww w .j av a 2s . co m*/ try { boolean isXa = (transactionManager != null && transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION); if (isXa) { transacted = true; ackMode = Session.SESSION_TRANSACTED; session = (PooledSession) super.createXaSession(transacted, ackMode); session.setIgnoreClose(true); session.setIsXa(true); transactionManager.getTransaction().registerSynchronization(new Synchronization(session)); incrementReferenceCount(); transactionManager.getTransaction().enlistResource(createXaResource(session)); } else { session = (PooledSession) super.createSession(transacted, ackMode); session.setIgnoreClose(false); } return session; } catch (RollbackException e) { final JMSException jmsException = new JMSException("Rollback Exception"); jmsException.initCause(e); throw jmsException; } catch (SystemException e) { final JMSException jmsException = new JMSException("System Exception"); jmsException.initCause(e); throw jmsException; } }
From source file:org.hibernate.transaction.JTATransaction.java
public void begin() throws HibernateException { if (begun) {//ww w . j a v a2 s . c o m return; } if (commitFailed) { throw new TransactionException("cannot re-start transaction after failed commit"); } log.debug("begin"); try { newTransaction = userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION; if (newTransaction) { userTransaction.begin(); log.debug("Began a new JTA transaction"); } } catch (Exception e) { log.error("JTA transaction begin failed", e); throw new TransactionException("JTA transaction begin failed", e); } /*if (newTransaction) { // don't need a synchronization since we are committing // or rolling back the transaction ourselves - assuming // that we do no work in beforeTransactionCompletion() synchronization = false; }*/ boolean synchronization = jdbcContext.registerSynchronizationIfPossible(); if (!newTransaction && !synchronization) { log.warn("You should set hibernate.transaction.manager_lookup_class if cache is enabled"); } if (!synchronization) { //if we could not register a synchronization, //do the before/after completion callbacks //ourself (but we need to let jdbcContext //know that this is what we are going to //do, so it doesn't keep trying to register //synchronizations) callback = jdbcContext.registerCallbackIfNecessary(); } begun = true; commitSucceeded = false; jdbcContext.afterTransactionBegin(this); }
From source file:org.j2free.jpa.Controller.java
/** * // w w w . ja va 2 s . com * @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.jcvi.ometa.action.EventLoader.java
public String execute() { String rtnVal = SUCCESS;//from w ww . j a va2 s .c om UserTransaction tx = null; try { sampleName = sampleName != null && sampleName.equals("0") ? null : sampleName; if (jobType != null) { boolean isProjectRegistration = eventName.equals(Constants.EVENT_PROJECT_REGISTRATION); boolean isSampleRegistration = eventName.equals(Constants.EVENT_SAMPLE_REGISTRATION); if (projectName == null || projectName.equals("0") || eventName == null || eventName.equals("0")) throw new Exception("Project or Event type is not selected."); if (jobType.equals("insert")) { //loads single event tx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction"); tx.begin(); psewt.loadAll(null, this.createMultiLoadParameter(projectName, loadingProject, loadingSample, beanList)); this.reset(); } else if (jobType.equals("grid")) { //loads multiple events from grid view tx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction"); tx.begin(); for (GridBean gBean : gridList) { if (gBean != null) { if (isProjectRegistration && gBean.getProjectName() != null && gBean.getProjectPublic() != null) { loadingProject = new Project(); loadingProject.setProjectName(gBean.getProjectName()); loadingProject.setIsPublic(Integer.valueOf(gBean.getProjectPublic())); } else if (isSampleRegistration && gBean.getSampleName() != null && gBean.getSamplePublic() != null) { loadingSample = new Sample(); loadingSample.setSampleName(gBean.getSampleName()); loadingSample.setParentSampleName(gBean.getParentSampleName()); loadingSample.setIsPublic(Integer.valueOf(gBean.getSamplePublic())); } else { if (gBean.getSampleName() != null) { this.sampleName = gBean.getSampleName(); } } List<FileReadAttributeBean> fBeanList = gBean.getBeanList(); if (fBeanList != null && fBeanList.size() > 0) { psewt.loadAll(null, this.createMultiLoadParameter(projectName, loadingProject, loadingSample, fBeanList)); } } } this.reset(); } else if (jobType.equals("file")) { //loads data from a CSV file to grid view if (!this.uploadFile.canRead()) { throw new Exception("Error in reading the file."); } else { try { CSVReader reader = new CSVReader(new FileReader(this.uploadFile)); int lineCount = 0; List<String> columns = new ArrayList<String>(); String currProjectName = null; gridList = new ArrayList<GridBean>(); boolean hasSampleName = false; String[] line; while ((line = reader.readNext()) != null) { if (lineCount != 1) { if (lineCount == 0) { Collections.addAll(columns, line); hasSampleName = columns.indexOf("SampleName") >= 0; } else { int colIndex = 0; currProjectName = line[colIndex++]; if (!isProjectRegistration && !currProjectName.equals(this.projectName)) { throw new Exception(MULTIPLE_SUBJECT_IN_FILE_MESSAGE); } GridBean gBean = new GridBean(); gBean.setProjectName(currProjectName); if (hasSampleName) { gBean.setSampleName(line[(colIndex++)]); } if (isProjectRegistration) { gBean.setProjectName(currProjectName); gBean.setProjectPublic(line[(colIndex++)]); } else if (isSampleRegistration) { gBean.setParentSampleName(line[(colIndex++)]); gBean.setSamplePublic(line[(colIndex++)]); } gBean.setBeanList(new ArrayList<FileReadAttributeBean>()); for (; colIndex < columns.size(); colIndex++) { FileReadAttributeBean fBean = new FileReadAttributeBean(); fBean.setProjectName( isProjectRegistration ? currProjectName : this.projectName); fBean.setAttributeName(columns.get(colIndex)); fBean.setAttributeValue(line[colIndex]); gBean.getBeanList().add(fBean); } this.gridList.add(gBean); } } lineCount++; } jobType = "grid"; } catch (Exception ex) { throw ex; } } } else if (jobType.equals("template")) { //download template List<EventMetaAttribute> emaList = readPersister.getEventMetaAttributes(projectName, eventName); /* * removing the sanity check on sample requirement since multiple sample support is in action * by hkim 5/2/13 ModelValidator validator = new ModelValidator(); validator.validateEventTemplateSanity(emaList, projectName, sampleName, eventName); */ TemplatePreProcessingUtils cvsUtils = new TemplatePreProcessingUtils(); String templateType = jobType.substring(jobType.indexOf("_") + 1); downloadStream = cvsUtils.buildFileContent(templateType, emaList, projectName, sampleName, eventName); downloadContentType = templateType.equals("c") ? "csv" : "vnd.ms-excel"; rtnVal = Constants.FILE_DOWNLOAD_MSG; } } } catch (Exception ex) { logger.error("Exception in EventLoader : " + ex.toString()); ex.printStackTrace(); if (ex.getClass() == ForbiddenResourceException.class) { addActionError(Constants.DENIED_USER_EDIT_MESSAGE); return Constants.FORBIDDEN_ACTION_RESPONSE; } else if (ex.getClass() == ForbiddenResourceException.class) { addActionError(Constants.DENIED_USER_EDIT_MESSAGE); return LOGIN; } else if (ex.getClass() == ParseException.class) addActionError(Constants.INVALID_DATE_MESSAGE); else { addActionError(ex.toString()); } //deletes uploaded files in event of error if (loadedFiles != null && loadedFiles.size() > 0) { for (String filePath : loadedFiles) { File tempFile = new File(fileStoragePath + filePath); if (tempFile.exists()) tempFile.delete(); } } try { if (tx != null) tx.rollback(); } catch (SystemException se) { addActionError(se.toString()); } rtnVal = ERROR; } finally { try { //get project list for the drop down box List<String> projectNameList = new ArrayList<String>(); if (projectNames == null || projectNames.equals("")) { projectNameList.add("ALL"); } else if (projectNames.contains(",")) { projectNameList.addAll(Arrays.asList(projectNames.split(","))); } else { projectNameList.add(projectNames); } projectList = readPersister.getProjects(projectNameList); if (tx != null && tx.getStatus() != Status.STATUS_NO_TRANSACTION) { tx.commit(); } if (jobType != null && jobType.equals("grid") && this.uploadFile != null) { this.uploadFile.delete(); } } catch (Exception ex) { ex.printStackTrace(); } } return rtnVal; }