Package javax.transaction

Examples of javax.transaction.UserTransaction


     * @return true if the transaction is active, false otherwise.
     * @throws SystemException if a transaction exception occurs.
     * @throws NamingException if a lookup error occurs.
     */
    public static boolean transactionIsActive() throws SystemException, NamingException {
        UserTransaction utx = TransactionHelper.getInternalUserTransaction();
        boolean bolResult = false;
        if (utx != null) {
            if (utx.getStatus() == Status.STATUS_ACTIVE) {
                bolResult = true;
            }
        }
        return bolResult;
    }
View Full Code Here


     * Gets a new transaction.
     * @throws NamingException if a lookup error occurs.
     * @return the class UserTransaction.
     */
    public static UserTransaction getUserTransaction() throws NamingException {
        UserTransaction utx = TransactionHelper.getInternalUserTransaction();
        return utx;
    }
View Full Code Here

            cTest.test("tmpTable" + cTest.hashCode());

        } else if (ic.getMethod().toString().contains("accessEntityManager")) {

            //EntityManager Access
            UserTransaction utx;
            try{
                utx = ctx.getUserTransaction();
                utx.begin();
            }catch(Exception e){
                utx = null;
            }

            checkInstance(eManager, EntityManagerTester.NAME);

            if (utx != null){
                utx.commit();
            }


        } else if (ic.getMethod().toString().contains("accessEntityManagerFactory")) {
View Full Code Here

     *        Never). False if the container must mark the transaction for
     *        rollback(transaction attribute:Required, Mandatory and Supports).
     * @throws Exception if an error during the tests occurs.
     */
    public void testUsingClientTransWithAppRollbackException(final boolean canCommit) throws Exception {
        UserTransaction utx = ExceptionHandleUtil.getUserTransaction();
        utx.begin();
        try {
            sfsbContainerTransactionRollback.insertCorrectFirstErrorSecond(DATABASE_1, DATABASE_2);
            fail("The container did not re-throw the application exception.");
        } catch (RollbackApplicationException e) {
            logger.debug("The bean threw an expected error during the execution {0}", e);
        }
        // tries to commit
        try {
            utx.commit();
            if (!canCommit) {
                fail("The transaction was marked as rolled back, the client cannot make the commit.");
            }
        } catch (Exception e) {
            logger.debug("The bean threw an expected error during the execution {0}", e);
View Full Code Here

     * extends Exception(with rollback = false) and does not do the rollback in
     * this case.This test uses a client transaction.
     * @throws Exception if an error during the tests occurs.
     */
    public void testUsingClientTransWithAppException() throws Exception {
        UserTransaction utx = ExceptionHandleUtil.getUserTransaction();
        utx.begin();
        try {
            sfsbContainerTransactionApp.insertCorrectFirstErrorSecond(DATABASE_1, DATABASE_2);
            fail("The container did not re-throw the application exception.");
        } catch (AppException e) {
            logger.debug("The bean threw an expected error during the execution {0}", e);
        }
        // tries to commit
        try {
            utx.commit();
        } catch (Exception e) {
            logger.debug("The bean threw an expected error during the execution {0}", e);
        }
        // verifies if the table was created in the DATABASE_1
        ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE);
View Full Code Here

     *        transaction. The client is able to commit when the bean does not
     *        use the client transaction.
     * @throws Exception if an error during the tests occurs.
     */
    public void testUsingClientTransWithAppRuntimeRollbackException(final boolean canCommit) throws Exception {
        UserTransaction utx = ExceptionHandleUtil.getUserTransaction();
        utx.begin();
        try {
            sfsbContainerTransactionApp02.insertCorrectFirstErrorSecond(DATABASE_1, DATABASE_2);
            fail("The container did not re-throw the application exception.");
        } catch (RollbackAppRuntimeException e) {
            logger.debug("The bean threw an expected error during the execution {0}", e);
        }
        // tries to commit
        try {
            utx.commit();
            if (!canCommit) {
                fail("The transaction was marked as rolled back, the client cannot make the commit.");
            }
        } catch (Exception e) {
            logger.debug("The bean threw an expected error during the execution {0}", e);
View Full Code Here

     * extends a runtime exception (with rollback = false) and does not do the
     * rollback in this case. The test uses a client transaction.
     * @throws Exception if an error during the tests occurs.
     */
    public void testUsingClientTransWithAppRuntimeException() throws Exception {
        UserTransaction utx = ExceptionHandleUtil.getUserTransaction();
        utx.begin();
        try {
            sfsbContainerTransactionApp01.insertCorrectFirstErrorSecond(DATABASE_1, DATABASE_2);
            fail("The container did not re-throw the application exception.");
        } catch (AppRuntimeException e) {
            logger.debug("The bean threw an expected error during the execution {0}", e);
        }
        // tries to commit
        try {
            utx.commit();
        } catch (Exception e) {
            logger.debug("The bean threw an expected error during the execution {0}", e);
        }
        // verifies if the table was created in the DATABASE_1
        ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE);
View Full Code Here

     * @param canCommit true if the bean does not use the client transaction.
     * @throws Exception if an error during the tests occurs.
     */
    public void testUsingClientTransWithRuntimeException(final Class expectedException, final boolean canCommit)
            throws Exception {
        UserTransaction utx = ExceptionHandleUtil.getUserTransaction();
        utx.begin();
        // verifies if the exception thrown is correct
        try {
            sfsbContainerTransactionRuntime.insertCorrectFirstErrorSecond(DATABASE_1, DATABASE_2);
        } catch (Exception e) {
            assertTrue(ExceptionHelper.isEquals(e, expectedException),
                    "The container did not throw the correct exception, the expected exception is "
                            + expectedException.getName() + ", but the container threw " + e.getClass().getName());
        }
        // tries to commit
        try {
            utx.commit();
            if (!canCommit) {
                fail("The transaction was marked as rolled back, the client cannot make the commit.");
            }
        } catch (Exception e) {
            logger.debug("The bean threw an expected error during the execution {0}", e);
View Full Code Here

     * call a bean-managed transaction.
     * @throws Exception if an error occurs.
     */
    public void getUserTransactionWithLookup() throws Exception {
        try {
            UserTransaction utx = TransactionHelper.getUserTransaction();
            utx.begin();
            utx.commit();
        } catch (Exception e) {
            throw new TransactionException("The bean cannot get the user transaction with the JNDI", e);
        }
    }
View Full Code Here

     * container-managed transaction cannot call a bean-managed transaction.
     * @throws Exception if an error occurs.
     */
    public void getUserTransactionWithEJBContext() throws Exception {
        try {
            UserTransaction utx = ctx.getUserTransaction();
            utx.begin();
            utx.commit();
        } catch (Exception e) {
            throw new TransactionException("The bean cannot get the user transaction with the EJBContext", e);
        }
    }
View Full Code Here

TOP

Related Classes of javax.transaction.UserTransaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.