Java 类javax.transaction.HeuristicRollbackException 实例源码

项目:Mastering-Java-EE-Development-with-WildFly    文件:ConverterTestCase.java   
@Test
public void testPasswordConverter() {
    logger.info("starting persistence converter test");
    Citizen citizen = new Citizen();
    citizen.setPassword("prova");
    try {
        userTransaction.begin();
        entityManager.persist(citizen);
        userTransaction.commit();
    } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
            | HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
        fail();
    }
    Citizen citizenFromDB = (Citizen) entityManager.createQuery("from citizen").getSingleResult();
    assertEquals("the password is always converted by the converter", "prova", citizenFromDB.getPassword());
    assertEquals("this is the password we have in the database", "cHJvdmE=", NEVER_DO_IT);
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:InheritanceTestCase.java   
/**
 * Tests annotation literals in a jar archive
 */
@Test
@SuppressWarnings("unchecked")
public void testSingleTable() {
    logger.info("starting single table inheritance test");
    Pet pet = new Pet("jackrussell", "dog");
    Dog dog = new Dog("mastino", "dog");
    try {
        userTransaction.begin();
        entityManager.persist(pet);
        entityManager.persist(dog);
        userTransaction.commit();
    } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
            | HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
        fail();
    }
    List<Pet> petsFromDB = entityManager.createNativeQuery("select * from pet").getResultList();
    assertEquals("only the pet table exists", 2, petsFromDB.size());
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:InheritanceTestCase.java   
/**
 * Tests annotation literals in a jar archive
 */
@Test
@SuppressWarnings("unchecked")
public void testTablePerClass() {
    logger.info("starting table per class inheritance test");
    Vehicle vehicle = new Vehicle("peugeot", "car");
    Car car = new Car("fiat", "car");
    try {
        userTransaction.begin();
        entityManager.persist(vehicle);
        entityManager.persist(car);
        userTransaction.commit();
    } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
            | HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
        fail();
    }
    List<Vehicle> vehiclesFromDB = entityManager.createNativeQuery("select * from vehicle").getResultList();
    assertEquals("the vehicle table exists", 1, vehiclesFromDB.size());
    List<Car> carsFromDB = entityManager.createNativeQuery("select * from car").getResultList();
    assertEquals("the car table exists", 1, carsFromDB.size());
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:InheritanceTestCase.java   
/**
 * Tests annotation literals in a jar archive
 */
