Search in sources :

Example 16 with PersistenceUnitMetadata

use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.

the class WeldJpaInjectionServices method getScopedPUName.

private String getScopedPUName(final DeploymentUnit deploymentUnit, final String persistenceUnitName, Member injectionPoint) {
    PersistenceUnitMetadata scopedPu;
    scopedPu = PersistenceUnitSearch.resolvePersistenceUnitSupplier(deploymentUnit, persistenceUnitName);
    if (null == scopedPu) {
        throw WeldLogger.ROOT_LOGGER.couldNotFindPersistenceUnit(persistenceUnitName, deploymentUnit.getName(), injectionPoint);
    }
    return scopedPu.getScopedPersistenceUnitName();
}
Also used : PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 17 with PersistenceUnitMetadata

use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.

the class PersistenceUnitServiceHandler method addPuService.

/**
     * Add one PU service per top level deployment that represents
     *
     *
     * @param phaseContext
     * @param puList
     * @param startEarly
     * @param platform
     * @throws DeploymentUnitProcessingException
     *
     */
private static void addPuService(final DeploymentPhaseContext phaseContext, final ArrayList<PersistenceUnitMetadataHolder> puList, final boolean startEarly, final Platform platform) throws DeploymentUnitProcessingException {
    if (puList.size() > 0) {
        final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
        final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
        final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        final Collection<ComponentDescription> components = eeModuleDescription.getComponentDescriptions();
        if (module == null) {
            // Unresolved OSGi bundles would not have a module attached
            ROOT_LOGGER.failedToGetModuleAttachment(deploymentUnit);
            return;
        }
        final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
        final ModuleClassLoader classLoader = module.getClassLoader();
        for (PersistenceUnitMetadataHolder holder : puList) {
            setAnnotationIndexes(holder, deploymentUnit);
            for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
                // only start the persistence unit if JPA_CONTAINER_MANAGED is true
                String jpaContainerManaged = pu.getProperties().getProperty(Configuration.JPA_CONTAINER_MANAGED);
                boolean deployPU = (jpaContainerManaged == null ? true : Boolean.parseBoolean(jpaContainerManaged));
                if (deployPU) {
                    final PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder = getPersistenceProviderDeploymentHolder(deploymentUnit);
                    final PersistenceProvider provider = lookupProvider(pu, persistenceProviderDeploymentHolder, deploymentUnit);
                    final PersistenceProviderAdaptor adaptor = getPersistenceProviderAdaptor(pu, persistenceProviderDeploymentHolder, deploymentUnit, provider, platform);
                    final boolean twoPhaseBootStrapCapable = (adaptor instanceof TwoPhaseBootstrapCapable) && Configuration.allowTwoPhaseBootstrap(pu);
                    if (startEarly) {
                        if (twoPhaseBootStrapCapable) {
                            deployPersistenceUnitPhaseOne(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, adaptor);
                        } else if (false == Configuration.needClassFileTransformer(pu)) {
                            // will start later when startEarly == false
                            ROOT_LOGGER.tracef("persistence unit %s in deployment %s is configured to not need class transformer to be set, no class rewriting will be allowed", pu.getPersistenceUnitName(), deploymentUnit.getName());
                        } else {
                            // we need class file transformer to work, don't allow cdi bean manager to be access since that
                            // could cause application classes to be loaded (workaround by setting jboss.as.jpa.classtransformer to false).  WFLY-1463
                            final boolean allowCdiBeanManagerAccess = false;
                            deployPersistenceUnit(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, startEarly, provider, adaptor, allowCdiBeanManagerAccess);
                        }
                    } else {
                        // !startEarly
                        if (twoPhaseBootStrapCapable) {
                            deployPersistenceUnitPhaseTwo(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, provider, adaptor);
                        } else if (false == Configuration.needClassFileTransformer(pu)) {
                            final boolean allowCdiBeanManagerAccess = true;
                            // PUs that have Configuration.JPA_CONTAINER_CLASS_TRANSFORMER = false will start during INSTALL phase
                            deployPersistenceUnit(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, startEarly, provider, adaptor, allowCdiBeanManagerAccess);
                        }
                    }
                } else {
                    ROOT_LOGGER.tracef("persistence unit %s in deployment %s is not container managed (%s is set to false)", pu.getPersistenceUnitName(), deploymentUnit.getName(), Configuration.JPA_CONTAINER_MANAGED);
                }
            }
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) ServiceTarget(org.jboss.msc.service.ServiceTarget) PersistenceProvider(javax.persistence.spi.PersistenceProvider) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) Module(org.jboss.modules.Module) PersistenceProviderDeploymentHolder(org.jboss.as.jpa.config.PersistenceProviderDeploymentHolder) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) TwoPhaseBootstrapCapable(org.jipijapa.plugin.spi.TwoPhaseBootstrapCapable) PersistenceProviderAdaptor(org.jipijapa.plugin.spi.PersistenceProviderAdaptor)

Example 18 with PersistenceUnitMetadata

use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.

the class PersistenceUnitXmlParser method parse.

