Java 类javax.transaction.NotSupportedException 实例源码

项目: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");
    }

}
项目:Mastering-Java-EE-Development-with-WildFly    文件:EventTestCase.java   
/**
 * Tests the fire of the event inside a failed transaction
 */
@Test
public void testFailedTransaction() {
    Bill bill = null;
    try {
        userTransaction.begin();
        bill = fire();
        assertEquals(
                "The id generation passes through the always and it is incremented only by inprogess always observer method",
                1, bill.getId());
        throw new RollbackException();
    } catch (NotSupportedException | SystemException | SecurityException | IllegalStateException
            | RollbackException e) {
        try {
            userTransaction.rollback();
            assertEquals(
                    "The id generation passes through the always and it is incremented only by transactional failure observer methods",
                    3, bill.getId());
        } catch (SystemException se) {

        }
    }

}
项目: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( "Basic rollback test" )
public void basicRollbackTest() 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 ) ) {
        txManager.begin();

        Connection connection = dataSource.getConnection();
        logger.info( format( "Got connection {0}", connection ) );

        txManager.rollback();

        assertTrue( connection.isClosed() );
    } catch ( NotSupportedException | SystemException e ) {
        fail( "Exception: " + e.getMessage() );
    }
}
项目: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 {
        }
    };
}
项目:scipio-erp    文件:TransactionUtil.java   
protected static void internalBegin(UserTransaction ut, int timeout) throws SystemException, NotSupportedException {
    // set the timeout for THIS transaction
    if (timeout > 0) {
        ut.setTransactionTimeout(timeout);
        if (Debug.verboseOn()) {
            Debug.logVerbose("Set transaction timeout to : " + timeout + " seconds", module);
        }
    }

    // begin the transaction
    ut.begin();
    if (Debug.verboseOn()) {
        Debug.logVerbose("Transaction begun", module);
    }

    // reset the timeout to the default
    if (timeout > 0) {
        ut.setTransactionTimeout(0);
    }
}
项目:spring4-understanding    文件:JtaTransactionManagerTests.java   
@Test
public void jtaTransactionManagerWithNotSupportedExceptionOnNestedBegin() throws Exception {
    UserTransaction ut = mock(UserTransaction.class);
    given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
    willThrow(new NotSupportedException("not supported")).given(ut).begin();

    try {
        JtaTransactionManager ptm = newJtaTransactionManager(ut);
        TransactionTemplate tt = new TransactionTemplate(ptm);
        tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_NESTED);
        tt.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                // something transactional
            }
        });
        fail("Should have thrown NestedTransactionNotSupportedException");
    }
    catch (NestedTransactionNotSupportedException ex) {
        // expected
    }
}
项目:sigma-events    文件:QueryBuilder.java   
public void deleteById(Object id) throws NotSupportedException, SystemException {
  tm.begin();
  try {
    EntityManager em = emf.createEntityManager();
    E entity = em.find(entityClass, id);
    if (entity != null) {
      em.remove(entity);
    }
    em.flush();
    em.close();
    tm.commit();
  } catch (Exception e) {
    e.printStackTrace();
    throw new SystemException(e.getMessage());
  }
}
项目:sigma-events    文件:EventDetailModelAccessProvider.java   
@Override
public EventDetailModel create(EventDetailModel entity)
    throws NotSupportedException, SystemException {

  SystemEventDetailModel systemEventDetail = entity.getSystemEventDetail();
  if (systemEventDetail != null && systemEventDetail.getId() == null) {
    systemEventDetail = new SystemEventDetailModelAccessProvider().create(systemEventDetail);
    entity.setSystemEventDetail(systemEventDetail);
  }

  UserEventDetailModel userEventDetail = entity.getUserEventDetail();
  if (userEventDetail != null && userEventDetail.getId() == null) {
    userEventDetail = new UserEventDetailModelAccessProvider().create(userEventDetail);
    entity.setUserEventDetail(userEventDetail);
  }
  return super.create(entity);
}
项目:sigma-events    文件:EventModelAccessProvider.java   
@Override
public EventModel create(EventModel entity) throws NotSupportedException, SystemException {
  EventHeaderModel header = entity.getHeader();
  if (header.getId() == null) {
    header = new EventHeaderModelAccessProvider().create(header);
    entity.setHeader(header);
  }

  EventDetailModel eventDetail = entity.getEventDetail();
  if (eventDetail != null) {
    if (eventDetail.getId() == null) {
      eventDetail = new EventDetailModelAccessProvider().create(eventDetail);
      entity.setEventDetail(eventDetail);
    }
  }

  return super.create(entity);
}
项目:ByteTCC    文件:TransactionManagerImpl.java   
public void begin() throws NotSupportedException, SystemException {
    TransactionManager transactionManager = this.beanFactory.getTransactionManager();
    CompensableManager compensableManager = this.beanFactory.getCompensableManager();

    CompensableTransaction transaction = compensableManager.getCompensableTransactionQuietly();

    CompensableInvocationRegistry registry = CompensableInvocationRegistry.getInstance();
    CompensableInvocation invocation = registry.getCurrent();

    if (transaction != null) {
        compensableManager.begin();
    } else if (invocation != null) {
        compensableManager.compensableBegin();
    } else {
        transactionManager.begin();
    }

}
项目:ByteTCC    文件:CompensableManagerImpl.java   
public void begin() throws NotSupportedException, SystemException {
    CompensableTransaction compensable = this.getCompensableTransactionQuietly();
    if (compensable == null || compensable.getTransaction() != null) {
        throw new SystemException();
    }

    TransactionContext compensableContext = compensable.getTransactionContext();

    XidFactory transactionXidFactory = this.beanFactory.getTransactionXidFactory();
    TransactionXid transactionXid = transactionXidFactory.createGlobalXid();

    TransactionContext transactionContext = compensableContext.clone();
    transactionContext.setXid(transactionXid);

    this.invokeBegin(transactionContext, false);
}
项目:ByteTCC    文件:CompensableManagerImpl.java   
protected void invokeRollbackInBegin(TransactionContext transactionContext) throws NotSupportedException, SystemException {
    RemoteCoordinator transactionCoordinator = this.beanFactory.getTransactionCoordinator();

    CompensableTransaction compensable = this.getCompensableTransactionQuietly();
    TransactionContext compensableContext = compensable.getTransactionContext();

    TransactionXid compensableXid = compensableContext.getXid();
    TransactionXid transactionXid = transactionContext.getXid();
    try {
        transactionCoordinator.end(transactionContext, XAResource.TMFAIL);
        transactionCoordinator.rollback(transactionXid);
    } catch (XAException tex) {
        logger.info("[{}] begin-transaction: error occurred while starting jta-transaction: {}",
                ByteUtils.byteArrayToString(compensableXid.getGlobalTransactionId()),
                ByteUtils.byteArrayToString(transactionXid.getGlobalTransactionId()), tex);
    }
}
项目: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) {

        }
    }
}
项目:lastaflute    文件:LazyUserTransaction.java   
@Override
protected void doBegin() throws NotSupportedException, SystemException {
    if (canLazyTransaction()) {
        if (!isLazyTransactionLazyBegun()) { // first transaction
            incrementHierarchyLevel();
            toBeLazyTransaction(); // not begin real transaction here for lazy
        } else { // lazy now, this begin() means nested transaction
            if (!isLazyTransactionRealBegun()) { // not begun lazy transaction yet
                beginRealTransactionLazily(); // forcedly begin outer transaction before e.g. 'requiresNew' scope
                suspendForcedlyBegunLazyTransactionIfNeeds(); // like requires new transaction
            }
            incrementHierarchyLevel();
            superDoBegin(); // nested transaction is not lazy fixedly
        }
    } else { // normal transaction
        superDoBegin();
    }
}
项目:openjtcc    文件:TransactionManagerImpl.java   
private void beginInternalTransaction() throws SystemException, NotSupportedException {
    TransactionImpl global = this.getCurrentTransaction();
    JtaTransactionImpl internal = this.getTransaction();
    if (internal == null) {
        internal = global.associateInternalTransaction();
        logger.info(String.format("[begin-native] global: %s, inner: %s", global, internal));

        if (global.isTransactionCompleting() == false) {
            AbstractSynchronization sync = this.threadToSynMap.get(Thread.currentThread());
            if (sync != null) {
                try {
                    TransactionContext transactionContext = global.getTransactionContext();
                    sync.afterCreation(transactionContext.getCurrentXid());
                } finally {
                    this.unRegisterSynchronization(sync);
                }
            }
        }
    } else {
        throw new NotSupportedException();
    }
}
项目:genericconnector    文件:MicroserviceResourceProducerTest.java   
@Test
public void testFind() throws ResourceException, NotSupportedException, SystemException {
    MicroserviceResourceFactory msrFactory = mock(MicroserviceResourceFactory.class);
    MicroserviceXAResource xa = new MicroserviceXAResource("a", mock(CommitRollbackCallback.class));
    when(msrFactory.build()).thenReturn(xa);
    MicroserviceResourceProducer.registerMicroserviceResourceFactory("a", msrFactory);
    MicroserviceResourceProducer producer = MicroserviceResourceProducer.getProducers().values().iterator().next();

       BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
       try{
        tm.begin();

        //TEST
        producer.getTransactionAssistant(); //enlists resource into TX and means we can then go find it

        XAResource found = producer.findXAResourceHolder(xa).getXAResource();
        assertEquals(xa, found);
       }finally{
        tm.rollback();
       }
}
项目: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   
/**
 * Begin.
 * @throws HandlerException oops
 */
