use of com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException in project Payara by payara.
the class ASCmpMappingTest method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
try {
if (descriptor instanceof IASEjbCMPEntityDescriptor) {
Collection col = null;
if (getVerifierContext().getJDOException() != null) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error: Exception [ {0} ] while initializing JDOCodeGenerator. Please check your descriptors and mapping files for consistency ", new Object[] { getVerifierContext().getJDOException().getMessage() }));
return result;
} else {
try {
JDOCodeGenerator jdc = getVerifierContext().getJDOCodeGenerator();
col = jdc.validate((IASEjbCMPEntityDescriptor) descriptor);
} catch (Exception ex) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().", new Object[] { ex.getMessage() }));
return result;
}
}
if (col.isEmpty()) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "The mappings for the cmp beans (if any) are correct."));
} else {
// collect all the cmpmapping related errors
String allErrors = null;
Iterator it = col.iterator();
while (it.hasNext()) {
Exception e = (Exception) it.next();
if (!(e instanceof EJBQLException)) {
allErrors = e.getMessage() + "\n\n";
}
}
if (allErrors != null) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".parseError", "Error: Entity bean [ {0} ] has the following error(s) [ {1} ].", new Object[] { descriptor.getEjbClassName(), "\n" + allErrors }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "The mappings for the cmp beans (if any) are correct."));
}
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "Not applicable: Test only applies to container managed EJBs"));
}
} catch (Exception e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().", new Object[] { e.getMessage() }));
}
return result;
}
use of com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException in project Payara by payara.
the class JDOCodeGenerator method generate.
/**
* @see CMPGenerator#generate(IASEjbCMPEntityDescriptor, File, File)
*/
public void generate(IASEjbCMPEntityDescriptor ejbcmp, File srcout, File classout) throws GeneratorException {
String beanName = ejbcmp.getName();
// StringBuilder to store validation exception messages if there are any.
// If there are no validation exceptions, the reference will be null.
StringBuilder validateex = null;
boolean debug = logger.isLoggable(Logger.FINE);
if (debug)
// NOI18N
logger.fine("gen file in " + srcout.getAbsolutePath());
// We need to create a new ArrayList because model validation
// returns an unmodifiable list. This may be a place to look
// for a performance improvement later for the case of empty
// or singleton collection (extra copies).
Collection c = new ArrayList(validateModel(ejbcmp));
// if the mapping info is not present, throw the exception and
// stop the generation process
GeneratorException mappingMissingEx = getMappingMissingException(c);
if (mappingMissingEx != null)
throw mappingMissingEx;
c.addAll(validateSupported(ejbcmp));
JDOConcreteBeanGenerator cmpGenerator = getCMPGenerator(ejbcmp);
MethodHelper mh = new MethodHelper(ejbcmp);
c.addAll(cmpGenerator.validate(mh, beanName));
if (!c.isEmpty()) {
// Validation failed the test. We will try to display all the
// exceptions in a concatenated message and a GeneratorException
// is thrown.
validateex = new StringBuilder();
Iterator iter = c.iterator();
while (iter.hasNext()) {
Exception ex = (Exception) iter.next();
if (debug)
// NOI18N
logger.log(Logger.FINE, "validation exception: ", ex);
// NOI18N
validateex.append(ex.getMessage()).append('\n');
}
if (!ignoreValidationResults)
throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
"CMG.ExceptionInValidate", beanName, bundle, validateex.toString());
}
try {
Collection<File> newfiles = null;
if (!ejbcmp.isEJB20())
ejbcmp.setQueryParser(jdoqlParamDeclParser);
// IMPORTANT:
// Concrete impl class generation must happen before generation of
// PC class as cmpGenerator will override cascadeDelete (DeleteAction)
// property if it is set, and generatePC() saves .mapping file.
newfiles = cmpGenerator.generate(mh, beanName, appName, srcout, classout);
files.addAll(newfiles);
newfiles = generatePC(ejbcmp, srcout, classout);
files.addAll(newfiles);
if (validateex != null)
throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
"CMG.ExceptionInValidate", beanName, bundle, validateex.toString());
} catch (JDOUserException e) {
// messages if there are any.
throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
"CMG.ExceptionInGenerate", beanName, bundle, e, validateex);
} catch (EJBQLException e) {
// validation messages if there are any.
throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
"CMG.ExceptionInGenerate", beanName, bundle, e, validateex);
} catch (IOException e) {
// validation messages if there are any.
throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
"CMG.IOExceptionInGenerate", beanName, bundle, e, validateex);
}
}
use of com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException 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 com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException in project Payara by payara.
the class EjbQLFromCmpEntityDescriptor method check.
/**
* Implements the check on EJB QL's syntax and semantics.
*
* @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();
try {
if (descriptor instanceof IASEjbCMPEntityDescriptor) {
Collection col = null;
if (getVerifierContext().getJDOException() != null) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error: Exception [ {0} ] while initialising JDO code generator.", new Object[] { getVerifierContext().getJDOException().getMessage() }));
return result;
} else {
try {
JDOCodeGenerator jdc = getVerifierContext().getJDOCodeGenerator();
col = jdc.validate((IASEjbCMPEntityDescriptor) descriptor);
} catch (Exception ex) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().", new Object[] { ex.getMessage() }));
return result;
}
}
if (col.isEmpty()) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Syntax and Semantics of EJBQL Queries (if any) are correct."));
} else {
// collect all the EJBQL errors
String allErrors = null;
Iterator it = col.iterator();
while (it.hasNext()) {
Exception e = (Exception) it.next();
if (e instanceof EJBQLException) {
allErrors = e.getMessage() + "\n\n";
}
}
if (allErrors != null) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".parseError", "Error: Entity bean [ {0} ] has the following EJBQL error(s) [ {1} ].", new Object[] { descriptor.getEjbClassName(), "\n" + allErrors }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Syntax and Semantics of EJBQL Queries (if any) are correct."));
}
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "Not applicable: Test only applies to container managed EJBs"));
}
} catch (Exception e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().", new Object[] { e.getMessage() }));
}
return result;
}
use of com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException in project Payara by payara.
the class JDOConcreteBean20Generator method validateEJBQL.
/**
* Validate EJBQL for ejbFind and ejbSelect methods by calling compilation.
* The method stores compilation results in the {@link #jdoqlElementsMap} map.
* This method is called only for CMP 2.x beans as there is no validation of
* CMP 1.1 queries at the deployment time.
* @param methodHelper the AbstractMethodHelper instance that contains
* all categorized methods and some other convenience methods for this bean.
* @return a Collection of found exceptions.
*/
private Collection validateEJBQL(AbstractMethodHelper methodHelper) {
Collection rc = new ArrayList();
jdoqlElementsMap = new HashMap();
List methods = new ArrayList(methodHelper.getFinders());
methods.addAll(methodHelper.getSelectors());
for (int i = 0; i < methods.size(); i++) {
Method m = (Method) methods.get(i);
String mname = m.getName();
if (mname.equals(CMP20TemplateFormatter.findByPrimaryKey_)) {
// No EJBQL is defined for findByPrimaryKey.
continue;
}
try {
// EJBQLC needs to know if we are processing a finder or a selector.
jdoqlElementsMap.put(m, ejbqlc.compile(methodHelper.getQueryString(m), m, methodHelper.getQueryReturnType(m), mname.startsWith(CMP20TemplateFormatter.find_), beanName));
} catch (EJBQLException e) {
rc.add(e);
}
}
return rc;
}
Aggregations