本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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());
}