Search in sources :

Example 6 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project wildfly by wildfly.

the class TransactedTopicMessageSender method sendToTopicSuccessfully.

@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public void sendToTopicSuccessfully() throws Exception {
    Connection connection = null;
    Session session = null;
    try {
        logger.trace("Creating a Connection");
        connection = factory.createConnection();
        logger.trace("Creating a Session");
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(topic);
        Message message = session.createTextMessage("Hello world!");
        logger.trace("Sending message");
        producer.send(message);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (session != null) {
            session.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : Message(javax.jms.Message) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) JMSException(javax.jms.JMSException) Session(javax.jms.Session) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 7 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project hibernate-orm by hibernate.

the class CmtSfStatefulBean method start.

@TransactionAttribute(TransactionAttributeType.NEVER)
public void start() {
    try {
        Configuration configuration = new Configuration();
        configuration = configuration.configure("hibernate.cfg.xml");
        configuration.addAnnotatedClass(WildFlyDdlEntity.class);
        sessionFactory = configuration.buildSessionFactory();
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 8 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project wildfly by wildfly.

the class SFSB method setupConfig.

@TransactionAttribute(TransactionAttributeType.NEVER)
public void setupConfig() {
    // static {
    try {
        // prepare the configuration
        Configuration configuration = new Configuration().setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
        configuration.getProperties().put(AvailableSettings.JTA_PLATFORM, JBossAppServerJtaPlatform.class);
        configuration.getProperties().put(AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jta");
        configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
        configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS");
        // fetch the properties
        Properties properties = new Properties();
        configuration = configuration.configure("hibernate.cfg.xml");
        properties.putAll(configuration.getProperties());
        Environment.verifyProperties(properties);
        ConfigurationHelper.resolvePlaceHolders(properties);
        sessionFactory = configuration.buildSessionFactory();
    } catch (Throwable ex) {
        // Make sure you log the exception, as it might be swallowed
        ex.printStackTrace();
        throw new ExceptionInInitializerError(ex);
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) Properties(java.util.Properties) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 9 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project wildfly by wildfly.

the class SFSBCMT method queryEmployeeNameRequireNewTX.

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Employee queryEmployeeNameRequireNewTX(int id) {
    Query q = em.createQuery("SELECT e FROM Employee e where id=?");
    q.setParameter(1, new Integer(id));
    return (Employee) q.getSingleResult();
}
Also used : Query(javax.persistence.Query) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 10 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project wildfly by wildfly.

the class TransactedQueueMessageSender method sendToQueueAndRollback.

@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public void sendToQueueAndRollback() throws JMSException {
    Connection connection = null;
    Session session = null;
    try {
        logger.trace("Creating a Connection");
        connection = factory.createConnection();
        logger.trace("Creating a Session");
        session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        Message message = session.createTextMessage("Hello world 2!");
        logger.trace("Sending message");
        producer.send(message);
        // ROLLBACK
        ctx.setRollbackOnly();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (session != null) {
            session.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : Message(javax.jms.Message) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) JMSException(javax.jms.JMSException) Session(javax.jms.Session) TransactionAttribute(javax.ejb.TransactionAttribute)

Aggregations

TransactionAttribute (javax.ejb.TransactionAttribute)13 Connection (javax.jms.Connection)4 JMSException (javax.jms.JMSException)4 Message (javax.jms.Message)4 MessageProducer (javax.jms.MessageProducer)4 Session (javax.jms.Session)4 Configuration (org.hibernate.cfg.Configuration)3 Properties (java.util.Properties)2 NoResultException (javax.persistence.NoResultException)2 Query (javax.persistence.Query)2 UserTransaction (javax.transaction.UserTransaction)2 Method (java.lang.reflect.Method)1 EntityManager (javax.persistence.EntityManager)1 EntityTransaction (javax.persistence.EntityTransaction)1 Transactional (javax.transaction.Transactional)1 BeanContext (org.apache.openejb.BeanContext)1 ThreadContext (org.apache.openejb.core.ThreadContext)1 TransactionPolicy (org.apache.openejb.core.transaction.TransactionPolicy)1 TransactionType (org.apache.openejb.core.transaction.TransactionType)1 Statement (org.junit.runners.model.Statement)1