Package org.springframework.orm.jpa

Examples of org.springframework.orm.jpa.EntityManagerHolder


            if ( this.appScopedEntityManager != null && !this.appScopedEntityManager.isOpen() ) {
                throw new RuntimeException( "Provided APP_SCOPED_ENTITY_MANAGER is not open" );
            }

            if ( this.appScopedEntityManager == null ) {
                EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource( this.emf );
                if ( emHolder == null ) {
                    this.appScopedEntityManager = this.emf.createEntityManager();
                    emHolder = new EntityManagerHolder( this.appScopedEntityManager );
                    TransactionSynchronizationManager.bindResource( this.emf,
                                                                    emHolder );
                    internalAppScopedEntityManager = true;
                } else {
                    this.appScopedEntityManager = emHolder.getEntityManager();
                }

                this.env.set( EnvironmentName.APP_SCOPED_ENTITY_MANAGER,
                              emHolder.getEntityManager() );
            }
        }
        if ( TransactionSynchronizationManager.isActualTransactionActive() ) {
            this.appScopedEntityManager.joinTransaction();
        }
View Full Code Here


    }

    public void beginCommandScopedEntityManager() {
        EntityManager cmdScopedEntityManager = (EntityManager) env.get( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER );
        if ( cmdScopedEntityManager == null || !cmdScopedEntityManager.isOpen() ) {
            EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource( "cmdEM" );
            EntityManager em = null;
            if ( emHolder == null ) {
                em = this.emf.createEntityManager();
                emHolder = new EntityManagerHolder( em );
                TransactionSynchronizationManager.bindResource( "cmdEM",
                                                                emHolder );
            } else {
                em = emHolder.getEntityManager();
            }
            this.env.set( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER,
                          em );
        }
View Full Code Here

    }
    else {
      logger.debug("Opening JPA EntityManager in OpenEntityManagerInViewInterceptor");
      try {
        EntityManager em = createEntityManager();
        TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), new EntityManagerHolder(em));
      }
      catch (PersistenceException ex) {
        throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex);
      }
    }
View Full Code Here

      else {
        request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
      }
    }
    else {
      EntityManagerHolder emHolder = (EntityManagerHolder)
          TransactionSynchronizationManager.unbindResource(getEntityManagerFactory());
      logger.debug("Closing JPA EntityManager in OpenEntityManagerInViewInterceptor");
      EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager());
    }
  }
View Full Code Here

    assertNotNull(transactionalField.em);
    // the EM w/ properties will be created
    assertNotNull(transactionalFieldWithProperties.em.getDelegate());
    // bind em to the thread now since it's created
    try {
      TransactionSynchronizationManager.bindResource(mockEmf, new EntityManagerHolder(em));
      assertNotNull(transactionalField.em.getDelegate());
      emfMc.verify();
      emC.verify();
    }
    finally {
View Full Code Here

    assertNotNull(transactionalField.em);
    // the EM w/o properties will be created
    assertNotNull(transactionalField.em.getDelegate());
    // bind em to the thread now since it's created
    try {
      TransactionSynchronizationManager.bindResource(mockEmf, new EntityManagerHolder(em));
      assertNotNull(transactionalFieldWithProperties.em.getDelegate());
      emfMc.verify();
      emC.verify();
    }
    finally {
View Full Code Here

    }
    catch (IllegalStateException ex) {
      // expected
    }

    TransactionSynchronizationManager.bindResource(mockEmf, new EntityManagerHolder(mockEm));
    try {
      assertSame(mockEm, emProxy.getTargetEntityManager());
    }
    finally {
      TransactionSynchronizationManager.unbindResource(mockEmf);
View Full Code Here

        if (!TransactionSynchronizationManager.hasResource(getEntityManagerFactory())) {
            logger.debug("Opening JPA EntityManager in OpenEntityManagerInTest");
            try {
                EntityManager em = createEntityManager();
                TransactionSynchronizationManager.bindResource(
                        getEntityManagerFactory(), new EntityManagerHolder(em));
            }
            catch (PersistenceException ex) {
                throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex);
            }
        }
View Full Code Here

            }
        }
    }
   
    public void unloadEntityManager() {
        EntityManagerHolder emHolder = (EntityManagerHolder)
        TransactionSynchronizationManager.unbindResource(getEntityManagerFactory());
        logger.debug("Closing JPA EntityManager in OpenEntityManagerInTest");
        emHolder.getEntityManager().close();
    }
View Full Code Here

            participate = true;
        }
        else {
            try {
                EntityManager em = emf.createEntityManager();
                TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em));
            }
            catch (PersistenceException ex) {
                throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex);
            }
        }

        try {
            runnable.run();
        }
        finally {
            if (!participate) {
                EntityManagerHolder emHolder = (EntityManagerHolder)
                        TransactionSynchronizationManager.unbindResource(emf);
                closeEntityManager(emHolder.getEntityManager());
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.springframework.orm.jpa.EntityManagerHolder

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.