@Test
@SuppressWarnings("unchecked")
public void testJoin() {
    logger.info("starting joined inheritance event test");
    Watch watch = new Watch();
    TopicWatch topicWatch = new TopicWatch();
    try {
        userTransaction.begin();
        entityManager.persist(watch);
        entityManager.persist(topicWatch);
        userTransaction.commit();
    } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
            | HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
        fail();
    }
    List<Watch> watchesFromDB = entityManager.createNativeQuery("select * from JBP_FORUMS_WATCH").getResultList();
    assertEquals("the watch table exists", 2, watchesFromDB.size());
    List<TopicWatch> topicWatchesFromDB = entityManager.createNativeQuery("select * from JBP_FORUMS_TOPICSWATCH")
            .getResultList();
    assertEquals("the topic watch table exists", 1, topicWatchesFromDB.size());
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:SearchTestCase.java   
@Test
public void testSearch() {
    Forum forum = entityManager.find(Forum.class, 0);
    Poster poster = new Poster("root");
    Topic topic = new Topic(forum, TOPIC_TEXT);
    topic.setPoster(poster);
    Post post = new Post(topic, POST_TEXT);
    post.setCreateDate(new Date());
    post.setPoster(poster);
    try {
        userTransaction.begin();
        entityManager.persist(poster);
        entityManager.persist(topic);
        entityManager.persist(post);
        userTransaction.commit();
    } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
            | HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
        e.printStackTrace();
    }
    List<Topic> topics = findTopics();
    List<Post> posts = findPosts();
    assertEquals("find topics", 1, topics.size());
    assertEquals("find posts", 1, posts.size());
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:CascadeTestCase.java   
@Test
public void testDeleteManyToMany() {
    logger.info("starting merge many to many cascade test");
    testPersistManyToMany();
    try {
        userTransaction.begin();
        Author davide_scala = (Author) entityManager.createQuery("from Author where fullName = :fullName")
                .setParameter("fullName", "Davide Scala").getSingleResult();
        davide_scala.remove();
        entityManager.remove(davide_scala);
        userTransaction.commit();
    } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
            | HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
        fail();
    }
    @SuppressWarnings("unchecked")
    List<Book> booksFromDb = entityManager.createNativeQuery("select * from Book").getResultList();
    assertEquals("the book table exists", 2, booksFromDb.size());
    @SuppressWarnings("unchecked")
    List<Author> authorsFromDb = entityManager.createNativeQuery("select * from Author").getResultList();
    assertEquals("the author table exists", 2, authorsFromDb.size());
    @SuppressWarnings("unchecked")
    List<Author> bookAuthorsFromDb = entityManager.createNativeQuery("select * from Book_Author").getResultList();
    assertEquals("the author table exists", 4, bookAuthorsFromDb.size());
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:CascadeTestCase.java   
@Test
public void testDeleteBooksAllManyToMany() {
    logger.info("starting merge many to many cascade test");
    testPersistManyToMany();
    try {
        userTransaction.begin();
        PMAuthor davide_scala = (PMAuthor) entityManager.createQuery("from PMAuthor where fullName = :fullName")
                .setParameter("fullName", "Davide Scala").getSingleResult();
        entityManager.remove(davide_scala);
        userTransaction.commit();
    } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
            | HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
        fail();
    }
    @SuppressWarnings("unchecked")
    List<PMBook> booksFromDb = entityManager.createNativeQuery("select * from PMBook").getResultList();
    assertEquals("the pm book table exists", 1, booksFromDb.size());
    @SuppressWarnings("unchecked")
    List<PMAuthor> authorsFromDb = entityManager.createNativeQuery("select * from PMAuthor").getResultList();
    assertEquals("the pm author table exists", 2, authorsFromDb.size());
    @SuppressWarnings("unchecked")
    List<PMAuthor> bookAuthorsFromDb = entityManager.createNativeQuery("select * from Book_PM_Author")
            .getResultList();
    assertEquals("the pm book author table exists", 2, bookAuthorsFromDb.size());
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:CascadeTestCase.java   
@Test
public void testDeleteBooksJoinTableAllManyToMany() {
    logger.info("starting merge many to many cascade test");
    testPersistManyToMany();
    try {
        userTransaction.begin();
        AllAuthor davide_scala = (AllAuthor) entityManager.createQuery("from AllAuthor where fullName = :fullName")
                .setParameter("fullName", "Davide Scala").getSingleResult();
        entityManager.remove(davide_scala);
        userTransaction.commit();
    } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException
            | HeuristicMixedException | HeuristicRollbackException | RollbackException e) {
        fail();
    }
    @SuppressWarnings("unchecked")
    List<AllBook> booksFromDb = entityManager.createNativeQuery("select * from AllBook").getResultList();
    assertEquals("the all book table doesn't exist", 0, booksFromDb.size());
    @SuppressWarnings("unchecked")
    List<AllAuthor> authorsFromDb = entityManager.createNativeQuery("select * from AllAuthor").getResultList();
    assertEquals("the all author table doesn't exist", 0, authorsFromDb.size());
    @SuppressWarnings("unchecked")
    List<AllAuthor> bookAuthorsFromDb = entityManager.createNativeQuery("select * from Book_All_Author")
            .getResultList();
    assertEquals("the all book author table exists", 0, bookAuthorsFromDb.size());
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:EventTestCase.java   
/**
 * Tests the fire of the event inside a transaction
 */
