List of usage examples for org.springframework.orm.jpa EntityManagerHolder EntityManagerHolder
public EntityManagerHolder(@Nullable EntityManager entityManager)
From source file:com.brienwheeler.lib.db.DbTestUtils.java
public static <T> T doInHibernateSession(ApplicationContext applicationContext, Callable<T> work) { EntityManagerFactory entityManagerFactory = applicationContext .getBean("com.brienwheeler.lib.db.appEntityManagerFactory", EntityManagerFactory.class); EntityManagerHolder entityManagerHolder = (EntityManagerHolder) TransactionSynchronizationManager .getResource(entityManagerFactory); boolean created = entityManagerHolder == null; if (created) { entityManagerHolder = new EntityManagerHolder(entityManagerFactory.createEntityManager()); TransactionSynchronizationManager.bindResource(entityManagerFactory, entityManagerHolder); }//from w w w. ja va 2 s. c o m try { return work.call(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (created) TransactionSynchronizationManager.unbindResource(entityManagerFactory); } }
From source file:com.healthcit.cacure.businessdelegates.export.DataExportTest.java
@Before public void setUp() { EntityManager em = emf.createEntityManager(); TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em)); }
From source file:com.healthcit.cacure.model.GetAllForms.java
@Before public void setUp() { // EntityManagerFactory emf = (EntityManagerFactory)context.getBean("entityManagerFactory"); EntityManager em = emf.createEntityManager(); TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em)); }
From source file:com.healthcit.cacure.businessdelegates.export.DataImporterTest.java
@Before public void setUp() { EntityManager em = emf.createEntityManager(); TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em)); login("lkagan", "koala"); }
From source file:corner.orm.gae.impl.EntityManagerSourceImpl.java
public EntityManagerSourceImpl(@Inject @Symbol(SymbolConstants.PRODUCTION_MODE) boolean product, EntityManagerFactory entityManagerFactory, Logger logger, Delegate delegate) { this.entityManagerFactory = entityManagerFactory; this.logger = logger; if (!product) { ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment()); ApiProxy.setDelegate(delegate);// ww w . jav a 2 s . co m } if (TransactionSynchronizationManager.hasResource(entityManagerFactory)) { // Do not modify the Session: just set the participate flag. participate = true; } else { logger.debug("Opening single entity manager in EntityManagerSourceImpl"); EntityManager em = entityManagerFactory.createEntityManager(); TransactionSynchronizationManager.bindResource(entityManagerFactory, new EntityManagerHolder(em)); } }
From source file:com.healthcit.cacure.dao.QuestionDaoTest.java
@Before public void setUp() { // EntityManagerFactory emf = (EntityManagerFactory)context.getBean("entityManagerFactory"); EntityManager em = emf.createEntityManager(); TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em)); }
From source file:hsa.awp.common.util.OpenEntityManagerTimerTaskFactory.java
/** * Opens an {@link EntityManager} per execution. *//*from w ww .j a v a 2 s . c o m*/ private void openEntityManager() { log.debug("Opening EntityManager"); em = emf.createEntityManager(); log.trace("Binding EntityManager to thread '{}'", Thread.currentThread().getName()); TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em)); }
From source file:org.drools.container.spring.beans.persistence.DroolsSpringJpaManager.java
public PersistenceContext getApplicationScopedPersistenceContext() { if (this.appScopedEntityManager == null) { // Use the App scoped EntityManager if the user has provided it, and it is open. this.appScopedEntityManager = (EntityManager) this.env.get(EnvironmentName.APP_SCOPED_ENTITY_MANAGER); if (this.appScopedEntityManager != null && !this.appScopedEntityManager.isOpen()) { throw new RuntimeException("Provided APP_SCOPED_ENTITY_MANAGER is not open"); }//from w w w . jav a2 s . co m 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(); } return new JpaPersistenceContext(this.appScopedEntityManager); }
From source file:org.jasig.jpa.OpenEntityManagerAspect.java
@Around("anyPublicMethod() && @annotation(openEntityManager)") public Object openEntityManager(ProceedingJoinPoint pjp, OpenEntityManager openEntityManager) throws Throwable { final EntityManagerFactory emf = getEntityManagerFactory(openEntityManager); EntityManager em = getTransactionalEntityManager(emf); boolean isNewEm = false; if (em == null) { logger.debug("Opening JPA EntityManager in OpenEntityManagerAspect"); em = createEntityManager(emf);/*from ww w .j av a2 s . c o m*/ isNewEm = true; TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em)); } else { logger.debug("Using Existing JPA EntityManager in OpenEntityManagerAspect"); } try { return pjp.proceed(); } finally { if (isNewEm) { logger.debug("Closing JPA EntityManager in OpenEntityManagerAspect"); TransactionSynchronizationManager.unbindResource(emf); EntityManagerFactoryUtils.closeEntityManager(em); } } }
From source file:hsa.awp.common.test.OpenEntityManagerInTest.java
/** * Opens an {@link EntityManager} per test. *///w w w.j a v a 2s .c o m @Before public final void openEntityManager() { create = !TransactionSynchronizationManager.hasResource(emf); if (create) { log.debug("Opening EntityManager"); em = emf.createEntityManager(); log.trace("Binding EntityManager to thread '{}'", Thread.currentThread().getName()); TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em)); } else { log.debug("Don't open EntityManager because of @Transactional annotation"); } }