Package javax.transaction

Examples of javax.transaction.TransactionManager


                }

                if (loc != null)
                {
                    // Return the actual TransactionManager
                    TransactionManager tm = loc.getTransactionManager(clr);
                    if (tm != null)
                    {
                        return tm;
                    }
                }
View Full Code Here


            } else {
                logger.debug("startup.securityService", securityService.getClass().getName());
            }
            system.setComponent(SecurityService.class, securityService);

            TransactionManager transactionManager = assembler.getTransactionManager();
            if (transactionManager == null) {
                String msg = messages.message("startup.assemblerReturnedNullTransactionManager");
                logger.fatal(msg);
                throw new OpenEJBException(msg);
            } else {
                logger.debug("startup.transactionManager", transactionManager.getClass().getName());
            }
            SystemInstance.get().setComponent(TransactionManager.class, transactionManager);

            logger.info("startup.ready");
View Full Code Here

    public Map<String, Object> buildMap() throws OpenEJBException {
        Map<String, Object> bindings = new HashMap<String, Object>();

        // bind TransactionManager
        TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
        bindings.put("java:comp/TransactionManager", transactionManager);

        // bind TransactionSynchronizationRegistry
        TransactionSynchronizationRegistry synchronizationRegistry = SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class);
        bindings.put("java:comp/TransactionSynchronizationRegistry", synchronizationRegistry);