@Test
public void testSimpleTransaction() {
    try {
        userTransaction.begin();
        Bill bill = fire();
        assertEquals(
                "The id generation passes through the always and it is incremented only by inprogess always observer method",
                1, bill.getId());
        userTransaction.commit();
        assertEquals(
                "The id generation passes through the always and it is incremented only by transactional observer methods",
                4, bill.getId());
    } catch (NotSupportedException | SystemException | SecurityException | IllegalStateException | RollbackException
            | HeuristicMixedException | HeuristicRollbackException e) {
        fail("no fail for the transaction");
    }

}
项目:alfresco-repository    文件:SimpleTransaction.java   
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
        SecurityException, SystemException
{
    try
    {
        if (isRollBackOnly)
        {
            throw new RollbackException("Commit failed: Transaction marked for rollback");
        }

    }
    finally
    {
        transaction.set(null);
    }
}
项目:alfresco-repository    文件:PeopleTest.java   
private void createUsers() throws HeuristicRollbackException, RollbackException, HeuristicMixedException, SystemException, NotSupportedException
    {
        txn = transactionService.getUserTransaction();
        txn.begin();
        for (UserInfo user : userInfos)
        {
            String username = user.getUserName();
            NodeRef nodeRef = personService.getPersonOrNull(username);
            boolean create = nodeRef == null;
            if (create)
            {
                PropertyMap testUser = new PropertyMap();
                testUser.put(ContentModel.PROP_USERNAME, username);
                testUser.put(ContentModel.PROP_FIRSTNAME, user.getFirstName());
                testUser.put(ContentModel.PROP_LASTNAME, user.getLastName());
                testUser.put(ContentModel.PROP_EMAIL, user.getUserName() + "@acme.test");
                testUser.put(ContentModel.PROP_PASSWORD, "password");

                nodeRef = personService.createPerson(testUser);
            }
            userNodeRefs.add(nodeRef);
//            System.out.println((create ? "create" : "existing")+" user " + username + " nodeRef=" + nodeRef);
        }
        txn.commit();
    }
项目:agroal    文件:BasicNarayanaTests.java   
@Test
@DisplayName( "Multiple close test" )
public void multipleCloseTest() throws SQLException {
    TransactionManager txManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
    TransactionSynchronizationRegistry txSyncRegistry = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();

    AgroalDataSourceConfigurationSupplier configurationSupplier = new AgroalDataSourceConfigurationSupplier()
            .connectionPoolConfiguration( cp -> cp
                    .transactionIntegration( new NarayanaTransactionIntegration( txManager, txSyncRegistry ) )
            );

    try ( AgroalDataSource dataSource = AgroalDataSource.from( configurationSupplier ) ) {

        // there is a call to connection#close in the try-with-resources block and another on the callback from the transaction#commit()
        try ( Connection connection = dataSource.getConnection() ) {
            logger.info( format( "Got connection {0}", connection ) );
            try {
                txManager.begin();
                txManager.commit();
            } catch ( NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e ) {
                fail( "Exception: " + e.getMessage() );
            }
        }  
    }
}
项目:201710-paseos_01    文件:FotoPersistenceTest.java   
/**
 * Configuración inicial de la prueba.
 *
 * @generated
 */
@Before
public void configTest() 
{
    try {
        utx.begin();
        clearData();
        insertData();
        utx.commit();
    } catch (IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | NotSupportedException | RollbackException | SystemException e) {
        e.printStackTrace();
        try {
            utx.rollback();
        } catch (IllegalStateException | SecurityException | SystemException e1) {
            e1.printStackTrace();
        }
    }
}
项目:201710-paseos_01    文件:FotoLogicTest.java   
/**
 * Configuración inicial de la prueba.
 *
 * @generated
 */
@Before
public void configTest() {
    try {
        utx.begin();
        clearData();
        insertData();
        utx.commit();
    } catch (IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | NotSupportedException | RollbackException | SystemException e) {
        e.printStackTrace();
        try {
            utx.rollback();
        } catch (IllegalStateException | SecurityException | SystemException e1) {
            e1.printStackTrace();
        }
    }
}
项目:scipio-erp    文件:DumbTransactionFactory.java   
public UserTransaction getUserTransaction() {
    return new UserTransaction() {
        public void begin() throws NotSupportedException, SystemException {
        }

        public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
        }

        public int getStatus() throws SystemException {
            return TransactionUtil.STATUS_NO_TRANSACTION;
        }

        public void rollback() throws IllegalStateException, SecurityException, SystemException {
        }

        public void setRollbackOnly() throws IllegalStateException, SystemException {
        }

        public void setTransactionTimeout(int i) throws SystemException {
        }
    };
}
项目:ByteTCC    文件:CompensableManagerImpl.java   
protected void invokeTransactionCommitIfNotLocalTransaction(CompensableTransaction compensable) throws RollbackException,
        HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {

    Transaction transaction = compensable.getTransaction();
    org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();
    RemoteCoordinator transactionCoordinator = this.beanFactory.getTransactionCoordinator();

    TransactionXid transactionXid = transactionContext.getXid();
    try {
        transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS);

        TransactionContext compensableContext = compensable.getTransactionContext();
        logger.error("[{}] jta-transaction in try-phase cannot be xa transaction.",
                ByteUtils.byteArrayToString(compensableContext.getXid().getGlobalTransactionId()));

        transactionCoordinator.rollback(transactionXid);
        throw new HeuristicRollbackException();
    } catch (XAException xaEx) {
        transactionCoordinator.forgetQuietly(transactionXid);
        SystemException sysEx = new SystemException();
        sysEx.initCause(xaEx);
        throw sysEx;
    }
}
项目:ByteTCC    文件:CompensableManagerImpl.java   
protected void invokeCompensableCommitIfNotLocalTransaction(CompensableTransaction compensable)
        throws HeuristicRollbackException, SystemException {

    RemoteCoordinator transactionCoordinator = this.beanFactory.getTransactionCoordinator();
    Transaction transaction = compensable.getTransaction();
    org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();

    TransactionXid transactionXid = transactionContext.getXid();
    try {
        transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS);
        TransactionContext compensableContext = compensable.getTransactionContext();
        logger.error("{}| jta-transaction in compensating-phase cannot be xa transaction.",
                ByteUtils.byteArrayToString(compensableContext.getXid().getGlobalTransactionId()));

        transactionCoordinator.rollback(transactionXid);
        throw new HeuristicRollbackException();
    } catch (XAException xaex) {
        transactionCoordinator.forgetQuietly(transactionXid);
        SystemException sysEx = new SystemException();
        sysEx.initCause(xaex);
        throw sysEx;
    }
}
项目:ByteTCC    文件:UserCompensableImpl.java   
public void compensableCommit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
        SecurityException, IllegalStateException, SystemException {
    CompensableManager tompensableManager = this.beanFactory.getCompensableManager();

    CompensableTransaction compensable = (CompensableTransaction) tompensableManager.getCompensableTransactionQuietly();
    if (compensable == null) {
        throw new IllegalStateException();
    }

    TransactionContext transactionContext = compensable.getTransactionContext();
    if (transactionContext.isCoordinator() == false) {
        throw new IllegalStateException();
    }

    this.invokeCompensableCommit(compensable);
}
项目:ByteTCC    文件:CompensableTransactionImpl.java   
public synchronized void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
        SecurityException, IllegalStateException, SystemException {

    if (this.transactionStatus == Status.STATUS_ACTIVE) {
        this.fireCommit();
    } else if (this.transactionStatus == Status.STATUS_MARKED_ROLLBACK) {
        this.fireRollback();
        throw new HeuristicRollbackException();
    } else if (this.transactionStatus == Status.STATUS_ROLLEDBACK) /* should never happen */ {
        throw new RollbackException();
    } else if (this.transactionStatus == Status.STATUS_COMMITTED) /* should never happen */ {
        logger.debug("Current transaction has already been committed.");
    } else {
        throw new IllegalStateException();
    }

}
项目:mercurius    文件:DomainTestContext.java   
protected void truncateTables(String... tables) {
    try {
        utx.begin();
        for (String table : tables) {
            StringBuilder deleteQueryBuilder = new StringBuilder("delete from ");
            deleteQueryBuilder.append(table);
            getEm().createQuery(deleteQueryBuilder.toString()).executeUpdate();
        }
        utx.commit();
    } catch (NotSupportedException | SystemException | SecurityException | IllegalStateException
            | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
        try {
            utx.rollback();
        } catch (IllegalStateException | SecurityException | SystemException e1) {

        }
    }
}
项目:requery    文件:ManagedTransaction.java   
@Override
public void commit() {
    if (initiatedTransaction) {
        try {
            transactionListener.beforeCommit(entities.types());
            getUserTransaction().commit();
            transactionListener.afterCommit(entities.types());
        } catch (RollbackException | SystemException | HeuristicMixedException |
            HeuristicRollbackException e) {
            throw new TransactionException(e);
        }
    }
    try {
        entities.clear();
    } finally {
        close();
    }
}
项目:openjtcc    文件:TransactionManagerImpl.java   
public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException,
        RollbackException, SecurityException, SystemException {
    TransactionImpl global = this.getCurrentTransaction();
    TransactionContext transactionContext = global.getTransactionContext();
    boolean compensable = transactionContext.isCompensable();
    boolean coordinator = transactionContext.isCoordinator();
    if (compensable == false) {
        this.commitRegularTransaction(global);
    } else if (coordinator) {
        if (global.isTransactionCompleting()) {
            global.commitCompleteTransaction();
        } else {
            this.commitGlobalTransaction(global);
        }
    } else if (global.isTransactionCompleting()) {
        global.commitCompleteTransaction();
    } else {
        global.commitTryingTransaction();
    }
}
项目:carbon-transports    文件:QueueTopicXATransactedSenderTestCase.java   
/**
 * This test will publish set of messages through XA transaction and then rollback, then publish another set of
 * messages. All this time a consumer will be running on the particular Queue, and total of the consumed messages
 * should be equal to the total number of committed messages.
 *
 * @throws JMSConnectorException      Error when sending messages through JMS transport connector.
 * @throws InterruptedException       Interruption when thread sleep.
 * @throws JMSException               Error when running the test message consumer.
 * @throws SystemException            XA Transaction exceptions.
 * @throws NotSupportedException      Transaction exceptions.
 * @throws RollbackException          Transaction exceptions.
 * @throws HeuristicRollbackException Transaction exceptions.
 * @throws HeuristicMixedException    Transaction exceptions.
 * @throws NoSuchFieldException       Error when accessing the private field.
 * @throws IllegalAccessException     Error when accessing the private field.
 */