public void begin() throws HandlerException {
    if (_enabled) {
        try {
            _userTx = TransactionManagerLocator.INSTANCE.getUserTransaction();
            if (_userTx.getStatus() == Status.STATUS_NO_TRANSACTION) {
                _userTx.begin();
                _isInitiator = true;
            }
        } catch (SystemException se) {
            throw CommonKnowledgeMessages.MESSAGES.userTransactionBeginFailedSystem(se);
        } catch (NotSupportedException nse) {
            throw CommonKnowledgeMessages.MESSAGES.userTransactionBeginFailedNSE(nse);
        }
    }
}
项目: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 {
        }
    };
}
项目:elpi    文件:TransactionUtil.java   
protected static void internalBegin(UserTransaction ut, int timeout) throws SystemException, NotSupportedException {
    // set the timeout for THIS transaction
    if (timeout > 0) {
        ut.setTransactionTimeout(timeout);
        if (Debug.verboseOn()) {
            Debug.logVerbose("[TransactionUtil.begin] set transaction timeout to : " + timeout + " seconds", module);
        }
    }

    // begin the transaction
    ut.begin();
    if (Debug.verboseOn()) {
        Debug.logVerbose("[TransactionUtil.begin] transaction begun", module);
    }

    // reset the timeout to the default
    if (timeout > 0) {
        ut.setTransactionTimeout(0);
    }
}
项目: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 {
        }
    };
}
项目:o3erp    文件:TransactionUtil.java   
protected static void internalBegin(UserTransaction ut, int timeout) throws SystemException, NotSupportedException {
    // set the timeout for THIS transaction
    if (timeout > 0) {
        ut.setTransactionTimeout(timeout);
        if (Debug.verboseOn()) {
            Debug.logVerbose("[TransactionUtil.begin] set transaction timeout to : " + timeout + " seconds", module);
        }
    }

    // begin the transaction
    ut.begin();
    if (Debug.verboseOn()) {
        Debug.logVerbose("[TransactionUtil.begin] transaction begun", module);
    }

    // reset the timeout to the default
    if (timeout > 0) {
        ut.setTransactionTimeout(0);
    }
}
项目:class-guard    文件:JtaTransactionManagerTests.java   
public void testJtaTransactionManagerWithNotSupportedExceptionOnNestedBegin() throws Exception {
    UserTransaction ut = mock(UserTransaction.class);
    given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
    willThrow(new NotSupportedException("not supported")).given(ut).begin();

    try {
        JtaTransactionManager ptm = newJtaTransactionManager(ut);
        TransactionTemplate tt = new TransactionTemplate(ptm);
        tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_NESTED);
        tt.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                // something transactional
            }
        });
        fail("Should have thrown NestedTransactionNotSupportedException");
    }
    catch (NestedTransactionNotSupportedException ex) {
        // expected
    }
}
项目: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);
}
项目:mycollab    文件:JackRabbitUserTransaction.java   
/**
 * @see javax.transaction.UserTransaction#begin
 */
