use of javax.persistence.SynchronizationType in project wildfly by wildfly.
the class PersistenceRefProcessor method getPersistenceContextRefs.
/**
* Resolves persistence-unit-ref
*
* @param environment The environment to resolve the elements for
* @param classLoader The deployment class loader
* @param deploymentReflectionIndex The reflection index
* @return The bindings for the environment entries
*/
private List<BindingConfiguration> getPersistenceContextRefs(DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
final RemoteEnvironment remoteEnvironment = environment.getEnvironment();
if (remoteEnvironment == null) {
return bindingConfigurations;
}
if (remoteEnvironment instanceof Environment) {
PersistenceContextReferencesMetaData persistenceUnitRefs = ((Environment) remoteEnvironment).getPersistenceContextRefs();
if (persistenceUnitRefs != null) {
for (PersistenceContextReferenceMetaData puRef : persistenceUnitRefs) {
String name = puRef.getName();
String persistenceUnitName = puRef.getPersistenceUnitName();
String lookup = puRef.getLookupName();
if (!isEmpty(lookup) && !isEmpty(persistenceUnitName)) {
throw JpaLogger.ROOT_LOGGER.cannotSpecifyBoth("<lookup-name>", lookup, "persistence-unit-name", persistenceUnitName, "<persistence-context-ref/>", resourceInjectionTarget);
}
if (!name.startsWith("java:")) {
name = environment.getDefaultContext() + name;
}
// our injection (source) comes from the local (ENC) lookup, no matter what.
LookupInjectionSource injectionSource = new LookupInjectionSource(name);
//add any injection targets
processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, puRef, EntityManager.class);
BindingConfiguration bindingConfiguration = null;
if (!isEmpty(lookup)) {
bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
} else {
PropertiesMetaData properties = puRef.getProperties();
Map<String, String> map = new HashMap<>();
if (properties != null) {
for (PropertyMetaData prop : properties) {
map.put(prop.getKey(), prop.getValue());
}
}
PersistenceContextType type = (puRef.getPersistenceContextType() == null || puRef.getPersistenceContextType() == PersistenceContextTypeDescription.TRANSACTION) ? PersistenceContextType.TRANSACTION : PersistenceContextType.EXTENDED;
SynchronizationType synchronizationType = (puRef.getPersistenceContextSynchronization() == null || PersistenceContextSynchronizationType.Synchronized.equals(puRef.getPersistenceContextSynchronization())) ? SynchronizationType.SYNCHRONIZED : SynchronizationType.UNSYNCHRONIZED;
InjectionSource pcBindingSource = this.getPersistenceContextBindingSource(deploymentUnit, persistenceUnitName, type, synchronizationType, map);
bindingConfiguration = new BindingConfiguration(name, pcBindingSource);
}
bindingConfigurations.add(bindingConfiguration);
}
}
}
return bindingConfigurations;
}
use of javax.persistence.SynchronizationType in project wildfly by wildfly.
the class JPAAnnotationProcessor method getBindingSource.
private InjectionSource getBindingSource(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, String injectionTypeName, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
PersistenceUnitMetadata pu = getPersistenceUnit(deploymentUnit, annotation, classDescription);
if (pu == null) {
return null;
}
String scopedPuName = pu.getScopedPersistenceUnitName();
ServiceName puServiceName = getPuServiceName(scopedPuName);
if (isPersistenceContext(annotation)) {
if (pu.getTransactionType() == PersistenceUnitTransactionType.RESOURCE_LOCAL) {
classDescription.setInvalid(JpaLogger.ROOT_LOGGER.cannotInjectResourceLocalEntityManager());
return null;
}
AnnotationValue pcType = annotation.value("type");
PersistenceContextType type = (pcType == null || PersistenceContextType.TRANSACTION.name().equals(pcType.asString())) ? PersistenceContextType.TRANSACTION : PersistenceContextType.EXTENDED;
AnnotationValue stType = annotation.value("synchronization");
SynchronizationType synchronizationType = (stType == null || SynchronizationType.SYNCHRONIZED.name().equals(stType.asString())) ? SynchronizationType.SYNCHRONIZED : SynchronizationType.UNSYNCHRONIZED;
Map<String, String> properties;
AnnotationValue value = annotation.value("properties");
AnnotationInstance[] props = value != null ? value.asNestedArray() : null;
if (props != null) {
properties = new HashMap<>();
for (int source = 0; source < props.length; source++) {
properties.put(props[source].value("name").asString(), props[source].value("value").asString());
}
} else {
properties = null;
}
// get deployment settings from top level du (jboss-all.xml is only parsed at the top level).
final JPADeploymentSettings jpaDeploymentSettings = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachment(JpaAttachments.DEPLOYMENT_SETTINGS_KEY);
return new PersistenceContextInjectionSource(type, synchronizationType, properties, puServiceName, deploymentUnit.getServiceRegistry(), scopedPuName, injectionTypeName, pu, jpaDeploymentSettings);
} else {
return new PersistenceUnitInjectionSource(puServiceName, deploymentUnit.getServiceRegistry(), injectionTypeName, pu);
}
}
use of javax.persistence.SynchronizationType in project tomee by apache.
the class StatefulContainer method createEntityManagers.
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;
}
use of javax.persistence.SynchronizationType in project tomee by apache.
the class ManagedContainer method createEntityManagers.
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;
}
Aggregations