下面列出了怎么用org.springframework.orm.jpa.SharedEntityManagerCreator的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public final void afterPropertiesSet() {
EntityManagerFactory emf = getEntityManagerFactory();
if (emf == null) {
throw new IllegalArgumentException("'entityManagerFactory' or 'persistenceUnitName' is required");
}
if (emf instanceof EntityManagerFactoryInfo) {
EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf;
if (this.entityManagerInterface == null) {
this.entityManagerInterface = emfInfo.getEntityManagerInterface();
if (this.entityManagerInterface == null) {
this.entityManagerInterface = EntityManager.class;
}
}
}
else {
if (this.entityManagerInterface == null) {
this.entityManagerInterface = EntityManager.class;
}
}
this.shared = SharedEntityManagerCreator.createSharedEntityManager(
emf, getJpaPropertyMap(), this.synchronizedWithTransaction, this.entityManagerInterface);
}
@Override
public final void afterPropertiesSet() {
EntityManagerFactory emf = getEntityManagerFactory();
if (emf == null) {
throw new IllegalArgumentException("'entityManagerFactory' or 'persistenceUnitName' is required");
}
if (emf instanceof EntityManagerFactoryInfo) {
EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf;
if (this.entityManagerInterface == null) {
this.entityManagerInterface = emfInfo.getEntityManagerInterface();
if (this.entityManagerInterface == null) {
this.entityManagerInterface = EntityManager.class;
}
}
}
else {
if (this.entityManagerInterface == null) {
this.entityManagerInterface = EntityManager.class;
}
}
this.shared = SharedEntityManagerCreator.createSharedEntityManager(
emf, getJpaPropertyMap(), this.synchronizedWithTransaction, this.entityManagerInterface);
}
@Override
public final void afterPropertiesSet() {
EntityManagerFactory emf = getEntityManagerFactory();
if (emf == null) {
throw new IllegalArgumentException("'entityManagerFactory' or 'persistenceUnitName' is required");
}
if (emf instanceof EntityManagerFactoryInfo) {
EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf;
if (this.entityManagerInterface == null) {
this.entityManagerInterface = emfInfo.getEntityManagerInterface();
if (this.entityManagerInterface == null) {
this.entityManagerInterface = EntityManager.class;
}
}
}
else {
if (this.entityManagerInterface == null) {
this.entityManagerInterface = EntityManager.class;
}
}
this.shared = SharedEntityManagerCreator.createSharedEntityManager(
emf, getJpaPropertyMap(), this.synchronizedWithTransaction, this.entityManagerInterface);
}
@Override
public final void afterPropertiesSet() {
EntityManagerFactory emf = getEntityManagerFactory();
if (emf == null) {
throw new IllegalArgumentException("'entityManagerFactory' or 'persistenceUnitName' is required");
}
if (emf instanceof EntityManagerFactoryInfo) {
EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf;
if (this.entityManagerInterface == null) {
this.entityManagerInterface = emfInfo.getEntityManagerInterface();
if (this.entityManagerInterface == null) {
this.entityManagerInterface = EntityManager.class;
}
}
}
else {
if (this.entityManagerInterface == null) {
this.entityManagerInterface = EntityManager.class;
}
}
this.shared = SharedEntityManagerCreator.createSharedEntityManager(
emf, getJpaPropertyMap(), this.synchronizedWithTransaction, this.entityManagerInterface);
}
private EntityManager resolveEntityManager(@Nullable String requestingBeanName) {
// Obtain EntityManager reference from JNDI?
EntityManager em = getPersistenceContext(this.unitName, false);
if (em == null) {
// No pre-built EntityManager found -> build one based on factory.
// Obtain EntityManagerFactory from JNDI?
EntityManagerFactory emf = getPersistenceUnit(this.unitName);
if (emf == null) {
// Need to search for EntityManagerFactory beans.
emf = findEntityManagerFactory(this.unitName, requestingBeanName);
}
// Inject a shared transactional EntityManager proxy.
if (emf instanceof EntityManagerFactoryInfo &&
((EntityManagerFactoryInfo) emf).getEntityManagerInterface() != null) {
// Create EntityManager based on the info's vendor-specific type
// (which might be more specific than the field's type).
em = SharedEntityManagerCreator.createSharedEntityManager(
emf, this.properties, this.synchronizedWithTransaction);
}
else {
// Create EntityManager based on the field's type.
em = SharedEntityManagerCreator.createSharedEntityManager(
emf, this.properties, this.synchronizedWithTransaction, getResourceType());
}
}
return em;
}
private EntityManager resolveEntityManager(@Nullable String requestingBeanName) {
// Obtain EntityManager reference from JNDI?
EntityManager em = getPersistenceContext(this.unitName, false);
if (em == null) {
// No pre-built EntityManager found -> build one based on factory.
// Obtain EntityManagerFactory from JNDI?
EntityManagerFactory emf = getPersistenceUnit(this.unitName);
if (emf == null) {
// Need to search for EntityManagerFactory beans.
emf = findEntityManagerFactory(this.unitName, requestingBeanName);
}
// Inject a shared transactional EntityManager proxy.
if (emf instanceof EntityManagerFactoryInfo &&
((EntityManagerFactoryInfo) emf).getEntityManagerInterface() != null) {
// Create EntityManager based on the info's vendor-specific type
// (which might be more specific than the field's type).
em = SharedEntityManagerCreator.createSharedEntityManager(
emf, this.properties, this.synchronizedWithTransaction);
}
else {
// Create EntityManager based on the field's type.
em = SharedEntityManagerCreator.createSharedEntityManager(
emf, this.properties, this.synchronizedWithTransaction, getResourceType());
}
}
return em;
}
private LockingStrategy newLockTxProxy(final String appId, final String uniqueId, final int ttl) {
final JpaLockingStrategy lock = new JpaLockingStrategy();
lock.entityManager = SharedEntityManagerCreator.createSharedEntityManager(factory);
lock.setApplicationId(appId);
lock.setUniqueId(uniqueId);
lock.setLockTimeout(ttl);
return (LockingStrategy) Proxy.newProxyInstance(
JpaLockingStrategy.class.getClassLoader(),
new Class[] {LockingStrategy.class},
new TransactionalLockInvocationHandler(lock, this.txManager));
}
private LockingStrategy newLockTxProxy(final String appId, final String uniqueId, final int ttl) {
final JpaLockingStrategy lock = new JpaLockingStrategy();
lock.entityManager = SharedEntityManagerCreator.createSharedEntityManager(factory);
lock.setApplicationId(appId);
lock.setUniqueId(uniqueId);
lock.setLockTimeout(ttl);
return (LockingStrategy) Proxy.newProxyInstance(
JpaLockingStrategy.class.getClassLoader(),
new Class[] {LockingStrategy.class},
new TransactionalLockInvocationHandler(lock));
}
private EntityManager resolveEntityManager(String requestingBeanName) {
// Obtain EntityManager reference from JNDI?
EntityManager em = getPersistenceContext(this.unitName, false);
if (em == null) {
// No pre-built EntityManager found -> build one based on factory.
// Obtain EntityManagerFactory from JNDI?
EntityManagerFactory emf = getPersistenceUnit(this.unitName);
if (emf == null) {
// Need to search for EntityManagerFactory beans.
emf = findEntityManagerFactory(this.unitName, requestingBeanName);
}
// Inject a shared transactional EntityManager proxy.
if (emf instanceof EntityManagerFactoryInfo &&
((EntityManagerFactoryInfo) emf).getEntityManagerInterface() != null) {
// Create EntityManager based on the info's vendor-specific type
// (which might be more specific than the field's type).
em = SharedEntityManagerCreator.createSharedEntityManager(
emf, this.properties, this.synchronizedWithTransaction);
}
else {
// Create EntityManager based on the field's type.
em = SharedEntityManagerCreator.createSharedEntityManager(
emf, this.properties, this.synchronizedWithTransaction, getResourceType());
}
}
return em;
}
private EntityManager resolveEntityManager(String requestingBeanName) {
// Obtain EntityManager reference from JNDI?
EntityManager em = getPersistenceContext(this.unitName, false);
if (em == null) {
// No pre-built EntityManager found -> build one based on factory.
// Obtain EntityManagerFactory from JNDI?
EntityManagerFactory emf = getPersistenceUnit(this.unitName);
if (emf == null) {
// Need to search for EntityManagerFactory beans.
emf = findEntityManagerFactory(this.unitName, requestingBeanName);
}
// Inject a shared transactional EntityManager proxy.
if (emf instanceof EntityManagerFactoryInfo &&
((EntityManagerFactoryInfo) emf).getEntityManagerInterface() != null) {
// Create EntityManager based on the info's vendor-specific type
// (which might be more specific than the field's type).
em = SharedEntityManagerCreator.createSharedEntityManager(
emf, this.properties, this.synchronizedWithTransaction);
}
else {
// Create EntityManager based on the field's type.
em = SharedEntityManagerCreator.createSharedEntityManager(
emf, this.properties, this.synchronizedWithTransaction, getResourceType());
}
}
return em;
}
public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
this.sharedEntityManager = SharedEntityManagerCreator.createSharedEntityManager(this.entityManagerFactory);
}
public void testCanGetSharedOpenJpaEntityManagerProxy() {
OpenJPAEntityManager openJPAEntityManager = (OpenJPAEntityManager) SharedEntityManagerCreator.createSharedEntityManager(
entityManagerFactory, null, OpenJPAEntityManager.class);
assertNotNull(openJPAEntityManager.getDelegate());
}
public FileConversionQueueItemRepositoryImpl(EntityManagerFactory entityManagerFactory) {
this(SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory));
}
public FileConversionQueueItemRepositoryImpl(EntityManagerFactory entityManagerFactory) {
this(SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory));
}
public static void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
entityManager = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
}