Search in sources :

Example 1 with PersistenceUnitDescriptor

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

the class ClassNotFound method check.

public Result check(Descriptor descriptor) {
    Result result = getInitializedResult();
    addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
    result.setStatus(Result.PASSED);
    final PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast(descriptor);
    for (String className : pu.getClasses()) {
        try {
            Class.forName(className, false, getVerifierContext().getClassLoader());
        } catch (ClassNotFoundException e) {
            result.failed(smh.getLocalString(getClass().getName() + "failed1", "Class [ {0} ] could not be loaded", new Object[] { className }));
        } catch (NoClassDefFoundError e) {
            result.failed(smh.getLocalString(getClass().getName() + "failed2", "Class [ {0} ] could not be loaded " + "because a dependent class could not be loaded. See reason:\n [ {1} ]", new Object[] { className, e.getMessage() }));
        }
    }
    return result;
}
Also used : Result(com.sun.enterprise.tools.verifier.Result) PersistenceUnitDescriptor(com.sun.enterprise.deployment.PersistenceUnitDescriptor)

Example 2 with PersistenceUnitDescriptor

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

the class DefaultProviderVerification method check.

public Result check(Descriptor descriptor) {
    PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast(descriptor);
    Result result = getInitializedResult();
    result.setStatus(Result.PASSED);
    PersistenceProvider provider;
    final String appLocation = getVerifierContext().getAbstractArchive().getURI().getPath();
    final InstrumentableClassLoader cl = InstrumentableClassLoader.class.cast(pu.getParent().getClassLoader());
    PersistenceUnitInfo pi = new AVKPersistenceUnitInfoImpl(pu, appLocation, cl);
    logger.fine("PersistenceInfo for PU is :\n" + pi);
    Properties props = new Properties();
    // This property is set to indicate that TopLink should only
    // validate the descriptors etc. and not try to login to database.
    props.put(PersistenceUnitProperties.VALIDATION_ONLY_PROPERTY, // NOI18N
    "TRUE");
    // This property is used so that TopLink throws validation exceptions
    // as opposed to printing CONFIG level messages to console.
    // e.g. if mapping file does not exist, we will get an exception.
    props.put(PersistenceUnitProperties.THROW_EXCEPTIONS, // NOI18N
    "TRUE");
    // the following property is needed as it initializes the logger in TL
    props.put(PersistenceUnitProperties.TARGET_SERVER, // NOI18N
    "SunAS9");
    // Turn off enhancement during verification. For details,
    // refer to http://glassfish.dev.java.net/issues/show_bug.cgi?id=3295
    props.put(PersistenceUnitProperties.WEAVING, "FALSE");
    provider = new org.eclipse.persistence.jpa.PersistenceProvider();
    EntityManagerFactory emf = null;
    try {
        emf = provider.createContainerEntityManagerFactory(pi, props);
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "emf = {0}", emf);
    } catch (IntegrityException ie) {
        result.setStatus(Result.FAILED);
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        for (Object o : ie.getIntegrityChecker().getCaughtExceptions()) {
            Exception e = Exception.class.cast(o);
            result.addErrorDetails(e.getMessage());
        }
    } catch (ValidationException ve) {
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        result.failed(ve.getMessage());
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", ve);
    } catch (DatabaseException de) {
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        result.failed(de.getMessage());
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", de);
    } catch (PersistenceException pe) {
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        result.failed(pe.getMessage());
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", pe);
    } finally {
        if (emf != null) {
            emf.close();
        }
    }
    return result;
}
Also used : ValidationException(org.eclipse.persistence.exceptions.ValidationException) InstrumentableClassLoader(org.glassfish.api.deployment.InstrumentableClassLoader) PersistenceProvider(javax.persistence.spi.PersistenceProvider) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) AVKPersistenceUnitInfoImpl(com.sun.enterprise.tools.verifier.persistence.AVKPersistenceUnitInfoImpl) Properties(java.util.Properties) PersistenceUnitProperties(org.eclipse.persistence.config.PersistenceUnitProperties) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) PersistenceException(javax.persistence.PersistenceException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) Result(com.sun.enterprise.tools.verifier.Result) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceException(javax.persistence.PersistenceException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) PersistenceUnitDescriptor(com.sun.enterprise.deployment.PersistenceUnitDescriptor)

Example 3 with PersistenceUnitDescriptor

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

the class DuplicatePUNameTest method check.

