Spring Framework EntityManagerHolder - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework EntityManagerHolder class.

This code example shows how to use the following methods:
		} 
		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); 
			} 
			catch (PersistenceException ex) { 
				throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex); 
			} 
		} 
	} 
 
	@Override 
	public void postHandle(WebRequest request, ModelMap model) { 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		EntityManager em = mock(EntityManager.class,"em"); 
		em.contains("foo"); 
		em.contains("bar"); 
		em.merge("bar"); 
		em.flush(); 
		TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em)); 
 
		List<String> items = Arrays.asList(new String[] { "foo", "bar" }); 
 
		writer.write(items); 
 
		TransactionSynchronizationManager.unbindResource(emf); 
	} 
 
	@Test 
	public void testWriteAndFlushWithFailure() throws Exception { 
		final RuntimeException ex = new RuntimeException("ERROR"); 
		EntityManager em = mock(EntityManager.class,"em"); 
		em.contains("foo"); 
		em.contains("bar"); 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getEntityManager
	} 
 
	private void closeAfterTimeout() { 
		if (this.timeoutInProgress) { 
			logger.debug("Closing JPA EntityManager after async request timeout"); 
			EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager()); 
		} 
	} 
 
 
	// Implementation of DeferredResultProcessingInterceptor methods 
 
	public <T> void beforeConcurrentHandling(NativeWebRequest request, DeferredResult<T> deferredResult) { 
	} 
 
	public <T> void preProcess(NativeWebRequest request, DeferredResult<T> deferredResult) { 
	} 
 
	public <T> void postProcess(NativeWebRequest request, DeferredResult<T> deferredResult, Object result) { 
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        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); 
        } 
         
        context.setExecutionAttribute(IS_NEW, isNewEm); 
    } 
 
    @Override 
    public void postExecution(HttpServletRequest request, HttpServletResponse response, IPortletExecutionContext context, Exception e) { 
        boolean isNewEm = (Boolean)context.getExecutionAttribute(IS_NEW); 
        if (isNewEm) { 
            TransactionSynchronizationManager.unbindResource(getEntityManagerFactory()); 
            EntityManager em = (EntityManager)context.getExecutionAttribute(ENTITY_MANAGER_FACTORY); 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        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 { 
			return pjp.proceed(); 
		} 
		finally { 
            if (isNewEm) { 
                logger.debug("Closing JPA EntityManager in OpenEntityManagerAspect"); 
                TransactionSynchronizationManager.unbindResource(emf); 
                EntityManagerFactoryUtils.closeEntityManager(em); 
            } 
		} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getEntityManager
     */ 
    public static EntityManager resolveEntityManager(EntityManagerFactory entityManagerFactory) { 
        EntityManagerHolder entityManagerHolder = 
                (EntityManagerHolder) TransactionSynchronizationManager.getResource(entityManagerFactory); 
        if (entityManagerHolder != null) { 
            return entityManagerHolder.getEntityManager(); 
        } 
        return entityManagerFactory.createEntityManager(); 
    } 
 
    public static void closeNonTransactionalEntityManager(EntityManager entityManager) { 
        if (entityManager == null) { 
            return; 
        } 
        boolean isTransactional = TransactionSynchronizationManager.hasResource(entityManager.getEntityManagerFactory()); 
        if (isTransactional) { 
            entityManager.close(); 
        } 
    } 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getEntityManager
		} 
	} 
	 
	public boolean registerSynchronization(Object resource, boolean shouldRemoveContextAtEnd) { 
		EntityManagerHolder entityManagerHolder = (EntityManagerHolder)resource; 
		Object delegate = entityManagerHolder.getEntityManager().getDelegate(); 
		if (syncsMap.containsKey(delegate.getClass().getName())) 
			return syncsMap.get(delegate.getClass().getName()).registerSynchronization(delegate, shouldRemoveContextAtEnd); 
		 
		return false; 
	} 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	public EntityManager openEntityManager() { 
		if (TransactionSynchronizationManager.hasResource(entityManagerFactory)) { 
			return ((EntityManagerHolder) TransactionSynchronizationManager.getResource(entityManagerFactory)).getEntityManager(); 
		} else { 
			EntityManager entityManager = entityManagerFactory.createEntityManager(); 
			TransactionSynchronizationManager.bindResource(entityManagerFactory, new EntityManagerHolder(entityManager)); 
			return entityManager; 
		} 
	} 
	 
	/** 
	 * Suppression du EntityManager. 
	 */ 
	public void closeEntityManager() { 
		if (TransactionSynchronizationManager.hasResource(entityManagerFactory)) { 
			EntityManagerHolder entityManagerHolder = (EntityManagerHolder) TransactionSynchronizationManager.unbindResource(entityManagerFactory); 
			EntityManagerFactoryUtils.closeEntityManager(entityManagerHolder.getEntityManager()); 
		} 
	} 
	 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
            try 
            { 
                // If we are not part of another transaction, create the EntityManager and bind it 
                // to the TransactionSynchronizationManager 
                EntityManager em = createEntityManager(); 
                TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), 
                    new EntityManagerHolder(em)); 
            } 
            catch (PersistenceException ex) 
            { 
                throw new DataAccessResourceFailureException("Could not create JPA EntityManager", 
                    ex); 
            } 
        } 
 
        Object ret = null; 
 
        try 
        { 
            ret = invocation.proceed(); 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
            } 
        } 
        else 
        { 
            em = createEntityManager(emf); 
            TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em)); 
        } 
 
        return em; 
    } 
 
    protected void commitActiveTransaction(final EntityManager em) 
    { 
        if (em.getTransaction().isActive()) 
        { 
            em.getTransaction().commit(); 
        } 
    } 
 
    protected void rollbackActiveTransaction(final EntityManager em) 
4
CodeRank
Experience pair programming with AI  Get Codota for Java