public JtaEntityManager(final String unitName, final JtaEntityManagerRegistry registry, final EntityManagerFactory entityManagerFactory, final Map properties, final boolean extended, final String synchronizationType) { if (registry == null) { throw new NullPointerException("registry is null"); } if (entityManagerFactory == null) { throw new NullPointerException("entityManagerFactory is null"); } this.unitName = unitName; this.registry = registry; this.entityManagerFactory = entityManagerFactory; this.properties = properties; this.extended = extended; this.synchronizationType = !isJPA21(entityManagerFactory) || synchronizationType == null ? null : SynchronizationType.valueOf(synchronizationType.toUpperCase(Locale.ENGLISH)); final String globalTimerConfig = SystemInstance.get().getProperty("openejb.jpa.timer"); final Object localTimerConfig = properties == null ? null : properties.get("openejb.jpa.timer"); this.timer = localTimerConfig == null ? (globalTimerConfig == null || Boolean.parseBoolean(globalTimerConfig)) : Boolean.parseBoolean(localTimerConfig.toString()); logger = unitName == null ? baseLogger : baseLogger.getChildLogger(unitName); final String wrapConfig = ReloadableEntityManagerFactory.class.isInstance(entityManagerFactory) ? ReloadableEntityManagerFactory.class.cast(entityManagerFactory).getUnitProperties().getProperty("openejb.jpa.query.wrap-no-tx", "true") : "true"; this.wrapNoTxQueries = wrapConfig == null || "true".equalsIgnoreCase(wrapConfig); }
public DatabaseReadOnlyNetwork(EntityManager entityManager, boolean isShortTerm) { super(new EntityManagerImpl(entityManager.unwrap(ServerSession.class), SynchronizationType.UNSYNCHRONIZED), isShortTerm); ServerSession server = entityManager.unwrap(ServerSession.class); if (!server.getProperties().containsKey("network")) { server.setProperty("network", this); } }
public static boolean isJPA21(final EntityManagerFactory entityManagerFactory) { return ReloadableEntityManagerFactory.class.isInstance(entityManagerFactory) ? hasMethod( ReloadableEntityManagerFactory.class.cast(entityManagerFactory).getEntityManagerFactoryCallable().getProvider(), "generateSchema", String.class, Map.class) : hasMethod(entityManagerFactory.getClass(), "createEntityManager", SynchronizationType.class); }
@Override public EntityManager createEntityManager(final SynchronizationType synchronizationType) { EntityManager em; try { em = delegate().createEntityManager(synchronizationType); } catch (final LinkageError le) { em = delegate.createEntityManager(synchronizationType); } if (logCriteriaJpql) { return new QueryLogEntityManager(em, logCriteriaJpqlLevel); } return em; }
@Override public EntityManager createEntityManager(final SynchronizationType synchronizationType, final Map map) { EntityManager em; try { em = delegate().createEntityManager(synchronizationType, map); } catch (final LinkageError le) { em = delegate.createEntityManager(synchronizationType, map); } if (logCriteriaJpql) { return new QueryLogEntityManager(em, logCriteriaJpqlLevel); } return em; }
private Index<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker> createEntityManagers(final BeanContext beanContext) { // create the extended entity managers final Index<EntityManagerFactory, BeanContext.EntityManagerConfiguration> factories = beanContext.getExtendedEntityManagerFactories(); Index<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker> entityManagers = null; if (factories != null && factories.size() > 0) { entityManagers = new Index<>(new ArrayList<>(factories.keySet())); for (final Map.Entry<EntityManagerFactory, BeanContext.EntityManagerConfiguration> entry : factories.entrySet()) { final EntityManagerFactory entityManagerFactory = entry.getKey(); JtaEntityManagerRegistry.EntityManagerTracker entityManagerTracker = entityManagerRegistry.getInheritedEntityManager(entityManagerFactory); final EntityManager entityManager; if (entityManagerTracker == null) { final Map properties = entry.getValue().getProperties(); final SynchronizationType synchronizationType = entry.getValue().getSynchronizationType(); if (synchronizationType != null) { if (properties != null) { entityManager = entityManagerFactory.createEntityManager(synchronizationType, properties); } else { entityManager = entityManagerFactory.createEntityManager(synchronizationType); } } else if (properties != null) { entityManager = entityManagerFactory.createEntityManager(properties); } else { entityManager = entityManagerFactory.createEntityManager(); } entityManagerTracker = new JtaEntityManagerRegistry.EntityManagerTracker(entityManager, synchronizationType != SynchronizationType.UNSYNCHRONIZED); } else { entityManagerTracker.incCounter(); } entityManagers.put(entityManagerFactory, entityManagerTracker); } } return entityManagers; }
private Index<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker> createEntityManagers(final BeanContext beanContext) { // create the extended entity managers final Index<EntityManagerFactory, BeanContext.EntityManagerConfiguration> factories = beanContext.getExtendedEntityManagerFactories(); Index<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker> entityManagers = null; if (factories != null && factories.size() > 0) { entityManagers = new Index<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker>(new ArrayList<EntityManagerFactory>(factories.keySet())); for (final Map.Entry<EntityManagerFactory, BeanContext.EntityManagerConfiguration> entry : factories.entrySet()) { final EntityManagerFactory entityManagerFactory = entry.getKey(); JtaEntityManagerRegistry.EntityManagerTracker entityManagerTracker = entityManagerRegistry.getInheritedEntityManager(entityManagerFactory); final EntityManager entityManager; if (entityManagerTracker == null) { final SynchronizationType synchronizationType = entry.getValue().getSynchronizationType(); final Map properties = entry.getValue().getProperties(); if (synchronizationType != null) { if (properties != null) { entityManager = entityManagerFactory.createEntityManager(synchronizationType, properties); } else { entityManager = entityManagerFactory.createEntityManager(synchronizationType); } } else if (properties != null) { entityManager = entityManagerFactory.createEntityManager(properties); } else { entityManager = entityManagerFactory.createEntityManager(); } entityManagerTracker = new JtaEntityManagerRegistry.EntityManagerTracker(entityManager, synchronizationType != SynchronizationType.UNSYNCHRONIZED); } else { entityManagerTracker.incCounter(); } entityManagers.put(entityManagerFactory, entityManagerTracker); } } return entityManagers; }
private InjectionPoint persistenceContext(String unitName) { final InjectionPoint ip = mock(InjectionPoint.class); final Annotated annotated = mock(Annotated.class); when(ip.getAnnotated()).thenReturn(annotated); final PersistenceContext annotation = new PersistenceContext() { @Override public Class<? extends Annotation> annotationType() { return null; } @Override public String name() { return null; } @Override public String unitName() { return unitName; } @Override public PersistenceContextType type() { return null; } @Override public SynchronizationType synchronization() { return null; } @Override public PersistenceProperty[] properties() { return new PersistenceProperty[0]; } }; when(annotated.getAnnotation(PersistenceContext.class)).thenReturn(annotation); return ip; }
@Override public EntityManager createEntityManager(SynchronizationType arg0) { EntityManager em = nativeEntityManagerFactory.createEntityManager(arg0); log.debug("create new CibetEntityManager with native " + em); return new CibetEntityManager(this, em, loadEager); }
@Override public EntityManager createEntityManager(SynchronizationType arg0, Map arg1) { EntityManager em = nativeEntityManagerFactory.createEntityManager(arg0, arg1); log.debug("create new CibetEntityManager with native " + em); return new CibetEntityManager(this, em, loadEager); }
@Override public EntityManager createEntityManager(SynchronizationType synchronizationType) { return null; }
@Override public EntityManager createEntityManager(SynchronizationType synchronizationType, Map map) { return null; }
public EntityManager createEntityManager(SynchronizationType type, Map properties) { return delegate.createEntityManager(type, properties); }
public EntityManager createEntityManager(SynchronizationType type) { return delegate.createEntityManager(type); }
public SecureEntityManager createEntityManager(SynchronizationType synchronizationType, Map properties) { return createSecureEntityManager(super.createEntityManager(synchronizationType, properties), properties); }
public SecureEntityManager createEntityManager(SynchronizationType synchronizationType) { return createSecureEntityManager(super.createEntityManager(synchronizationType), Collections.<String, Object>emptyMap()); }
@Override public EntityManager createEntityManager(SynchronizationType arg0) { return null; }
@Override public EntityManager createEntityManager(SynchronizationType arg0, Map arg1) { return null; }
public EntityManager createEntityManager(SynchronizationType st) { throw new UnsupportedOperationException("Not supported."); }
public EntityManager createEntityManager(SynchronizationType st, Map map) { throw new UnsupportedOperationException("Not supported."); }
public PersistenceContextResourceFactory(String unitName, EntityManagerFactory emf, TransactionType transactionType, SynchronizationType sync) { this.unitName = unitName; this.emf = emf; this.sync = sync; this.transactionType = transactionType; }
public static EntityManager getEntityManager(SynchronizationType st) { return emf.createEntityManager(st); }
public EntityManagerImpl(EntityManagerFactoryImpl entityManagerFactory, PersistenceContextType pcType, SynchronizationType synchronizationType, PersistenceUnitTransactionType transactionType, boolean discardOnClose, Class sessionInterceptorClass, Map properties) { super(entityManagerFactory, pcType, synchronizationType, transactionType, discardOnClose, sessionInterceptorClass, properties); }
@SuppressWarnings("rawtypes") public EntityManager createEntityManager(Map map) { return createEntityManager(SynchronizationType.SYNCHRONIZED, map); }
@Override public EntityManager createEntityManager(SynchronizationType synchronizationType) { return createEntityManager(synchronizationType, Collections.EMPTY_MAP); }
@Override public EntityManager createEntityManager(SynchronizationType synchronizationType, @SuppressWarnings("rawtypes") Map map) { EntityManager result = new JefEntityManager(this, map); log.debug("[JPA DEBUG]:creating EntityManager:{} at {}", result, Thread.currentThread()); return result; }
public EntityManager createEntityManager(SynchronizationType syncType, Map params) { EntityManager entityManager = entityManagerFactory.createEntityManager(syncType, params); return new EntityManagerWrapper(entityManager); }
public EntityManager createEntityManager(SynchronizationType syncType) { EntityManager entityManager = entityManagerFactory.createEntityManager(syncType); return new EntityManagerWrapper(entityManager); }
@Override public EntityManager createEntityManager() { return createEntityManager(SynchronizationType.UNSYNCHRONIZED, Collections.emptyMap()); }
@Override public EntityManager createEntityManager(Map map) { return emf.createEntityManager(SynchronizationType.UNSYNCHRONIZED, map); }
@Override public EntityManager createEntityManager(SynchronizationType synchronizationType) { return emf.createEntityManager(synchronizationType, Collections.emptyMap()); }
public EntityManagerConfiguration(final Map properties, final SynchronizationType synchronizationType) { this.properties = properties; this.synchronizationType = synchronizationType; }
public SynchronizationType getSynchronizationType() { return synchronizationType; }
public static EntityManagerWrapper buildEntityManagerWrapper(String unitName, EntityManagerFactory emf, SynchronizationType sync) { JtaTransactionHolder jtaHolder = JtaTransactionHolder.getInstance(); TransactionManager transactionManager = jtaHolder.getTransactionManager(); TransactionSynchronizationRegistry transactionSynchronizationRegistry = jtaHolder.getTransactionSynchronizationRegistry(); NonTxEntityManagerHolder emHolder = new NonTxEntityManagerHolder(); EntityManager em = new TxScopedEntityManager(unitName, emf, sync, transactionManager, transactionSynchronizationRegistry, emHolder); return new TxScopedEntityManagerWrapper(em, emHolder); }