public static PersistenceUnitMetadataHolder parse(final XMLStreamReader reader, final PropertyReplacer propertyReplacer) throws XMLStreamException {
    // check for a bogus document and throw error
    reader.require(START_DOCUMENT, null, null);
    // Read until the first start element
    Version version = null;
    while (reader.hasNext() && reader.next() != START_ELEMENT) {
        if (reader.getEventType() == DTD) {
            final String dtdLocation = readDTDLocation(reader);
            if (dtdLocation != null) {
                version = Version.forLocation(dtdLocation);
            }
        }
    }
    final String schemaLocation = readSchemaLocation(reader);
    if (schemaLocation != null) {
        version = Version.forLocation(schemaLocation);
    }
    if (version == null || Version.UNKNOWN.equals(version)) {
        // Look at the version attribute
        String versionString = null;
        final int count = reader.getAttributeCount();
        for (int i = 0; i < count; i++) {
            final String attributeNamespace = reader.getAttributeNamespace(i);
            if (attributeNamespace != null && !attributeNamespace.isEmpty()) {
                continue;
            }
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            if (attribute == Attribute.VERSION) {
                versionString = reader.getAttributeValue(i);
            }
        }
        if ("1.0".equals(versionString)) {
            version = Version.JPA_1_0;
        } else if ("1".equals(versionString)) {
            version = Version.JPA_1_0;
        } else if ("2.0".equals(versionString)) {
            version = Version.JPA_2_0;
        } else if ("2.1".equals(versionString)) {
            version = Version.JPA_2_1;
        } else if ("2".equals(versionString)) {
            version = Version.JPA_2_0;
        } else {
            version = Version.JPA_2_1;
        }
    }
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String attributeNamespace = reader.getAttributeNamespace(i);
        if (attributeNamespace != null && !attributeNamespace.isEmpty()) {
            continue;
        }
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        switch(attribute) {
            case VERSION:
                // TODO:  handle version
                break;
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    final List<PersistenceUnitMetadata> PUs = new ArrayList<PersistenceUnitMetadata>();
    // until the ending PERSISTENCE tag
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        switch(element) {
            case PERSISTENCEUNIT:
                PersistenceUnitMetadata pu = parsePU(reader, version, propertyReplacer);
                PUs.add(pu);
                ROOT_LOGGER.readingPersistenceXml(pu.getPersistenceUnitName());
                break;
            default:
                throw unexpectedElement(reader);
        }
    }
    PersistenceUnitMetadataHolder result = new PersistenceUnitMetadataHolder(PUs);
    if (ROOT_LOGGER.isTraceEnabled())
        ROOT_LOGGER.trace(result.toString());
    return result;
}
Also used : PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) ArrayList(java.util.ArrayList) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 19 with PersistenceUnitMetadata

use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.

the class JPADependencyProcessor method addPUServiceDependencyToComponents.

/**
     * Add the <code>puServiceName</code> as a dependency on each of the passed <code>components</code>
     *
     * @param components    The components to which the PU service is added as a dependency
     * @param holder        The persistence units
     */
private static void addPUServiceDependencyToComponents(final Collection<ComponentDescription> components, final PersistenceUnitMetadataHolder holder) {
    if (components == null || components.isEmpty() || holder == null) {
        return;
    }
    for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
        String jpaContainerManaged = pu.getProperties().getProperty(Configuration.JPA_CONTAINER_MANAGED);
        boolean deployPU = (jpaContainerManaged == null ? true : Boolean.parseBoolean(jpaContainerManaged));
        if (deployPU) {
            final ServiceName puServiceName = PersistenceUnitServiceImpl.getPUServiceName(pu);
            for (final ComponentDescription component : components) {
                ROOT_LOGGER.debugf("Adding dependency on PU service %s for component %s", puServiceName, component.getComponentClassName());
                component.addDependency(puServiceName, ServiceBuilder.DependencyType.REQUIRED);
            }
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ServiceName(org.jboss.msc.service.ServiceName) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 20 with PersistenceUnitMetadata

use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.

the class PersistenceRefProcessor method getPersistenceContextBindingSource.

private InjectionSource getPersistenceContextBindingSource(final DeploymentUnit deploymentUnit, final String unitName, PersistenceContextType type, SynchronizationType synchronizationType, Map properties) throws DeploymentUnitProcessingException {
    PersistenceUnitMetadata pu = getPersistenceUnit(deploymentUnit, unitName);
    String scopedPuName = pu.getScopedPersistenceUnitName();
    ServiceName puServiceName = getPuServiceName(scopedPuName);
    // 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, EntityManager.class.getName(), pu, jpaDeploymentSettings);
}
Also used : EntityManager(javax.persistence.EntityManager) JPADeploymentSettings(org.jboss.as.jpa.config.JPADeploymentSettings) ServiceName(org.jboss.msc.service.ServiceName) PersistenceContextInjectionSource(org.jboss.as.jpa.injectors.PersistenceContextInjectionSource) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Aggregations

PersistenceUnitMetadata (org.jipijapa.plugin.spi.PersistenceUnitMetadata)25 PersistenceUnitMetadataHolder (org.jboss.as.jpa.config.PersistenceUnitMetadataHolder)10 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)6 ServiceName (org.jboss.msc.service.ServiceName)6 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 AnnotationInstance (org.jboss.jandex.AnnotationInstance)3 Index (org.jboss.jandex.Index)3 URL (java.net.URL)2 Properties (java.util.Properties)2 PersistenceProvider (javax.persistence.spi.PersistenceProvider)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2 JPADeploymentSettings (org.jboss.as.jpa.config.JPADeploymentSettings)2 PersistenceProviderDeploymentHolder (org.jboss.as.jpa.config.PersistenceProviderDeploymentHolder)2 PersistenceUnitsInApplication (org.jboss.as.jpa.config.PersistenceUnitsInApplication)2 PersistenceContextInjectionSource (org.jboss.as.jpa.injectors.PersistenceContextInjectionSource)2 PersistenceUnitInjectionSource (org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 AnnotationValue (org.jboss.jandex.AnnotationValue)2