public Result check(Descriptor descriptor) {
    PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast(descriptor);
    Result result = getInitializedResult();
    addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
    // default status is PASSED
    result.setStatus(Result.PASSED);
    int count = 0;
    for (PersistenceUnitDescriptor nextPU : getPUsInSameScope(pu)) {
        result.addErrorDetails(smh.getLocalString(getClass().getName() + "puName", "Found a persistence unit by name [ {0} ] in persistence unit root [ {1} ]", new Object[] { nextPU.getName(), nextPU.getPuRoot() }));
        if (nextPU.getName().equals(pu.getName()))
            count++;
    }
    if (count != 1) {
        result.failed(smh.getLocalString(getClass().getName() + "failed", "There are [ {0} ] number of persistence units by name [ {1} ]", new Object[] { count, pu.getName() }));
    }
    return result;
}
Also used : PersistenceUnitDescriptor(com.sun.enterprise.deployment.PersistenceUnitDescriptor) Result(com.sun.enterprise.tools.verifier.Result)

Example 4 with PersistenceUnitDescriptor

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

the class JarNotFound method check.

public Result check(Descriptor descriptor) {
    Result result = getInitializedResult();
    result.setStatus(Result.PASSED);
    addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
    PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast(descriptor);
    File absolutePURootFile = getAbsolutePuRootFile(pu);
    logger.fine("Absolute PU Root: " + absolutePURootFile);
    String absolutePuRoot = absolutePURootFile.getAbsolutePath();
    List<String> jarFileNames = new ArrayList<String>(pu.getJarFiles());
    for (String jarFileName : jarFileNames) {
        // ASSUMPTION:
        // Because of the way deployment changes names of directories etc.
        // it is very difficult to back calculate path names. So,
        // the following code assumes user is specifying valid URIs.
        // in the xml, names always use '/'
        String nativeJarFileName = jarFileName.replace('/', File.separatorChar);
        final File parentFile = new File(absolutePuRoot).getParentFile();
        // only components are exploded, hence first look for original archives.
        File jarFile = new File(parentFile, nativeJarFileName);
        if (!jarFile.exists()) {
            // if the referenced jar is itself a component, then
            // it might have been exploded, hence let's see
            // if that is the case.
            // let's calculate the name component and path component from this URI
            // e.g. if URI is ../../foo_bar/my-ejb.jar,
            // name component is foo_bar/my-ejb.jar and
            // path component is ../../
            // These are my own notions used here.
            String pathComponent = "";
            String nameComponent = jarFileName;
            if (jarFileName.lastIndexOf("../") != -1) {
                final int separatorIndex = jarFileName.lastIndexOf("../") + 3;
                pathComponent = jarFileName.substring(0, separatorIndex);
                nameComponent = jarFileName.substring(separatorIndex);
            }
            logger.fine("For jar-file=" + jarFileName + ", " + "pathComponent=" + pathComponent + ", nameComponent=" + nameComponent);
            File parentPath = new File(parentFile, pathComponent);
            jarFile = new File(parentPath, DeploymentUtils.getRelativeEmbeddedModulePath(parentPath.getAbsolutePath(), nameComponent));
            if (!jarFile.exists()) {
                result.failed(smh.getLocalString(getClass().getName() + "failed", "[ {0} ] specified in persistence.xml does not exist in the application.", new Object[] { jarFileName }));
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) Result(com.sun.enterprise.tools.verifier.Result) PersistenceUnitDescriptor(com.sun.enterprise.deployment.PersistenceUnitDescriptor)

Example 5 with PersistenceUnitDescriptor

use of com.sun.enterprise.deployment.PersistenceUnitDescriptor 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)

Aggregations

PersistenceUnitDescriptor (com.sun.enterprise.deployment.PersistenceUnitDescriptor)10 Result (com.sun.enterprise.tools.verifier.Result)6 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)2 ArrayList (java.util.ArrayList)2 ManagedBeanManager (com.sun.enterprise.container.common.spi.ManagedBeanManager)1 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 EntityManagerFactoryReferenceDescriptor (com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor)1 PersistenceUnitsDescriptor (com.sun.enterprise.deployment.PersistenceUnitsDescriptor)1 AVKPersistenceUnitInfoImpl (com.sun.enterprise.tools.verifier.persistence.AVKPersistenceUnitInfoImpl)1 File (java.io.File)1 Properties (java.util.Properties)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 PersistenceException (javax.persistence.PersistenceException)1 PersistenceProvider (javax.persistence.spi.PersistenceProvider)1 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)1 PersistenceUnitProperties (org.eclipse.persistence.config.PersistenceUnitProperties)1 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)1 IntegrityException (org.eclipse.persistence.exceptions.IntegrityException)1 ValidationException (org.eclipse.persistence.exceptions.ValidationException)1 InstrumentableClassLoader (org.glassfish.api.deployment.InstrumentableClassLoader)1