• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java EntityManagerFactoryUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.orm.jpa.EntityManagerFactoryUtils的典型用法代码示例。如果您正苦于以下问题:Java EntityManagerFactoryUtils类的具体用法?Java EntityManagerFactoryUtils怎么用?Java EntityManagerFactoryUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



EntityManagerFactoryUtils类属于org.springframework.orm.jpa包,在下文中一共展示了EntityManagerFactoryUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: lookupEntityManagerFactory

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
/**
 * Look up the EntityManagerFactory that this filter should use.
 * <p>The default implementation looks for a bean with the specified name
 * in Spring's root application context.
 * @return the EntityManagerFactory to use
 * @see #getEntityManagerFactoryBeanName
 */
protected EntityManagerFactory lookupEntityManagerFactory() {
	WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
	String emfBeanName = getEntityManagerFactoryBeanName();
	String puName = getPersistenceUnitName();
	if (StringUtils.hasLength(emfBeanName)) {
		return wac.getBean(emfBeanName, EntityManagerFactory.class);
	}
	else if (!StringUtils.hasLength(puName) && wac.containsBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME)) {
		return wac.getBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME, EntityManagerFactory.class);
	}
	else {
		// Includes fallback search for single EntityManagerFactory bean by type.
		return EntityManagerFactoryUtils.findEntityManagerFactory(wac, puName);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:OpenEntityManagerInViewFilter.java


示例2: beforeCommit

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
@Override
public void beforeCommit()
{
    if (flush)
    {
        EntityManagerFactoryUtils.getTransactionalEntityManager(emf).flush();
    }
    
	final MutableEntityDataChangeSet cs = preChangeset.get();
	
	if (! cs.isEmpty())
	{
   		lazySetId(cs);
   		
   		for (EntityChangeSetListener listener : entityChangeSetListeners)
   		{
   		    listener.preDataChanged(MutableEntityDataChangeSet.clone(cs));
   		}
	}
	
	preChangeset.remove();
}
 
开发者ID:ethlo,项目名称:dachs,代码行数:23,代码来源:DefaultInternalEntityListener.java


示例3: extractIdPropertyNames

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
@Override
public String[] extractIdPropertyNames(Object entity)
{
    final EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
    final ClassDescriptor desc = em.unwrap(JpaEntityManager.class).getServerSession().getClassDescriptor(entity);
    if (desc != null)
    {
   	    final Collection<DatabaseMapping> fieldNames = desc.getMappings();
   	    final List<DatabaseMapping> tmp = new LinkedList<>();
   	    for (DatabaseMapping m : fieldNames)
   	    {
   	        if (m.isPrimaryKeyMapping())
   	        {
   	            tmp.add(m);
   	        }
   	    }
   	    final String[] retVal = new String[tmp.size()];
   	    for (int i = 0; i < retVal.length; i++)
   	    {
   	        retVal[i] = tmp.get(i).getAttributeName();
   	    }
   	    return retVal;
    }
    
    return null;
}
 
开发者ID:ethlo,项目名称:dachs,代码行数:27,代码来源:EclipselinkLazyIdExtractor.java


示例4: getEntityManager

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
/**
 * 获得EntityManager
 * 
 * @return
 */
protected final EntityManager getEntityManager() {
    TransactionMode tx = jefEmf.getDefault().getTxType();
    EntityManager em;
    switch (tx) {
    case JPA:
    case JTA:
        em = EntityManagerFactoryUtils.doGetTransactionalEntityManager(entityManagerFactory, null);
        if (em == null) { // 当无事务时。Spring返回null
            em = entityManagerFactory.createEntityManager(null, Collections.EMPTY_MAP);
        }
        break;
    case JDBC:
        ConnectionHolder conn = (ConnectionHolder) TransactionSynchronizationManager.getResource(jefEmf.getDefault().getDataSource());
        if (conn == null) {// 基于数据源的Spring事务
            em = entityManagerFactory.createEntityManager(null, Collections.EMPTY_MAP);
        } else {
            ManagedTransactionImpl session = new ManagedTransactionImpl(jefEmf.getDefault(), conn.getConnection());
            em = new JefEntityManager(entityManagerFactory, null, session);
        }
        break;
    default:
        throw new UnsupportedOperationException(tx.name());
    }
    return em;
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:31,代码来源:BaseDao.java


示例5: getEntityManager

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
/**
 * 获得EntityManager
 * 
 * @return
 */
public static final EntityManager getEntityManager(JefEntityManagerFactory jefEmf) {
    TransactionMode tx = jefEmf.getDefault().getTxType();
    EntityManager em;
    switch (tx) {
    case JPA:
    case JTA:
        em = EntityManagerFactoryUtils.doGetTransactionalEntityManager(jefEmf, null);
        if (em == null) { // 当无事务时。Spring返回null
            em = jefEmf.createEntityManager(null, Collections.EMPTY_MAP);
        }
        break;
    case JDBC:
        ConnectionHolder conn = (ConnectionHolder) TransactionSynchronizationManager.getResource(jefEmf.getDefault().getDataSource());
        if (conn == null) {// 基于数据源的Spring事务
            em = jefEmf.createEntityManager(null, Collections.EMPTY_MAP);
        } else {
            ManagedTransactionImpl session = new ManagedTransactionImpl(jefEmf.getDefault(), conn.getConnection());
            em = new JefEntityManager(jefEmf, null, session);
        }
        break;
    default:
        throw new UnsupportedOperationException(tx.name());
    }
    return em;
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:31,代码来源:QueryUtils.java


示例6: getEntityManager

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
private EntityManager getEntityManager() {
    EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
    if (em == null) {
        return emf.createEntityManager();
    }
    return em;
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:8,代码来源:JpaDatasourceMapper.java


示例7: applyQueryImpl

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
protected void applyQueryImpl(Query query) {
    EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
    if (em == null) {
        entityManager = emf.createEntityManager();
        em = entityManager;
    }
    FullTextSession fullTextSession = Search.getFullTextSession(em.unwrap(Session.class));
    fullTextQuery = fullTextSession.createFullTextQuery(query, entityClass);
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:10,代码来源:JpaDatasourceMapper.java


示例8: afterCompletion

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
@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());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:OpenEntityManagerInViewInterceptor.java


示例9: findNamedEntityManagerFactory

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
/**
 * Find an EntityManagerFactory with the given name in the current
 * Spring application context.
 * @param unitName the name of the persistence unit (never empty)
 * @param requestingBeanName the name of the requesting bean
 * @return the EntityManagerFactory
 * @throws NoSuchBeanDefinitionException if there is no such EntityManagerFactory in the context
 */
protected EntityManagerFactory findNamedEntityManagerFactory(String unitName, String requestingBeanName)
		throws NoSuchBeanDefinitionException {

	EntityManagerFactory emf = EntityManagerFactoryUtils.findEntityManagerFactory(this.beanFactory, unitName);
	if (this.beanFactory instanceof ConfigurableBeanFactory) {
		((ConfigurableBeanFactory) this.beanFactory).registerDependentBean(unitName, requestingBeanName);
	}
	return emf;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:PersistenceAnnotationBeanPostProcessor.java


示例10: translateExceptionIfPossible

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
	if (ex instanceof HibernateException) {
		return convertHibernateAccessException((HibernateException) ex);
	}
	if (ex instanceof PersistenceException && ex.getCause() instanceof HibernateException) {
		return convertHibernateAccessException((HibernateException) ex.getCause());
	}
	return EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:HibernateJpaDialect.java


示例11: closeEntityManager

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
/**
 * close the entity manager.
 * Use it with caution! This is only intended for use with async request, which Spring won't
 * close the entity manager until the async request is finished.
 */
public void closeEntityManager() {
  EntityManagerHolder emHolder = (EntityManagerHolder)
      TransactionSynchronizationManager.getResource(getEntityManagerFactory());
  if (emHolder == null) {
    return;
  }
  logger.debug("Closing JPA EntityManager in EntityManagerUtil");
  EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager());
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:15,代码来源:EntityManagerUtil.java


示例12: getEntityManager

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
/**
 * Return the underlying {@link EntityManager} that's actually used to perform all
 * operations.
 * @return the entity manager
 */
public final EntityManager getEntityManager() {
	EntityManager manager = EntityManagerFactoryUtils
			.getTransactionalEntityManager(this.entityManagerFactory);
	Assert.state(manager != null, "No transactional EntityManager found");
	return manager;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:TestEntityManager.java


示例13: openSession

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
@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);
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:9,代码来源:SpringEntityManagerSessionFactory.java


示例14: openSession

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
@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);
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:9,代码来源:SpringEntityManagerSessionFactory.java


示例15: getEntityManager

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
@Override
public EntityManager getEntityManager(String store) {
    if (!TransactionSynchronizationManager.isActualTransactionActive())
        throw new IllegalStateException("No active transaction");

    EntityManagerFactory emf;
    if (Stores.isMain(store))
        emf = this.jpaEmf;
    else
        emf = AppBeans.get("entityManagerFactory_" + store);

    javax.persistence.EntityManager jpaEm = EntityManagerFactoryUtils.doGetTransactionalEntityManager(emf, null);

    if (!jpaEm.isJoinedToTransaction())
        throw new IllegalStateException("No active transaction for " + store + " database");

    EntityManager entityManager = createEntityManager(jpaEm);

    EntityManagerContext ctx = contextHolder.get(store);
    if (ctx != null) {
        entityManager.setSoftDeletion(ctx.isSoftDeletion());
    } else {
        ctx = new EntityManagerContext();
        ctx.setSoftDeletion(isSoftDeletion());
        contextHolder.set(ctx, store);
        entityManager.setSoftDeletion(isSoftDeletion());
    }

    EntityManager emProxy = (EntityManager) Proxy.newProxyInstance(
            getClass().getClassLoader(),
            new Class[]{EntityManager.class},
            new EntityManagerInvocationHandler(entityManager, store)
    );
    return emProxy;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:36,代码来源:PersistenceImpl.java


示例16: closeEntityManager

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
/**
 * Suppression du EntityManager.
 */
public void closeEntityManager() {
	if (TransactionSynchronizationManager.hasResource(entityManagerFactory)) {
		EntityManagerHolder entityManagerHolder = (EntityManagerHolder) TransactionSynchronizationManager.unbindResource(entityManagerFactory);
		EntityManagerFactoryUtils.closeEntityManager(entityManagerHolder.getEntityManager());
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:10,代码来源:EntityManagerUtils.java


示例17: openSession

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
public Session openSession() {
  EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
  if (entityManager == null) {
    return new EntityManagerSessionImpl(entityManagerFactory, handleTransactions, closeEntityManager);
  }
  return new EntityManagerSessionImpl(entityManagerFactory, entityManager, false, false);
}
 
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:8,代码来源:SpringEntityManagerSessionFactory.java


示例18: getSession

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
protected Session getSession() {
	EntityManager em = EntityManagerFactoryUtils.doGetTransactionalEntityManager(emf, null);
	if (em == null) { // 当无事务时。Spring返回null
		em = emf.createEntityManager(null, Collections.EMPTY_MAP);
	}
	if (em instanceof JefEntityManager) {
		return ((JefEntityManager) em).getSession();
	}
	throw new IllegalArgumentException(em.getClass().getName());
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:11,代码来源:AbstractGqQuery.java


示例19: afterCompletion

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
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());
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:9,代码来源:OpenEntityManagerInViewInterceptor.java


示例20: translateExceptionIfPossible

import org.springframework.orm.jpa.EntityManagerFactoryUtils; //导入依赖的package包/类
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
	if (ex instanceof HibernateException) {
		return SessionFactoryUtils.convertHibernateAccessException((HibernateException) ex);
	}
	if (ex instanceof PersistenceException && ex.getCause() instanceof HibernateException) {
		return SessionFactoryUtils.convertHibernateAccessException((HibernateException) ex.getCause());
	}
	return EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:11,代码来源:HibernateJpaDialect.java



注:本文中的org.springframework.orm.jpa.EntityManagerFactoryUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SidedInvWrapper类代码示例发布时间:2022-05-21
下一篇:
Java StreamUtil类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap