FileDocCategorySizeDatePackage
EjbQLChecker.javaAPI DocGlassfish v2 API5734Fri May 04 22:33:48 BST 2007com.sun.enterprise.tools.verifier.tests.ejb.entity.ejbql

EjbQLChecker

public class EjbQLChecker extends Object
This class contains tests for EJB QLs that are shared by tests for entity beans and for depenent objects.
author
Qingqing Ouyang
version

Fields Summary
protected static final com.sun.enterprise.util.LocalStringManagerImpl
smh

helper property to get to the localized strings

Constructors Summary
Methods Summary
public static booleancheckSyntax(com.sun.enterprise.deployment.EjbDescriptor ejbDesc, com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLC ejbqlDriver, com.sun.enterprise.tools.verifier.Result result, java.lang.String ownerClassName)
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.

    
                                                            
          
                  
        
        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;
    
private static intmapRetType(int rettype)


    switch(rettype) {

    case 0 : return 2;
    case 1 : return 0;
    case 2 : return 1;
    default: return 2;
         
    }