@Test(groups = "jmsSending",
      description = "XA transacted queue sending tested case")
public void queueSendingTestCase()
        throws JMSConnectorException, InterruptedException, JMSException, SystemException, NotSupportedException,
        RollbackException, HeuristicRollbackException, HeuristicMixedException, NoSuchFieldException,
        IllegalAccessException {

    // Run message consumer and publish messages
    performPublishAndConsume(jmsClientConnectorQueue, xaQueueName, false);

    JMSTestUtils.closeResources((JMSClientConnectorImpl) jmsClientConnectorQueue);

    Assert.assertEquals(receivedMsgCount, 5,
            "XA transacted queue sender expected message count " + 5 + " , received message count "
                    + receivedMsgCount);
}
项目:carbon-transports    文件:QueueTopicXATransactedSenderTestCase.java   
/**
 * This test will publish set of messages through XA transaction and then rollback, then publish another set of
 * messages. All this time a consumer will be running on the particular Topic, and total of the consumed messages
 * should be equal to the total number of committed messages.
 *
 * @throws JMSConnectorException      Error when sending messages through JMS transport connector.
 * @throws InterruptedException       Interruption when thread sleep.
 * @throws JMSException               Error when running the test message consumer.
 * @throws SystemException            XA Transaction exceptions.
 * @throws NotSupportedException      Transaction exceptions.
 * @throws RollbackException          Transaction exceptions.
 * @throws HeuristicRollbackException Transaction exceptions.
 * @throws HeuristicMixedException    Transaction exceptions.
 * @throws NoSuchFieldException       Error when accessing the private field.
 * @throws IllegalAccessException     Error when accessing the private field.
 */
