Package org.springframework.orm.jpa

Examples of org.springframework.orm.jpa.EntityManagerHolder


      // pushing onto a stack...
      public void bind()
      {
        synchronized(bindings)
        {
          EntityManagerHolder current = (EntityManagerHolder)
            TransactionSynchronizationManager.getResource(entityManagerFactory);

          if (current != null)
          {
            TransactionSynchronizationManager.unbindResource(entityManagerFactory);
          }

          bindings.push(current);

          TransactionSynchronizationManager.bindResource(entityManagerFactory,
            new EntityManagerHolder(em));
        }
      }

      public void unbind()
      {
View Full Code Here


      boolean isFirstRequest = !isAsyncDispatch(request);
      if (isFirstRequest || !applyEntityManagerBindingInterceptor(asyncManager, key)) {
        logger.debug("Opening JPA EntityManager in OpenEntityManagerInViewFilter");
        try {
          EntityManager em = createEntityManager(emf);
          EntityManagerHolder emHolder = new EntityManagerHolder(em);
          TransactionSynchronizationManager.bindResource(emf, emHolder);

          AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(emf, emHolder);
          asyncManager.registerCallableInterceptor(key, interceptor);
          asyncManager.registerDeferredResultInterceptor(key, interceptor);
        }
        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);
        if (!isAsyncStarted(request)) {
          logger.debug("Closing JPA EntityManager in OpenEntityManagerInViewFilter");
          EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager());
        }
      }
    }
  }
View Full Code Here

    }
    else {
      logger.debug("Opening JPA EntityManager in OpenEntityManagerInViewInterceptor");
      try {
        EntityManager em = createEntityManager();
        EntityManagerHolder emHolder = new EntityManagerHolder(em);
        TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), emHolder);

        AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(getEntityManagerFactory(), emHolder);
        asyncManager.registerCallableInterceptor(participateAttributeName, interceptor);
        asyncManager.registerDeferredResultInterceptor(participateAttributeName, interceptor);
View Full Code Here

  }

  @Override
  public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
    if (!decrementParticipateCount(request)) {
      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());
      verify(em).close();
    }
    finally {
      TransactionSynchronizationManager.unbindResource(mockEmf);
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());
      verify(em).close();
    }
    finally {
      TransactionSynchronizationManager.unbindResource(mockEmf);
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

        boolean isNewEm = false;
        if (em == null) {
            logger.debug("Creating new EntityManager for JpaInterceptor invocation");
            em = createEntityManager();
            isNewEm = true;
            TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), new EntityManagerHolder(em));
           
            //For new EM store as attribute so it can be closed
            context.setExecutionAttribute(ENTITY_MANAGER_FACTORY, em);
        }
       
View Full Code Here

        boolean isNewEm = false;
        if (em == null) {
            logger.debug("Opening JPA EntityManager in OpenEntityManagerAspect");
            em = createEntityManager(emf);
            isNewEm = true;
            TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em));
        }
        else {
            logger.debug("Using Existing JPA EntityManager in OpenEntityManagerAspect");
        }
    try {
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

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.