Package org.springframework.orm.jpa

Examples of org.springframework.orm.jpa.EntityManagerHolder


   
    });
  }

  private EntityManager getTransactionEntityManager() {
    EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager
        .getResource(getJpaTemplate().getEntityManagerFactory());
    return emHolder.getEntityManager();
  }
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

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

    try {
      filterChain.doFilter(request, response);
    }

    finally {
      if (!participate) {
        EntityManagerHolder emHolder = (EntityManagerHolder)
            TransactionSynchronizationManager.unbindResource(emf);
        logger.debug("Closing JPA EntityManager in OpenEntityManagerInViewFilter");
        EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager());
      }
    }
  }
View Full Code Here

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

    try {
      filterChain.doFilter(request, response);
    }

    finally {
      if (!participate) {
        EntityManagerHolder emHolder = (EntityManagerHolder)
            TransactionSynchronizationManager.unbindResource(emf);
        logger.debug("Closing JPA EntityManager in OpenEntityManagerInViewFilter");
        emHolder.getEntityManager().close();
      }
    }
  }
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");
      emHolder.getEntityManager().close();
    }
  }
View Full Code Here

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

    try {
      filterChain.doFilter(request, response);
    }

    finally {
      if (!participate) {
        EntityManagerHolder emHolder = (EntityManagerHolder)
            TransactionSynchronizationManager.unbindResource(emf);
        logger.debug("Closing JPA EntityManager in OpenEntityManagerInViewFilter");
        EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager());
      }
    }
  }
View Full Code Here

  private EntityManager getEntityManager(FlowSession session) {
    return (EntityManager) session.getScope().get(PERSISTENCE_CONTEXT_ATTRIBUTE);
  }

  private void bind(EntityManager em) {
    TransactionSynchronizationManager.bindResource(entityManagerFactory, new EntityManagerHolder(em));
  }
View Full Code Here

            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() && isJTA) {
            this.appScopedEntityManager.joinTransaction();
        }
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.