use of org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor in project Payara by payara.
the class AbstractMethodHelper method categorizeMethods.
/**
* Reads all known methods and sorts them by name into specific
* Collections for further processing.
*/
protected void categorizeMethods() {
EjbCMPEntityDescriptor descriptor = getDescriptor();
Iterator iterator = descriptor.getMethodDescriptors().iterator();
while (iterator.hasNext()) {
MethodDescriptor methodDescriptor = (MethodDescriptor) iterator.next();
Method method = methodDescriptor.getMethod(descriptor);
String methodName = methodDescriptor.getName();
if (methodName.startsWith(CMPTemplateFormatter.find_))
finders.add(method);
else if (methodName.startsWith(CMPTemplateFormatter.ejbSelect_))
selectors.add(method);
else if (methodName.startsWith(CMPTemplateFormatter.create_))
createMethods.add(method);
else if (methodName.startsWith(CMPTemplateFormatter.get_) || methodName.startsWith(CMPTemplateFormatter.set_)) {
// skip
;
}
// else
// otherMethods.add(method);
// It is OK to use HashMap here as we won't use it for possible
// overloaded methods.
methodNames.put(methodName, method);
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor in project Payara by payara.
the class EjbQLChecker method checkSyntax.
/**
* Check the syntax and semantics of the targetted
* queries.
*
* @param desc An PersistenceDescriptor object.
* @param ejbqlDriver An EjbQlDriver created using the
* targetted ejb bundle.
* @param result The test results.
* @param ownerClassName Name of the class initiated the test.
* @return whether any error has occurred.
*/
public static boolean checkSyntax(EjbDescriptor ejbDesc, EJBQLC ejbqlDriver, Result result, String ownerClassName) {
boolean hasError = false;
String query = null;
PersistenceDescriptor desc = ((EjbCMPEntityDescriptor) ejbDesc).getPersistenceDescriptor();
for (Iterator it = desc.getQueriedMethods().iterator(); it.hasNext(); ) {
MethodDescriptor method = (MethodDescriptor) it.next();
try {
QueryDescriptor qDesc = desc.getQueryFor(method);
query = qDesc.getQuery();
if (qDesc.getIsEjbQl()) {
Method m = method.getMethod(ejbDesc);
int retypeMapping = mapRetType(qDesc.getReturnTypeMapping());
boolean finder = false;
if ((method.getName()).startsWith("find")) {
finder = true;
retypeMapping = 2;
/*QueryDescriptor.NO_RETURN_TYPE_MAPPING;*/
}
ejbqlDriver.compile(query, m, retypeMapping, finder, ejbDesc.getName());
}
} catch (EJBQLException ex) {
ex.printStackTrace();
if (!hasError) {
hasError = true;
}
result.addErrorDetails(smh.getLocalString(ownerClassName + ".parseError", "Error: [ {0} ] has parsing error(s)", new Object[] { query }));
result.addErrorDetails(smh.getLocalString(ownerClassName + ".SAXParseException", "Exception occured : [{0}]", new Object[] { ex.toString() }));
}
}
if (hasError == false) {
result.addGoodDetails(smh.getLocalString(ownerClassName + ".passed", " Syntax and Semantics of the Queries are correct", new Object[] {}));
}
return hasError;
}
use of org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor in project Payara by payara.
the class HomeInterfaceFindMethodHasQuery method commonToBothInterfaces.
/**
* This method is responsible for the logic of the test. It is called for both local and remote interfaces.
* @param descriptor the Enterprise Java Bean deployment descriptor
* @param home for the Home interface of the Ejb.
* @param methodIntf is the interface type
* @return boolean the results for this assertion i.e if a test has failed or not
*/
private boolean commonToBothInterfaces(String home, EjbDescriptor descriptor, String methodIntf) {
boolean oneFailed = false;
// methods which must throw javax.ejb.FinderException
try {
PersistenceDescriptor pers = ((EjbCMPEntityDescriptor) descriptor).getPersistenceDescriptor();
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(home, false, getVerifierContext().getClassLoader());
Method[] methods = c.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().startsWith("find") && !(methods[i].getName()).equals(FINDBYPRIMARYKEY)) {
QueryDescriptor query = pers.getQueryFor(new MethodDescriptor(methods[i], methodIntf));
if (query != null) {
if (query.getQuery() != null && !"".equals(query.getQuery())) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The [ {0} ] method has a query assigned to it", new Object[] { methods[i].getName() }));
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A [ {0} ] method was found, but did not have a query element assigned", new Object[] { methods[i].getName() }));
}
// end of reporting for this particular 'find' method
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A [ {0} ] method was found, but did not have a query element assigned", new Object[] { methods[i].getName() }));
}
}
// if the home interface found a "find" method
}
// for all the methods within the home interface class, loop
return oneFailed;
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { home, descriptor.getName() }));
return oneFailed;
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor in project Payara by payara.
the class PrimaryKeyClassFieldsCmp method check.
/**
* Enterprise Java Bean primary key class fields subset of the names of
* the container-managed fields test.
*
* The names of the fields in the primary key class must be a subset of the
* names of the container-managed fields. (This allows the container to
* extract the primary key fields from an instance's container-managed fields,
* and vice versa.)
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (descriptor instanceof EjbEntityDescriptor) {
String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) {
// field in entity bean class and this test in notApplicable
try {
FieldDescriptor fd = ((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc();
if (fd != null) {
String pkf = fd.getName();
if (pkf.length() > 0) {
// N/A case
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Entity Bean [ {0} ] with primekey-field non-blank, test not applicable.", new Object[] { descriptor.getEjbClassName() }));
}
} else {
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader());
boolean oneFailed = false;
boolean badField = false;
Field[] fields = c.getDeclaredFields();
Set persistentFields = ((EjbCMPEntityDescriptor) descriptor).getPersistenceDescriptor().getCMPFields();
for (int i = 0; i < fields.length; i++) {
badField = false;
if (EjbUtils.isFieldSubsetOfCMP(fields[i], persistentFields)) {
continue;
} else {
if (!oneFailed) {
oneFailed = true;
}
badField = true;
}
if (badField) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Field [ {0} ] defined within primary key class [ {1} ] is not defined within container managed fields.", new Object[] { fields[i].getName(), ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
}
}
if (!oneFailed) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "This primary key class [ {0} ] has defined all fields which are defined within container managed fields.", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
}
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
} catch (Throwable t) {
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.warning(smh.getLocalString(getClass().getName() + ".warningException", "Warning: [ {0} ] class encountered [ {1} ]. Cannot access fields of class [ {2} ] which is external to [ {3} ].", new Object[] { (descriptor).getEjbClassName(), t.toString(), t.getMessage(), descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri() }));
}
}
} catch (NullPointerException e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: Primkey field not defined within [ {0} ] bean.", new Object[] { descriptor.getName() }));
}
return result;
} else {
// if (BEAN_PERSISTENCE.equals(persistence)
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", new Object[] { EjbEntityDescriptor.CONTAINER_PERSISTENCE, descriptor.getName(), persistence }));
return result;
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected {1} bean, but called with {2}.", new Object[] { getClass(), "Entity", "Session" }));
return result;
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor in project Payara by payara.
the class PrimekeyFieldPersistentFields method check.
/**
* The primkey-field must be one of the fields declared in the cmp-field
* elements.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
// cmp-field elements
if (descriptor instanceof EjbEntityDescriptor) {
String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) {
try {
// do i need to use this to help determine single vs. multiple
// object finders, etc.
String primkey = ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName();
if (primkey.equals("java.lang.String")) {
try {
FieldDescriptor primField = ((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc();
// primField must exist in order to be valid & pass test
Descriptor persistentField;
Field field;
Set persistentFields = ((EjbCMPEntityDescriptor) descriptor).getPersistenceDescriptor().getCMPFields();
Iterator iterator = persistentFields.iterator();
boolean foundMatch = false;
while (iterator.hasNext()) {
persistentField = (Descriptor) iterator.next();
if (primField != null) {
if (primField.getName().equals(persistentField.getName())) {
foundMatch = true;
break;
} else {
continue;
}
} else {
// should already be set, can't ever be in cmp
// fields if primField doesn't exist
foundMatch = false;
break;
}
}
if (foundMatch) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Primary key field [ {0} ] is defined within set of container managed fields for bean [ {1} ]", new Object[] { primField.getName(), descriptor.getName() }));
} else {
if (primField != null) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Primary key field [ {0} ] is not defined within set of container managed fields for bean [ {1} ]", new Object[] { primField.getName(), descriptor.getName() }));
} else {
// not failed
try {
if (((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName().equals("java.lang.Object")) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Primkey field not defined for [ {0} ] bean.", new Object[] { descriptor.getName() }));
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Primary key field is not defined within set of container managed fields for bean [ {0} ]", new Object[] { descriptor.getName() }));
}
} catch (NullPointerException e) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Primkey field not defined for [ {0} ] bean.", new Object[] { descriptor.getName() }));
}
}
}
} catch (NullPointerException e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed2", "Error: Primary Key Field must be defined for bean [ {0} ] with primary key class set to [ {1} ]", new Object[] { descriptor.getName(), primkey }));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable3", "primkey [ {0} ] is not java.lang.String for bean [ {1} ]", new Object[] { primkey, descriptor.getName() }));
}
} catch (NullPointerException e) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Primkey field not defined for [ {0} ] bean.", new Object[] { descriptor.getName() }));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence", new Object[] { EjbEntityDescriptor.CONTAINER_PERSISTENCE, descriptor.getName(), persistence }));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected \n {1} bean, but called with {2} bean", new Object[] { getClass(), "Entity", "Session" }));
}
return result;
}
Aggregations