Package org.mule.api.transaction

Examples of org.mule.api.transaction.Transaction


    {
        InterceptingMessageProcessor mp = new OutboundTxRollbackMessageProcessor();
        TestListener listener = new TestListener();
        mp.setListener(listener);

        Transaction tx = new TestTransaction(muleContext);
        try
        {
            TransactionCoordination.getInstance().bindTransaction(tx);
            tx.setRollbackOnly();

            MuleEvent event = createTestOutboundEvent();
            MuleEvent result = mp.process(event);

            assertNull(listener.sensedEvent);
View Full Code Here


    }
    if (log.isDebugEnabled()) {
      log.debug("Enlistment request");
    }

    Transaction transaction = TransactionCoordination.getInstance().getTransaction();
    if (transaction == null) {
      throw new IllegalTransactionStateException(CoreMessages.noMuleTransactionAvailable());
    }
    if (!(transaction instanceof XaTransaction)) {
      throw new IllegalTransactionStateException(CoreMessages.notMuleXaTransaction(transaction));
View Full Code Here

    }
    if (log.isDebugEnabled()) {
      log.debug("Delistment request");
    }

    Transaction transaction = TransactionCoordination.getInstance().getTransaction();
    if (transaction == null) {
      throw new IllegalTransactionStateException(CoreMessages.noMuleTransactionAvailable());
    }
    if (!(transaction instanceof XaTransaction)) {
      throw new IllegalTransactionStateException(CoreMessages.notMuleXaTransaction(transaction));
    }
    if (isEnlisted() && transaction.isXA()) {
      XAConnection conn = ((org.apache.openjpa.jdbc.kernel.JDBCStoreManager.ClientConnection) (impl
          .unwrap(org.apache.openjpa.persistence.EntityManagerImpl.class)).getConnection()).getInnermostDelegate().unwrap(XAConnection.class);

      if (conn != null) {
        XAResource xaResource = ((XAConnection) conn).getXAResource();
View Full Code Here

  private Object executeJpaQuery(String query, Boolean singleResult, Map<String, Object> parameters, Integer maxResults, Integer startPosition)
      throws JpaException {
    EntityManager em = null;
    EntityTransaction etx = null;
    try {
      Transaction tx = TransactionCoordination.getInstance().getTransaction();
      em = getEntityManager();
      if (tx == null) {
        log.info("No transaction available, so open a new transaction");
        etx = em.getTransaction();
      }
View Full Code Here

  @Processor
  public Object executeDslQuery(QueryDslQuery jpaQuery, @Optional String maxResults, @Optional Boolean singleResult, @Optional Boolean distinct,
      @Optional Boolean returnCount) throws JpaException {
    EntityManager em = null;
    EntityTransaction etx = null;
    Transaction tx = TransactionCoordination.getInstance().getTransaction();

    Integer maxRes = parseMaxResults(maxResults);

    try {
      em = getEntityManager();
View Full Code Here

  private Object executeStrategy(EntityManagerStrategy emStrategy, Object payload) throws JpaException {
    EntityManager em = null;
    EntityTransaction etx = null;

    Transaction tx = TransactionCoordination.getInstance().getTransaction();
    try {
      em = emStrategy.getEntityManager();
      if (tx == null) {
        log.info("No transaction available, so open a new transaction");
        etx = em.getTransaction();
View Full Code Here

    }

  }

  private EntityManager getEntityManager() {
    Transaction tx = TransactionCoordination.getInstance().getTransaction();
    if (tx != null) {
      if (tx.hasResource(entityManagerFactory)) {
        log.debug("Retrieving session from current transaction");
        Object r = tx.getResource(entityManagerFactory);
        if (r instanceof JpaXaResource) {
          return ((JpaXaResource) r).getEntityManager();
        } else {
          return (EntityManager) r;
        }
      }
    }
    log.debug("Retrieving new entityManager from factory");
    EntityManager entityManager;
    if (jpaProperties != null && !jpaProperties.isEmpty()) {
      entityManager = entityManagerFactory.createEntityManager(jpaProperties);
    } else {
      entityManager = entityManagerFactory.createEntityManager();
    }
    if (tx != null) {
      log.debug("Binding session to current transaction");
      try {
        Object r;
        if (tx instanceof XaTransaction) {
          if (isUnmanagedPoolAndOpenJpa) {
            r = new JpaXaResourceForTomcatAndOpenJpa(entityManager);
          } else {
            r = new JpaXaResource(entityManager);
          }
        } else {
          r = entityManager;
        }
        tx.bindResource(entityManagerFactory, r);
      } catch (TransactionException e) {
        throw new RuntimeException("Could not bind connection to current transaction", e);
      }
    }
    return entityManager;
View Full Code Here

                fail with fanfares to signal this case, which is really a user error.
              */

            if (session != null && endpoint != null) // endpoint can be null in some programmatic tests only in fact
            {
                Transaction muleTx = TransactionCoordination.getInstance().getTransaction();

                final JmsConnector connector = (JmsConnector) endpoint.getConnector();
                if (muleTx == null)
                {
                    if (logger.isDebugEnabled())
                    {
                        logger.debug("Closing non-transacted jms session: " + session);
                    }
                    connector.closeQuietly(session);
                }
                else if (!muleTx.hasResource(connector.getConnection()))
                {
                    // this is some other session from another connection, don't let it leak
                    if (logger.isDebugEnabled())
                    {
                        logger.debug("Closing an orphaned, but transacted jms session: " + session +
View Full Code Here

    public void createsConnectionWhenJoinIfPossibleAndActiveTransaction() throws Exception
    {
        Connection expectedConnection = mock(Connection.class);
        when(connectionFactory.create(datasource)).thenReturn(expectedConnection);

        Transaction transaction = mock(Transaction.class);
        when(transaction.hasResource(datasource)).thenReturn(false);

        when(dbTransactionManager.getTransaction()).thenReturn(transaction);

        factory = new TransactionalDbConnectionFactory(dbTransactionManager, null, connectionFactory, datasource);
View Full Code Here

    private void doUseActiveTransaction(TransactionalAction transactionalAction) throws SQLException
    {
        Connection expectedConnection = mock(Connection.class);

        Transaction transaction = mock(Transaction.class);
        when(transaction.hasResource(datasource)).thenReturn(true);
        when(transaction.getResource(datasource)).thenReturn(expectedConnection);

        when(dbTransactionManager.getTransaction()).thenReturn(transaction);

        factory = new TransactionalDbConnectionFactory(dbTransactionManager, null, null, datasource);
        DbConnection connection = factory.createConnection(transactionalAction);
View Full Code Here

TOP

Related Classes of org.mule.api.transaction.Transaction

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.