Search in sources :

Example 1 with PersistenceUnitsDescriptor

use of com.sun.enterprise.deployment.PersistenceUnitsDescriptor in project Payara by payara.

the class PUTransactionType method check.

public Result check(Descriptor descriptor) {
    ApplicationClientDescriptor appClient = (ApplicationClientDescriptor) descriptor;
    Result result = getInitializedResult();
    addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
    // default status is PASSED
    result.setStatus(Result.PASSED);
    for (PersistenceUnitsDescriptor pus : appClient.getExtensionsDescriptors(PersistenceUnitsDescriptor.class)) {
        for (PersistenceUnitDescriptor nextPU : pus.getPersistenceUnitDescriptors()) {
            if ("JTA".equals(nextPU.getTransactionType())) {
                result.failed(smh.getLocalString(getClass().getName() + ".puName", "Found a persistence unit by name [ {0} ] in persistence unit root [ {1} ] with JTA transaction type.", new Object[] { nextPU.getName(), nextPU.getPuRoot() }));
            }
        }
    }
    for (EntityManagerFactoryReferenceDescriptor emfRef : appClient.getEntityManagerFactoryReferenceDescriptors()) {
        String unitName = emfRef.getUnitName();
        PersistenceUnitDescriptor nextPU = appClient.findReferencedPU(unitName);
        if (nextPU == null)
            continue;
        if ("JTA".equals(nextPU.getTransactionType())) {
            result.failed(smh.getLocalString(getClass().getName() + ".puRefName", "Found a reference to a persistence unit by name [ {0} ] in persistence unit root [ {1} ] with JTA transaction type.", new Object[] { nextPU.getName(), nextPU.getPuRoot() }));
        }
    }
    return result;
}
Also used : ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) PersistenceUnitsDescriptor(com.sun.enterprise.deployment.PersistenceUnitsDescriptor) EntityManagerFactoryReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor) Result(com.sun.enterprise.tools.verifier.Result) PersistenceUnitDescriptor(com.sun.enterprise.deployment.PersistenceUnitDescriptor)

Example 2 with PersistenceUnitsDescriptor

use of com.sun.enterprise.deployment.PersistenceUnitsDescriptor in project Payara by payara.

the class PersistenceUnitLoader method loadPU.

/**
 * Loads an individual PersistenceUnitDescriptor and registers the
 * EntityManagerFactory in appropriate DOL structure.
 *
 * @param pud PersistenceUnitDescriptor to be loaded.
 */
private EntityManagerFactory loadPU(PersistenceUnitDescriptor pud) {
    checkForUpgradeFromTopLinkEssentials(pud);
    checkForDataSourceOverride(pud);
    calculateDefaultDataSource(pud);
    PersistenceUnitInfo pInfo = new PersistenceUnitInfoImpl(pud, providerContainerContractInfo);
    String applicationLocation = providerContainerContractInfo.getApplicationLocation();
    final boolean fineMsgLoggable = logger.isLoggable(Level.FINE);
    if (fineMsgLoggable) {
        logger.fine("Loading persistence unit for application: \"" + applicationLocation + "\"pu Root is: " + pud.getPuRoot());
        // NOI18N
        logger.fine("PersistenceInfo for this pud is :\n" + pInfo);
    }
    PersistenceProvider provider;
    try {
        // See we use application CL as opposed to system CL to loadPU
        // provider. This allows user to get hold of provider specific
        // implementation classes in their code. But this also means
        // provider must not use appserver implementation classes directly
        // because once we implement isolation in our class loader hierarchy
        // the only classes available to application class loader would be
        // our appserver interface classes. By Sahoo
        provider = PersistenceProvider.class.cast(providerContainerContractInfo.getClassLoader().loadClass(pInfo.getPersistenceProviderClassName()).newInstance());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    Map<String, Object> schemaGenerationOverrides;
    schemaGenerationProcessor = SchemaGenerationProcessorFactory.createSchemaGenerationProcessor(pud);
    if (providerContainerContractInfo.isJava2DBRequired()) {
        schemaGenerationProcessor.init(pud, providerContainerContractInfo.getDeploymentContext());
        schemaGenerationOverrides = schemaGenerationProcessor.getOverridesForSchemaGeneration();
    } else {
        // schema generation is not required if this EMF is being created for
        // -appserver restarting or,
        // -on an instance or,
        // -appclient
        // Suppress schema generation in this case
        schemaGenerationOverrides = schemaGenerationProcessor.getOverridesForSuppressingSchemaGeneration();
    }
    Map<String, Object> overRides = new HashMap<String, Object>(integrationProperties);
    if (schemaGenerationOverrides != null) {
        overRides.putAll(schemaGenerationOverrides);
    }
    // Check if the persistence unit requires Bean Validation
    ValidationMode validationMode = getValidationMode(pud);
    if (validationMode == ValidationMode.AUTO || validationMode == ValidationMode.CALLBACK) {
        overRides.put(VALIDATOR_FACTORY, providerContainerContractInfo.getValidatorFactory());
    }
    if (!providerContainerContractInfo.isWeavingEnabled()) {
        // NOI18N
        overRides.put(ECLIPSELINK_WEAVING_PROPERTY, System.getProperty(ECLIPSELINK_WEAVING_PROPERTY, "false"));
    }
    EntityManagerFactory emf = provider.createContainerEntityManagerFactory(pInfo, overRides);
    if (fineMsgLoggable) {
        // NOI18N
        logger.logp(// NOI18N
        Level.FINE, // NOI18N
        "PersistenceUnitLoader", // NOI18N
        "loadPU", "emf = {0}", // NOI18N
        emf);
    }
    PersistenceUnitsDescriptor parent = pud.getParent();
    RootDeploymentDescriptor containingBundle = parent.getParent();
    providerContainerContractInfo.registerEMF(pInfo.getPersistenceUnitName(), pud.getPuRoot(), containingBundle, emf);
    if (fineMsgLoggable) {
        logger.fine(// NOI18N
        "Finished loading persistence unit for application: " + applicationLocation);
    }
    return emf;
}
Also used : HashMap(java.util.HashMap) PersistenceProvider(javax.persistence.spi.PersistenceProvider) ValidationMode(javax.persistence.ValidationMode) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) PersistenceUnitsDescriptor(com.sun.enterprise.deployment.PersistenceUnitsDescriptor) RootDeploymentDescriptor(org.glassfish.deployment.common.RootDeploymentDescriptor) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 3 with PersistenceUnitsDescriptor

use of com.sun.enterprise.deployment.PersistenceUnitsDescriptor in project Payara by payara.

the class PersistenceArchivist method readPersistenceDeploymentDescriptor.

protected PersistenceUnitsDescriptor readPersistenceDeploymentDescriptor(Archivist main, ReadableArchive subArchive, String puRoot, RootDeploymentDescriptor descriptor) throws IOException, SAXParseException {
    final String subArchiveURI = subArchive.getURI().getSchemeSpecificPart();
    if (deplLogger.isLoggable(Level.FINE)) {
        deplLogger.logp(Level.FINE, "Archivist", "readPersistenceDeploymentDescriptor", "PURoot = [{0}] subArchive = {1}", new Object[] { puRoot, subArchiveURI });
    }
    if (descriptor.getExtensionsDescriptors(PersistenceUnitsDescriptor.class, puRoot) != null) {
        if (deplLogger.isLoggable(Level.FINE)) {
            deplLogger.logp(Level.FINE, "Archivist", "readPersistenceDeploymentDescriptor", "PU has been already read for = {0}", subArchiveURI);
        }
        return null;
    }
    PersistenceUnitsDescriptor persistenceUnitsDescriptor = PersistenceUnitsDescriptor.class.cast(super.open(main, subArchive, descriptor));
    if (persistenceUnitsDescriptor != null) {
        persistenceUnitsDescriptor.setParent(descriptor);
        persistenceUnitsDescriptor.setPuRoot(puRoot);
        descriptor.addExtensionDescriptor(PersistenceUnitsDescriptor.class, persistenceUnitsDescriptor, puRoot);
    }
    return persistenceUnitsDescriptor;
}
Also used : PersistenceUnitsDescriptor(com.sun.enterprise.deployment.PersistenceUnitsDescriptor)

Aggregations

PersistenceUnitsDescriptor (com.sun.enterprise.deployment.PersistenceUnitsDescriptor)3 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)1 EntityManagerFactoryReferenceDescriptor (com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor)1 PersistenceUnitDescriptor (com.sun.enterprise.deployment.PersistenceUnitDescriptor)1 Result (com.sun.enterprise.tools.verifier.Result)1 HashMap (java.util.HashMap)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 ValidationMode (javax.persistence.ValidationMode)1 PersistenceProvider (javax.persistence.spi.PersistenceProvider)1 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)1 RootDeploymentDescriptor (org.glassfish.deployment.common.RootDeploymentDescriptor)1