1 23 24 25 package com.sun.enterprise.tools.verifier.tests.persistence; 26 27 import com.sun.enterprise.deployment.Descriptor; 28 import com.sun.enterprise.deployment.PersistenceUnitDescriptor; 29 import com.sun.enterprise.tools.verifier.Result; 30 import com.sun.enterprise.tools.verifier.persistence.AVKPersistenceUnitInfoImpl; 31 import com.sun.enterprise.tools.verifier.tests.VerifierCheck; 32 import com.sun.enterprise.tools.verifier.tests.VerifierTest; 33 34 import javax.persistence.EntityManagerFactory; 35 import javax.persistence.PersistenceException; 36 37 import com.sun.enterprise.loader.InstrumentableClassLoader; 38 import javax.persistence.spi.PersistenceProvider; 39 import javax.persistence.spi.PersistenceUnitInfo; 40 import java.util.logging.Level ; 41 import java.util.Properties ; 42 43 import oracle.toplink.essentials.exceptions.IntegrityException; 44 import oracle.toplink.essentials.exceptions.ValidationException; 45 import oracle.toplink.essentials.exceptions.DatabaseException; 46 import oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider; 47 48 53 public class DefaultProviderVerification extends VerifierTest 54 implements VerifierCheck { 55 public Result check(Descriptor descriptor) { 56 PersistenceUnitDescriptor pu = 57 PersistenceUnitDescriptor.class.cast(descriptor); 58 Result result = getInitializedResult(); 59 result.setStatus(Result.PASSED); 60 PersistenceProvider provider; 61 final String appLocation = 62 getVerifierContext().getAbstractArchive().getArchiveUri(); 63 final InstrumentableClassLoader cl = 64 InstrumentableClassLoader.class.cast(pu.getClassLoader()); 65 PersistenceUnitInfo pi = new AVKPersistenceUnitInfoImpl(pu, appLocation, cl); 66 logger.fine("PersistenceInfo for PU is :\n" + pi); 67 Properties props = new Properties (); 68 props.put(EntityManagerFactoryProvider.TOPLINK_VALIDATION_ONLY_PROPERTY, 71 "TRUE"); props.put(EntityManagerFactoryProvider.TOPLINK_ORM_THROW_EXCEPTIONS, 76 "TRUE"); provider = new EntityManagerFactoryProvider(); 78 EntityManagerFactory emf = null; 79 try { 80 emf = provider.createContainerEntityManagerFactory(pi, props); 81 logger.logp(Level.FINE, "DefaultProviderVerification", "check", 82 "emf = {0}", emf); 83 } catch(IntegrityException ie){ 84 result.setStatus(Result.FAILED); 85 addErrorDetails(result, getVerifierContext().getComponentNameConstructor()); 86 for(Object o: ie.getIntegrityChecker().getCaughtExceptions()){ 87 Exception e = Exception .class.cast(o); 88 result.addErrorDetails(e.getMessage()); 89 } 90 } catch (ValidationException ve) { 91 addErrorDetails(result, getVerifierContext().getComponentNameConstructor()); 92 result.failed(ve.getMessage()); 93 } catch(DatabaseException de) { 94 addErrorDetails(result, getVerifierContext().getComponentNameConstructor()); 95 result.failed(de.getMessage()); 96 } catch(PersistenceException pe) { 97 addErrorDetails(result, getVerifierContext().getComponentNameConstructor()); 98 result.failed(pe.getMessage()); 99 } finally { 100 if(emf != null) { 101 emf.close(); 102 } 103 } 104 return result; 105 } 106 107 } 108 | Popular Tags |