Package javax.transaction

Examples of javax.transaction.UserTransaction


     * @output the tables not created because the transaction rolled back.
     * @throws Exception if an error occurs during the tests.
     */
    @Test
    public void testSessionSyncWithMandatory() throws Exception {
        UserTransaction utx = getUserTransaction();
        utx.begin();
        sfsbSessionSync.insertTableMandatory();
        try{
            utx.commit();
        }catch(Exception e){
           logger.debug("The method threw an expected exception {e}", e);
        }
        verifyCallbacks();
    }
View Full Code Here


     *         rollback.
     * @throws Exception if an error occurs during the tests.
     */
    @Test
    public void testSessionSyncWithUserTransAndSupports() throws Exception {
        UserTransaction utx = getUserTransaction();
        utx.begin();
        sfsbSessionSync.insertTableSupports();
        try{
            utx.commit();
        }catch(Exception e){
           logger.debug("The method threw an expected exception {e}", e);
        }
        verifyCallbacks();
    }
View Full Code Here

     */
    @Test
    public void testAppExceptionWithoutRollback() throws Exception{
        //verifies if the application exception is re-throw
        //the exception is not a checked exception
        UserTransaction utx = TransactionHelper.getInternalUserTransaction();
        try{
            utx.begin();
            bean.createTableWithAppException(DB_NAME);
            fail("The container did not re-throw the application exception.");
        }catch(CustomException01 e){
           logger.debug("The container threw an expected exception {0}", e);
        }finally{
            // the container must not mark the transaction for rollback, so the
            // commit should work.
            utx.commit();
        }
        //verifies if the commit worked
        verifyTable(DB_NAME);
    }
View Full Code Here

     */
    @Test
    public void testAppExceptionWithRollbackOverride() throws Exception{
        //verifies if the application exception is re-throw
        //the exception is not a checked exception
        UserTransaction utx = TransactionHelper.getInternalUserTransaction();
        try{
            utx.begin();
            bean.createTableWithAppExceptionOverride(DB_NAME);
            fail("The container did not re-throw the application exception.");
        }catch(RollbackApplicationException e){
           logger.debug("The container threw an expected exception {0}", e);
        }finally{
            // the container must not mark the transaction for rollback, so the
            // commit should work.
            utx.commit();
        }
        //verifies if the commit worked
        verifyTable(DB_NAME);
    }
View Full Code Here

     */
    @Test
    public void testAppExceptionWithRollback() throws Exception{
        //verifies if the application exception is re-throw
        //the exception is a checked exception
        UserTransaction utx = TransactionHelper.getInternalUserTransaction();
        try{
            utx.begin();
            bean.createTableWithAppExceptionAndRollback(DB_NAME);
            fail("The container did not re-throw the application exception.");
        }catch(CustomException00 e){
           logger.debug("The container threw an expected exception {0}", e);
        }finally{
            // the container must mark the transaction for rollback, so the
            // commit should not work.
            try{
                utx.commit();
                fail("The container did not mark the transaction for rollback");
            }catch(Exception e){
                logger.debug("The container threw an expected exception {0}", e);
            }
        }
View Full Code Here

     */
    @Test
    public void testAppExceptionWithRollbackDefault() throws Exception{
        //verifies if the application exception is re-throw
        //the exception is not a checked exception
        UserTransaction utx = TransactionHelper.getInternalUserTransaction();
        try{
            utx.begin();
            bean.createTableWithAppExceptionDefault(DB_NAME);
            fail("The container did not re-throw the application exception.");
        }catch(IllegalException e){
           logger.debug("The container threw an expected exception {0}", e);
        }finally{
            // the container must not mark the transaction for rollback, so the
            // commit should work.
            utx.commit();
        }
        //verifies if the commit worked
        verifyTable(DB_NAME);
    }
View Full Code Here

    public void verifyAllDefinition() throws Exception {
        // the transaction attribute defined for all methods is required, so the
        // method must work with or without a client transaction.

        // the method is working with transaction...
        UserTransaction utx = TransactionHelper.getInternalUserTransaction();
        utx.begin();
        bean.insertTable01(DB_NAME, TABLE_NAME);
        utx.commit();

        // cleans the db to avoid error
        deleteTable(DB_NAME, TABLE_NAME);

        // the method is working without transaction
View Full Code Here

        // attribute never. The other method with the same name, but with
        // diferent attributes, has the general tarsnaction attribute(REQUIRED).

        // The transaction attribute is never, so when the method is called with
        // a transactional context, an exception must be throw.
        UserTransaction utx = TransactionHelper.getInternalUserTransaction();
        try {
            utx.begin();
            bean.insertTable03(DB_NAME, TABLE_NAME);
            fail("A method with transaction attribute never is not throwing an "
                    + "EJBException when it is called with transaction context");
        } catch (Exception e) {
            assertTrue(e instanceof EJBException,
                    "A method with transaction attribute never is not throwing an "
                    + "EJBException when it is called with transaction context");
        } finally {
            utx.rollback();
        }

        // cleans the db to avoid error
        deleteTable(DB_NAME, TABLE_NAME);

        // the transaction attribute defined for all methods is required, so the
        // method must work with or without a client transaction.

        // the method is working with transaction...
        utx.begin();
        bean.insertTable03(DB_NAME, TABLE_NAME, 1);
        utx.commit();

        // cleans the db to avoid error
        deleteTable(DB_NAME, TABLE_NAME);

        // the method is working without transaction
View Full Code Here

            System.err.println("Cannot get statefulBean: " + e);
            System.exit(2);
        }

        // We want to start transactions from client: get UserTransaction
        UserTransaction utx = null;
        try {
            utx = (UserTransaction) initialContext.lookup("javax.transaction.UserTransaction");
        } catch (NamingException e) {
            System.err.println("Cannot lookup UserTransaction: " + e);
            System.exit(2);
        }

        // First transaction (committed)
        try {
            System.out.println("Start a first transaction");
            utx.begin();
            System.out.println("First request on the new bean");
            statefulBean.buy(FIRST_BUY_AMOUNT);
            System.out.println("Second request on the bean");
            statefulBean.buy(SECOND_BUY_AMOUNT);
            System.out.println("Commit the transaction");
            utx.commit();
        } catch (Exception e) {
            System.err.println("exception during 1st Tx: " + e);
            System.exit(2);
        }

        // Start another transaction (rolled back)
        try {
            System.out.println("Start a second transaction");
            utx.begin();
            System.out.println("Buy " + THIRD_BUY_AMOUNT + " amount.");
            statefulBean.buy(THIRD_BUY_AMOUNT);
            System.out.println("Rollback the transaction");
            utx.rollback();
        } catch (Exception e) {
            System.err.println("exception during 2nd Tx: " + e);
            System.exit(2);
        }
View Full Code Here

     * Tests the sessionContext by invoking "getUserTransaction".
     * @throws Exception if a problem occurs.
     */
    @SuppressWarnings("unused")
    protected void access02() throws Exception{
        UserTransaction utx = ctx.getUserTransaction();
    }
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.