Search in sources :

Example 1 with PersistenceUnitReferenceMetaData

use of org.jboss.metadata.javaee.spec.PersistenceUnitReferenceMetaData in project wildfly by wildfly.

the class PersistenceRefProcessor method getPersistenceUnitRefs.

/**
     * 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> getPersistenceUnitRefs(DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
    final List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
    if (environment.getEnvironment() == null) {
        return bindingConfigurations;
    }
    PersistenceUnitReferencesMetaData persistenceUnitRefs = environment.getEnvironment().getPersistenceUnitRefs();
    if (persistenceUnitRefs != null) {
        if (persistenceUnitRefs.size() > 0) {
            JPADeploymentMarker.mark(deploymentUnit);
        }
        for (PersistenceUnitReferenceMetaData 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-unit-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, EntityManagerFactory.class);
            BindingConfiguration bindingConfiguration = null;
            if (!isEmpty(lookup)) {
                bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
            } else {
                InjectionSource puBindingSource = this.getPersistenceUnitBindingSource(deploymentUnit, persistenceUnitName);
                bindingConfiguration = new BindingConfiguration(name, puBindingSource);
            }
            bindingConfigurations.add(bindingConfiguration);
        }
    }
    return bindingConfigurations;
}
Also used : PersistenceUnitReferenceMetaData(org.jboss.metadata.javaee.spec.PersistenceUnitReferenceMetaData) PersistenceUnitReferencesMetaData(org.jboss.metadata.javaee.spec.PersistenceUnitReferencesMetaData) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) PersistenceContextInjectionSource(org.jboss.as.jpa.injectors.PersistenceContextInjectionSource) PersistenceUnitInjectionSource(org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource) ArrayList(java.util.ArrayList) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource)

Aggregations

ArrayList (java.util.ArrayList)1 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)1 InjectionSource (org.jboss.as.ee.component.InjectionSource)1 LookupInjectionSource (org.jboss.as.ee.component.LookupInjectionSource)1 PersistenceContextInjectionSource (org.jboss.as.jpa.injectors.PersistenceContextInjectionSource)1 PersistenceUnitInjectionSource (org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource)1 PersistenceUnitReferenceMetaData (org.jboss.metadata.javaee.spec.PersistenceUnitReferenceMetaData)1 PersistenceUnitReferencesMetaData (org.jboss.metadata.javaee.spec.PersistenceUnitReferencesMetaData)1