View Full Code Here

  private boolean isTestMethodScopedSessionFactoryRequired(FrameworkMethod method) {
    return !testMethodScopedFactoryFields.isEmpty() && !super.isTestMethodSkipped( method );
  }

  private void cleanUpPendingTransactionIfRequired() {
    TransactionManager transactionManager = ( (SessionFactoryImplementor) testScopedSessionFactory )
        .getServiceRegistry()
        .getService( JtaPlatform.class )
        .retrieveTransactionManager();

    try {
      if ( transactionManager != null && transactionManager.getTransaction() != null ) {
        LOG.warn( "The test started a transaction but failed to commit it or roll it back. Going to roll it back." );
        transactionManager.rollback();
      }
    }
    catch (Exception e) {
      throw new RuntimeException( e );
    }
View Full Code Here

    if ( !transactionFactory.compatibleWithJtaSynchronization() ) {
      // Today we only require a TransactionManager on JTA based transaction factories
      log.trace( "TransactionFactory does not require a TransactionManager: don't wrap in a JTA transaction" );
      return false;
    }
    final TransactionManager transactionManager = getTransactionManager();
    if ( transactionManager == null ) {
      // no TM, nothing to do OR configuration mistake
      log.trace( "No TransactionManager found, do not start a surrounding JTA transaction" );
      return false;
    }
    try {
      if ( transactionManager.getStatus() == Status.STATUS_NO_TRANSACTION ) {
        log.trace( "No Transaction in progress, needs to start a JTA transaction" );
        return true;
      }
    }
    catch ( SystemException e ) {
View Full Code Here

      errorHandler.handleException( log.massIndexerUnexpectedErrorMessage(), e );
    }
  }

  private void consumeInTransaction(Tuple tuple) {
    TransactionManager transactionManager = getTransactionManager();
    try {
      final Session session = factory.openSession();
      transactionManager.begin();
      delegate.run( session, tuple );
      transactionManager.commit();
      session.close();
    }
    catch ( Throwable e ) {
      errorHandler.handleException( log.massIndexerUnexpectedErrorMessage(), e );
      rollback( transactionManager, e );
View Full Code Here

  @Test
  public void testJTAStandalone() throws Exception {

    final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone", TestHelper.getEnvironmentProperties() );

    TransactionManager transactionManager = extractJBossTransactionManager( emf );

    transactionManager.begin();
    final EntityManager em = emf.createEntityManager();
    Poem poem = new Poem();
    poem.setName( "L'albatros" );
    em.persist( poem );
    transactionManager.commit();

    em.clear();

    transactionManager.begin();
    poem = em.find( Poem.class, poem.getId() );
    assertThat( poem ).isNotNull();
    assertThat( poem.getName() ).isEqualTo( "L'albatros" );
    em.remove( poem );
    transactionManager.commit();

    em.close();

    dropSchemaAndDatabase( emf );
    emf.close();
View Full Code Here

  public void testJPAPolymorphicFind() throws Exception {

    final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone",
        TestHelper.getEnvironmentProperties() );

    TransactionManager transactionManager = extractJBossTransactionManager( emf );

    transactionManager.begin();
    final EntityManager em = emf.createEntityManager();
    Hero h = new Hero();
    h.setName( "Spartacus" );
    em.persist( h );
    SuperHero sh = new SuperHero();
    sh.setName( "Batman" );
    sh.setSpecialPower( "Technology and samurai techniques" );
    em.persist( sh );
    transactionManager.commit();

    em.clear();

    transactionManager.begin();
    Hero lh = em.find( Hero.class, h.getName() );
    assertThat( lh ).isNotNull();
    assertThat( lh ).isInstanceOf( Hero.class );
    Hero lsh = em.find( Hero.class, sh.getName() );
    assertThat( lsh ).isNotNull();
    assertThat( lsh ).isInstanceOf( SuperHero.class );
    em.remove( lh );
    em.remove( lsh );

    transactionManager.commit();

    em.close();

    dropSchemaAndDatabase( emf );
    emf.close();
View Full Code Here

        }
    }
   
   
    public void onEntry() throws SystemException, NotSupportedException {
        TransactionManager manager = null;
        synchronized (this) {
            if (this.manager != null) {
                manager = this.manager; // Stack confinement
            } else {
                return; // Nothing can be done...
            }
        }
       
        Transaction transaction = manager.getTransaction();
        switch (propagation) {
            case REQUIRES:
                // Are we already in a transaction?
                if (transaction == null) {
                    // No, create one
                    if (timeout > 0) {
                        manager.setTransactionTimeout(timeout);
                    }
                    manager.begin();
                    m_owned.put(Thread.currentThread(), manager.getTransaction());
                } else {
                    // Add the transaction to the transaction list
                    handler.addTransaction(transaction);
                }
                break;
            case MANDATORY:
                if (transaction == null) {
                    // Error
                    throw new IllegalStateException("The method " + method + " must be called inside a transaction");
                } else {
                    // Add the transaction to the transaction list
                    handler.addTransaction(transaction);
                }
                break;
            case SUPPORTED:
                // if transaction != null, register the callback, else do nothing
                if (transaction != null) {
                    handler.addTransaction(transaction);
                } // Else do nothing.
                break;
            case NOT_SUPPORTED:
                // Do nothing.
                break;
            case NEVER:
                if (transaction != null) {
                    throw new IllegalStateException("The method " + method + " must never be called inside a transaction");
                }
                break;
            case REQUIRES_NEW:
                if (transaction == null) {
                    // No current transaction, Just creates a new one
                    if (timeout > 0) {
                        manager.setTransactionTimeout(timeout);
                    }
                    manager.begin();
                    m_owned.put(Thread.currentThread(), manager.getTransaction());
                } else {
                    if (suspended == null) {
                        suspended = manager.suspend();
                        if (timeout > 0) {
                            manager.setTransactionTimeout(timeout);
                        }
                        manager.begin();
                        m_owned.put(Thread.currentThread(), manager.getTransaction());
                    } else {
                        throw new IllegalStateException("The method " + method + " requires to suspend a second times a transaction");
                    }
                }
                break;
View Full Code Here

       
        }
    }
   
    public void onError(String exception) throws SystemException {
        TransactionManager manager = null;
        synchronized (this) {
            if (this.manager != null) {
                manager = this.manager; // Stack confinement
            } else {
                return; // Nothing can be done...
            }
        }
       
        // is the error something to exclude, and are we inside the transaction (owner or participant)?
        if (! exceptions.contains(exception)) {
            Transaction tr = manager.getTransaction();
            if (m_owned.containsValue(tr|| handler.getTransactions().contains(tr)) {
                // Set the transaction to rollback only
                manager.getTransaction().setRollbackOnly();
            }
        }
    }
View Full Code Here

TOP

Related Classes of javax.transaction.TransactionManager

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.