@Test(groups = "jmsSending",
      description = "XA transacted topic sending tested case")
public void topicSendingTestCase()
        throws JMSConnectorException, InterruptedException, JMSException, SystemException, NotSupportedException,
        RollbackException, HeuristicRollbackException, HeuristicMixedException, NoSuchFieldException,
        IllegalAccessException {

    // Run message consumer and publish messages
    performPublishAndConsume(jmsClientConnectorTopic, xaTopicName, true);

    JMSTestUtils.closeResources((JMSClientConnectorImpl) jmsClientConnectorTopic);

    Assert.assertEquals(receivedMsgCount, 5,
            "XA transacted topic sender expected message count " + 5 + " , received message count "
                    + receivedMsgCount);
}
项目:switchyard    文件:TransactionHelper.java   
/**
 * Commit.
 * @throws HandlerException oops
 */
public void commit() throws HandlerException {
    if (_isInitiator) {
        try {
            _userTx.commit();
        } catch (SystemException se) {
            throw CommonKnowledgeMessages.MESSAGES.userTransactionCommitFailedSystem(se);
        } catch (HeuristicRollbackException hre) {
            throw CommonKnowledgeMessages.MESSAGES.userTransactionCommitFailedRollback(hre);
        } catch (HeuristicMixedException hme) {
            throw CommonKnowledgeMessages.MESSAGES.userTransactionCommitFailedMixed(hme);
        } catch (RollbackException re) {
            throw CommonKnowledgeMessages.MESSAGES.userTransactionCommitFailed(re);
        }
    }
}
项目:elpi    文件:DumbFactory.java   
public UserTransaction getUserTransaction() {
    return new UserTransaction() {
        public void begin() throws NotSupportedException, SystemException {
        }

        public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
        }

        public int getStatus() throws SystemException {
            return TransactionUtil.STATUS_NO_TRANSACTION;
        }

        public void rollback() throws IllegalStateException, SecurityException, SystemException {
        }

        public void setRollbackOnly() throws IllegalStateException, SystemException {
        }

        public void setTransactionTimeout(int i) throws SystemException {
        }
    };
}
项目:ByteJTA    文件:TransactionImpl.java   
public synchronized void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
        SecurityException, IllegalStateException, CommitRequiredException, SystemException {

    if (this.transactionStatus == Status.STATUS_ACTIVE) {
        this.fireCommit();
    } else if (this.transactionStatus == Status.STATUS_MARKED_ROLLBACK) {
        this.fireRollback();
        throw new HeuristicRollbackException();
    } else if (this.transactionStatus == Status.STATUS_ROLLEDBACK) /* should never happen */ {
        throw new RollbackException();
    } else if (this.transactionStatus == Status.STATUS_COMMITTED) /* should never happen */ {
        logger.debug("Current transaction has already been committed.");
    } else {
        throw new IllegalStateException();
    }

}
项目:ByteJTA    文件:SimpleTransactionStrategy.java   
public void commit(Xid xid)
        throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
    try {
        this.terminator.commit(xid, false);
    } catch (XAException xaex) {
        switch (xaex.errorCode) {
        case XAException.XA_HEURCOM:
            break;
        case XAException.XA_HEURMIX:
            throw new HeuristicMixedException();
        case XAException.XA_HEURRB:
            throw new HeuristicRollbackException();
        default:
            logger.error("Unknown state in committing transaction phase.", xaex);
            throw new SystemException();
        }
    } catch (RuntimeException rex) {
        logger.error("Unknown state in committing transaction phase.", rex);
        throw new SystemException();
    }
}
项目:community-edition-old    文件:SimpleTransaction.java   
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
        SecurityException, SystemException
{
    try
    {
        if (isRollBackOnly)
        {
            throw new RollbackException("Commit failed: Transaction marked for rollback");
        }

    }
    finally
    {
        transaction.set(null);
    }
}
项目:o3erp    文件:DumbFactory.java   
public UserTransaction getUserTransaction() {
    return new UserTransaction() {
        public void begin() throws NotSupportedException, SystemException {
        }

        public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
        }

        public int getStatus() throws SystemException {
            return TransactionUtil.STATUS_NO_TRANSACTION;
        }

        public void rollback() throws IllegalStateException, SecurityException, SystemException {
        }

        public void setRollbackOnly() throws IllegalStateException, SystemException {
        }

        public void setTransactionTimeout(int i) throws SystemException {
        }
    };
}
项目:G4-N-03-SHARE    文件:PromotionsServlet.java   
/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
 *      response)
 */
protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    List<Promotion> resultList = null;
    try {
        tx.begin();
        resultList = entityManager.createNamedQuery("Promotion.findAll")
                .getResultList();

        for (Promotion promotion : resultList) {
            promotion.getPersonnes().size();
        }
        tx.commit();

    } catch (NotSupportedException | SystemException | SecurityException
            | IllegalStateException | RollbackException
            | HeuristicMixedException | HeuristicRollbackException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    request.setAttribute("promotions", resultList);
    request.getRequestDispatcher("WEB-INF/promotions.jsp").forward(request,
            response);

}
项目:G4-N-03-SHARE    文件:PromotionServlet.java   
/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
 *      response)
 */
protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    Promotion result = null;
    String promotionIdString = request.getParameter("promotionId");
    Integer promotionId = Integer.valueOf(promotionIdString);
    try {
        tx.begin();
        result = entityManager.find(Promotion.class, promotionId);

        result.getPersonnes().size();

        tx.commit();

    } catch (NotSupportedException | SystemException | SecurityException
            | IllegalStateException | RollbackException
            | HeuristicMixedException | HeuristicRollbackException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    request.setAttribute("promotion", result);
    request.getRequestDispatcher("WEB-INF/promotion.jsp").forward(request,
            response);
}
项目:clearpool    文件:TransactionImpl.java   
@Override
public void commit() throws RollbackException, HeuristicMixedException,
    HeuristicRollbackException, SecurityException, SystemException {
  if (this.status == Status.STATUS_ROLLEDBACK) {
    throw new RollbackException("the transaction had been rolled back");
  }
  if (this.rollbackOnly) {
    this.rollback();
    return;
  }
  if (this.status != Status.STATUS_ACTIVE) {
    throw new IllegalStateException("the transaction is not active");
  }
  this.tryEndResource();
  boolean preparedSuccess = this.tryPrepared();
  if (preparedSuccess) {
    this.tryCommit();
    return;
  }
  try {
    this.tryRollback();
  } catch (SystemException e) {
    throw new HeuristicRollbackException(e.getMessage());
  }
  throw new HeuristicRollbackException("roll back all the transaction");
}
项目:fuse-bxms-integ    文件:TransactionHelper.java   
/** Commit.
 * 
 * @throws HandlerException oops */
public void commit() throws HandlerException {
    if (_isInitiator) {
        try {
            _userTx.commit();
        } catch (SystemException se) {
            throw CommonKnowledgeMessages.MESSAGES.userTransactionCommitFailedSystem(se);
        } catch (HeuristicRollbackException hre) {
            throw CommonKnowledgeMessages.MESSAGES.userTransactionCommitFailedRollback(hre);
        } catch (HeuristicMixedException hme) {
            throw CommonKnowledgeMessages.MESSAGES.userTransactionCommitFailedMixed(hme);
        } catch (RollbackException re) {
            throw CommonKnowledgeMessages.MESSAGES.userTransactionCommitFailed(re);
        }
    }
}
项目:ironjacamar    文件:TransactionManagerImpl.java   
/**
 * {@inheritDoc}
 */
