Search in sources :

Example 1 with EJBQLException

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;
}
Also used : IASEjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor) JDOCodeGenerator(com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator) Iterator(java.util.Iterator) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) Collection(java.util.Collection) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) Result(com.sun.enterprise.tools.verifier.Result)

Example 2 with EJBQLException

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);
    }
}
Also used : EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) ModelException(com.sun.jdo.api.persistence.model.ModelException) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) SQLException(java.sql.SQLException) DBException(org.netbeans.modules.dbschema.DBException) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) Schema2BeansException(org.netbeans.modules.schema2beans.Schema2BeansException) GeneratorException(com.sun.jdo.spi.persistence.support.ejb.codegen.GeneratorException) ConversionException(com.sun.jdo.api.persistence.mapping.ejb.ConversionException) GeneratorException(com.sun.jdo.spi.persistence.support.ejb.codegen.GeneratorException)

Example 3 with EJBQLException

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;
}
Also used : PersistenceDescriptor(org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor) QueryDescriptor(org.glassfish.ejb.deployment.descriptor.QueryDescriptor) Iterator(java.util.Iterator) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) Method(java.lang.reflect.Method) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 4 with EJBQLException

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;
}
Also used : IASEjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor) JDOCodeGenerator(com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator) Iterator(java.util.Iterator) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) Collection(java.util.Collection) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) Result(com.sun.enterprise.tools.verifier.Result)

Example 5 with EJBQLException

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;
}
Also used : EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) Method(java.lang.reflect.Method)

Aggregations

EJBQLException (com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException)5 Iterator (java.util.Iterator)3 Result (com.sun.enterprise.tools.verifier.Result)2 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)2 JDOCodeGenerator (com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator)2 Method (java.lang.reflect.Method)2 Collection (java.util.Collection)2 IASEjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor)2 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)1 ConversionException (com.sun.jdo.api.persistence.mapping.ejb.ConversionException)1 ModelException (com.sun.jdo.api.persistence.model.ModelException)1 JDOUserException (com.sun.jdo.api.persistence.support.JDOUserException)1 GeneratorException (com.sun.jdo.spi.persistence.support.ejb.codegen.GeneratorException)1 SQLException (java.sql.SQLException)1 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)1 PersistenceDescriptor (org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor)1 QueryDescriptor (org.glassfish.ejb.deployment.descriptor.QueryDescriptor)1 DBException (org.netbeans.modules.dbschema.DBException)1 Schema2BeansException (org.netbeans.modules.schema2beans.Schema2BeansException)1