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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations