FileDocCategorySizeDatePackage
DefaultProviderVerification.javaAPI DocGlassfish v2 API6278Tue Jul 17 05:34:28 BST 2007com.sun.enterprise.tools.verifier.tests.persistence

DefaultProviderVerification

public class DefaultProviderVerification extends com.sun.enterprise.tools.verifier.tests.VerifierTest implements com.sun.enterprise.tools.verifier.tests.VerifierCheck
This test uses TopLink Essential to do the validation.
author
Sanjeeb.Sahoo@Sun.COM

Fields Summary
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.Descriptor descriptor)

        PersistenceUnitDescriptor pu =
                PersistenceUnitDescriptor.class.cast(descriptor);
        Result result = getInitializedResult();
        result.setStatus(Result.PASSED);
        PersistenceProvider provider;
        final String appLocation =
                getVerifierContext().getAbstractArchive().getArchiveUri();
        final InstrumentableClassLoader cl =
                InstrumentableClassLoader.class.cast(pu.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(EntityManagerFactoryProvider.TOPLINK_VALIDATION_ONLY_PROPERTY, 
                "TRUE"); // NOI18N
        // 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(EntityManagerFactoryProvider.TOPLINK_ORM_THROW_EXCEPTIONS, 
                "TRUE"); // NOI18N

        // the following property is needed as it initializes the logger in TL
        props.put(TopLinkProperties.TARGET_SERVER,
                      "oracle.toplink.essentials.platform.server.sunas.SunAS9ServerPlatform"); // NOI18N

        // Turn off enhancement during verification. For details,
        // refer to http://glassfish.dev.java.net/issues/show_bug.cgi?id=3295
        props.put(TopLinkProperties.WEAVING, "FALSE");

        provider = new EntityManagerFactoryProvider();
        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());
        } catch(DatabaseException de) {
            addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
            result.failed(de.getMessage());
        } catch(PersistenceException pe) {
            addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
            result.failed(pe.getMessage());
        } finally {
            if(emf != null) {
                emf.close();
            }
        }
        return result;