Java Code Examples for org.springframework.orm.jpa.EntityManagerFactoryUtils#getTransactionalEntityManager()

The following examples show how to use org.springframework.orm.jpa.EntityManagerFactoryUtils#getTransactionalEntityManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringEntityManagerSessionFactory.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Session openSession(CommandContext commandContext) {
  EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
  if (entityManager == null) {
    return new EntityManagerSessionImpl(entityManagerFactory, handleTransactions, closeEntityManager);
  }
  return new EntityManagerSessionImpl(entityManagerFactory, entityManager, false, false);
}
 
Example 2
Source File: SpringEntityManagerSessionFactory.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Session openSession() {
  EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
  if (entityManager == null) {
    return new EntityManagerSessionImpl(entityManagerFactory, handleTransactions, closeEntityManager);
  }
  return new EntityManagerSessionImpl(entityManagerFactory, entityManager, false, false);
}
 
Example 3
Source File: DatabaseResourceReleaser.java    From multitenant with Apache License 2.0 5 votes vote down vote up
@Override
public void release(Organization organization) {
	entityManagerFactoryService.removeEntityManagerFactory(organization);
	EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
	if (!EmbeddedDatabaseConnection.isEmbedded(properties.determineDriverClassName())) {
		em.createNativeQuery("drop database " + organization.getId()).executeUpdate();
	}
	
}
 
Example 4
Source File: SpringEntityManagerSessionFactory.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Session openSession() {
    EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
    if (entityManager == null) {
        return new EntityManagerSessionImpl(entityManagerFactory, handleTransactions, closeEntityManager);
    }
    return new EntityManagerSessionImpl(entityManagerFactory, entityManager, false, false);
}
 
Example 5
Source File: SpringEntityManagerSessionFactory.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Session openSession(CommandContext commandContext) {
    EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
    if (entityManager == null) {
        return new EntityManagerSessionImpl(entityManagerFactory, handleTransactions, closeEntityManager);
    }
    return new EntityManagerSessionImpl(entityManagerFactory, entityManager, false, false);
}
 
Example 6
Source File: JPAGenericDAO.java    From lutece-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Return the Entity Manager
 * 
 * @return The Entity Manager
 */
public EntityManager getEM( )
{
    EntityManagerFactory emf = getEntityManagerFactory( );

    if ( TransactionSynchronizationManager.isSynchronizationActive( ) )
    {
        // first, get Spring entitymanager (if available)
        try
        {
            EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager( emf );

            if ( em == null )
            {
                LOG.error( "getEM(  ) : no EntityManager found. Will use native entity manager factory [Transaction will not be supported]" );
            }
            else
            {
                LOG.debug( "EntityManager found for the current transaction : " + em.toString( ) + " - using Factory : " + emf.toString( ) );

                return em;
            }
        }
        catch( DataAccessResourceFailureException ex )
        {
            LOG.error( ex );
        }
    }

    LOG.error( "getEM(  ) : no EntityManager found. Will use native entity manager factory [Transaction will not be supported]" );

    if ( _defaultEM == null )
    {
        _defaultEM = emf.createEntityManager( );
    }
    return _defaultEM;
}
 
Example 7
Source File: SpringEntityManagerSessionFactory.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public Session openSession() {
  EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
  if (entityManager == null) {
    return new EntityManagerSessionImpl(entityManagerFactory, handleTransactions, closeEntityManager);
  }
  return new EntityManagerSessionImpl(entityManagerFactory, entityManager, false, false);
}
 
Example 8
Source File: JpaUtil.java    From linq with Apache License 2.0 2 votes vote down vote up
/**
 * 根据领域类(实体类),返回EmtityManager
 * @param domainClass 领域类(实体类)
 * @param <T> 领域类(实体类)范型
 * @return EntityManager
 */
public static <T> EntityManager getEntityManager(Class<T> domainClass) {
	EntityManagerFactory emf = getEntityManagerFactoryStrategy.getEntityManagerFactory(domainClass);
	return EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
}
 
Example 9
Source File: JpaUtil.java    From linq with Apache License 2.0 2 votes vote down vote up
/**
 * 实体管理器工厂在spring中的名称,返回EmtityManager
 * @param entityManagerFactoryName 实体管理器工厂在spring中的名称
 * @return EntityManager
 */
public static EntityManager getEntityManager(String entityManagerFactoryName) {
	EntityManagerFactory emf = getEntityManagerFactory(entityManagerFactoryName);
	return EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
}