@Override
public void begin() throws NotSupportedException, SystemException {
    if (status != Status.STATUS_NO_TRANSACTION) {
        throw new IllegalStateException("Transaction already active");
    }

    try {
        xid = new XidImpl(counter++);
        xares.start(xid, XAResource.TMNOFLAGS);
        status = Status.STATUS_ACTIVE;

    } catch (XAException e) {
        final SystemException systemException = new SystemException("Unable to commit transaction: " + "XA_ERR="
                + e.errorCode);
        systemException.initCause(e);
        throw systemException;
    }
}
项目:Hibernate-Search-GenericJPA    文件:TransactionWrappedReusableEntityProvider.java   
private void beginTransaction() {
    if ( !this.useJTATransaction ) {
        this.em.getTransaction().begin();
    }
    else {
        try {
            if ( this.transactionManager.getStatus() == Status.STATUS_NO_TRANSACTION ) {
                this.transactionManager.begin();
                this.em.joinTransaction();
                this.startedJTA = true;
            }
            else {
                throw new AssertionFailure(
                        "TransactionWrappedReusableEntityProvider must be able to start/close it's own transactions!"
                );
            }
        }
        catch (NotSupportedException | SystemException e) {
            throw new SearchException( "couldn't start a JTA Transaction", e );
        }
    }
}