public void commit() throws RollbackException,
                            HeuristicMixedException,
                            HeuristicRollbackException,
                            SecurityException,
                            IllegalStateException,
                            SystemException
{
   Transaction tx = registry.getTransaction();

   if (tx == null)
      throw new SystemException();

   if (tx.getStatus() == Status.STATUS_ROLLEDBACK ||
       tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
      throw new RollbackException();

   registry.commitTransaction();
}
项目:ironjacamar    文件:TransactionImpl.java   
/**
 * {@inheritDoc}
 */
public void commit() throws RollbackException,
                            HeuristicMixedException,
                            HeuristicRollbackException,
                            SecurityException,
                            IllegalStateException,
                            SystemException
{
   if (status == Status.STATUS_UNKNOWN)
      throw new IllegalStateException("Status unknown");

   if (status == Status.STATUS_MARKED_ROLLBACK)
      throw new IllegalStateException("Status marked rollback");

   finish(true);
}
项目:ironjacamar    文件:UserTransactionImpl.java   
/**
 * {@inheritDoc}
 */
public void commit() throws RollbackException,
                            HeuristicMixedException,
                            HeuristicRollbackException,
                            SecurityException,
                            IllegalStateException,
                            SystemException
{
   Transaction tx = registry.getTransaction();

   if (tx == null)
      throw new SystemException();

   if (tx.getStatus() == Status.STATUS_ROLLING_BACK ||
       tx.getStatus() == Status.STATUS_ROLLEDBACK ||
       tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
      throw new RollbackException();

   registry.commitTransaction();
}
项目:tomee    文件:CmrMappingTests.java   
private void validateOneToManyRelationship() throws NotSupportedException, SystemException, Exception, HeuristicMixedException, HeuristicRollbackException, RollbackException {
    try {
        final OneInverseSideLocal inverseLocal = findOneInverseSide(compoundPK_20_10_field1);


        // verify one side has a set containing the many bean
        final Set set = inverseLocal.getManyOwningSide();
        Assert.assertEquals(1, set.size());
        final ManyOwningSideLocal owningLocal = (ManyOwningSideLocal) set.iterator().next();
        Assert.assertEquals(compoundPK_20_10, owningLocal.getPrimaryKey());

        // verify the many bean has a back reference to the one
        final OneInverseSideLocal oneInverseSide = owningLocal.getOneInverseSide();
        Assert.assertNotNull(oneInverseSide);
        Assert.assertEquals(compoundPK_20_10_field1, oneInverseSide.getPrimaryKey());

        completeTransaction();
    } finally {
        completeTransaction();
    }
}
项目:Pingeso    文件:StudentManagementSB.java   
/**
 *
 * @param object
 * @return
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public boolean persistInsert(Object object) {
    try {
        ut.begin(); // Start a new transaction
        try {
            em.persist(object);
            ut.commit(); // Commit the transaction
            return true;
        } catch (RollbackException | HeuristicMixedException | HeuristicRollbackException | SecurityException | IllegalStateException | SystemException e) {
            ut.rollback(); // Rollback the transaction
            return false;
        }
    } catch (NotSupportedException | SystemException ex) {
        Logger.getLogger(TakeAttendanceSB.class.getName()).log(Level.SEVERE, null, ex); // Rollback the transaction
        return false;
    }
}
项目:Pingeso    文件:StudentManagementSB.java   
/**
 *
 * @param object
 * @return
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public boolean persistUpdate(Object object) {
    try {
        ut.begin(); // Start a new transaction
        try {
            em.merge(object);
            ut.commit(); // Commit the transaction
            return true;
        } catch (RollbackException | HeuristicMixedException | HeuristicRollbackException | SecurityException | IllegalStateException | SystemException e) {
            ut.rollback(); // Rollback the transaction
            System.out.println("rollbakc:" + e);
            return false;
        }
    } catch (NotSupportedException | SystemException ex) {
        Logger.getLogger(TakeAttendanceSB.class.getName()).log(Level.SEVERE, null, ex); // Rollback the transaction
        System.out.println("rollbakc:" + ex);
        return false;
    }
}