当前位置: 首页>>代码示例>>Java>>正文


Java EntityManagerFactoryUtils.doGetTransactionalEntityManager方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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


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