Search in sources :

Example 1 with QueryDescriptor

use of org.glassfish.ejb.deployment.descriptor.QueryDescriptor in project Payara by payara.

the class SelectMethodQL method runIndividualSelectTest.

/**
 * <p>
 * run an individual test against a declared ejbSelect method
 * </p>
 *
 * @param m is the ejbSelect method
 * @param descriptor is the entity declaring the ejbSelect
 * @param result is where to put the result
 *
 * @return true if the test passes
 */
protected boolean runIndividualSelectTest(Method m, EjbCMPEntityDescriptor descriptor, Result result) {
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // We don't use getQueryFor to free ourselfves from classloader issues.
    Set set = descriptor.getPersistenceDescriptor().getQueriedMethods();
    Iterator iterator = set.iterator();
    while (iterator.hasNext()) {
        MethodDescriptor queryMethod = (MethodDescriptor) iterator.next();
        if (queryMethod.getName().equals(m.getName())) {
            Class[] mParms = m.getParameterTypes();
            String[] queryParms = queryMethod.getParameterClassNames();
            if (queryParms != null) {
                if (queryParms.length == mParms.length) {
                    boolean same = true;
                    for (int i = 0; i < mParms.length; i++) {
                        if (!mParms[i].getName().equals(queryParms[i]))
                            same = false;
                    }
                    if (same) {
                        QueryDescriptor qd = descriptor.getPersistenceDescriptor().getQueryFor(queryMethod);
                        String query = qd.getQuery();
                        if (query == null && qd.getSQL() == null) {
                            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.failed2", "Error : [ {0} ] EJB-QL query and description are null", new Object[] { m.getName() }));
                            return false;
                        } else {
                            if (query == null) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.passed1", "Description for [ {0} ] is provided", new Object[] { m.getName() }));
                                return true;
                            }
                            if (query.toUpperCase().indexOf("SELECT") == -1) {
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.failed2", "Error : EJB-QL query for method [ {0}  is null", new Object[] { m.getName() }));
                                return false;
                            } else {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.passed2", "EJB-QL query for [ {0} ] is correct", new Object[] { m.getName() }));
                                return true;
                            }
                        }
                    }
                }
            } else if (mParms.length == 0) {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.passed3", "No EJB-QL query found", new Object[] {}));
                return true;
            } else {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.failed2", "Error : EJB-QL query for method [ {0}  is null", new Object[] { m.getName() }));
                return false;
            }
        }
    }
    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
    result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.failed1", "Error : [ {0} ] does not have a XML query element associated", new Object[] { m.getName() }));
    return false;
}
Also used : QueryDescriptor(org.glassfish.ejb.deployment.descriptor.QueryDescriptor) Set(java.util.Set) Iterator(java.util.Iterator) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 2 with QueryDescriptor

use of org.glassfish.ejb.deployment.descriptor.QueryDescriptor in project Payara by payara.

the class EjbBundleTracerVisitor method accept.

protected void accept(EjbDescriptor ejb) {
    logInfo("==================");
    logInfo(ejb.getType() + " Bean " + ejb.getName());
    logInfo("\thomeClassName " + ejb.getHomeClassName());
    logInfo("\tremoteClassName " + ejb.getRemoteClassName());
    logInfo("\tlocalhomeClassName " + ejb.getLocalHomeClassName());
    logInfo("\tlocalClassName " + ejb.getLocalClassName());
    logInfo("\tremoteBusinessIntfs " + ejb.getRemoteBusinessClassNames());
    logInfo("\tlocalBusinessIntfs " + ejb.getLocalBusinessClassNames());
    logInfo("\tjndiName " + ejb.getJndiName());
    logInfo("\tejbClassName " + ejb.getEjbClassName());
    logInfo("\ttransactionType " + ejb.getTransactionType());
    if (ejb.getUsesCallerIdentity() == false) {
        logInfo("\trun-as role " + ejb.getRunAsIdentity());
    } else {
        logInfo("\tuse-caller-identity " + ejb.getUsesCallerIdentity());
    }
    for (EjbReference aRef : ejb.getEjbReferenceDescriptors()) {
        accept(aRef);
    }
    for (Iterator e = ejb.getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext(); ) {
        MethodPermission mp = (MethodPermission) e.next();
        Set methods = (Set) ejb.getPermissionedMethodsByPermission().get(mp);
        accept(mp, methods);
    }
    if (ejb.getStyledPermissionedMethodsByPermission() != null) {
        for (Iterator e = ejb.getStyledPermissionedMethodsByPermission().keySet().iterator(); e.hasNext(); ) {
            MethodPermission mp = (MethodPermission) e.next();
            Set methods = (Set) ejb.getStyledPermissionedMethodsByPermission().get(mp);
            accept(mp, methods);
        }
    }
    for (RoleReference roleRef : ejb.getRoleReferences()) {
        accept(roleRef);
    }
    for (Iterator e = ejb.getMethodContainerTransactions().keySet().iterator(); e.hasNext(); ) {
        MethodDescriptor md = (MethodDescriptor) e.next();
        ContainerTransaction ct = (ContainerTransaction) ejb.getMethodContainerTransactions().get(md);
        accept(md, ct);
    }
    for (EnvironmentProperty envProp : ejb.getEnvironmentProperties()) {
        accept(envProp);
    }
    for (ResourceReferenceDescriptor next : ejb.getResourceReferenceDescriptors()) {
        accept(next);
    }
    for (ResourceEnvReferenceDescriptor next : ejb.getResourceEnvReferenceDescriptors()) {
        accept(next);
    }
    for (MessageDestinationReferencer next : ejb.getMessageDestinationReferenceDescriptors()) {
        accept(next);
    }
    // referencer as well.
    if (ejb.getType().equals(EjbMessageBeanDescriptor.TYPE)) {
        MessageDestinationReferencer msgDestReferencer = (MessageDestinationReferencer) ejb;
        if (msgDestReferencer.getMessageDestinationLinkName() != null) {
            accept(msgDestReferencer);
        }
    }
    for (ServiceReferenceDescriptor sref : ejb.getServiceReferenceDescriptors()) {
        accept(sref);
    }
    if (ejb instanceof EjbCMPEntityDescriptor) {
        EjbCMPEntityDescriptor cmp = (EjbCMPEntityDescriptor) ejb;
        PersistenceDescriptor persistenceDesc = cmp.getPersistenceDescriptor();
        for (Object fd : persistenceDesc.getCMPFields()) {
            accept((FieldDescriptor) fd);
        }
        for (Object o : persistenceDesc.getQueriedMethods()) {
            if (o instanceof MethodDescriptor) {
                QueryDescriptor qd = persistenceDesc.getQueryFor((MethodDescriptor) o);
                accept(qd);
            }
        }
    }
}
Also used : Set(java.util.Set) ServiceReferenceDescriptor(com.sun.enterprise.deployment.ServiceReferenceDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) MethodPermission(com.sun.enterprise.deployment.MethodPermission) EjbReference(com.sun.enterprise.deployment.types.EjbReference) PersistenceDescriptor(org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor) MessageDestinationReferencer(com.sun.enterprise.deployment.types.MessageDestinationReferencer) QueryDescriptor(org.glassfish.ejb.deployment.descriptor.QueryDescriptor) RoleReference(com.sun.enterprise.deployment.RoleReference) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) Iterator(java.util.Iterator) ResourceEnvReferenceDescriptor(com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)

Example 3 with QueryDescriptor

use of org.glassfish.ejb.deployment.descriptor.QueryDescriptor in project Payara by payara.

the class MethodHelper method isQueryPrefetchEnabled.

/**
 * Returns <code>true</code> if prefetch is enabled for the specified
 * method, <code>false</code> otherwise. Prefetch is enabled by default.
 * @param method the java.lang.reflect.Method object used to find the
 * prefetch setting.
 * @return a boolean representing the prefetch setting
 */
public boolean isQueryPrefetchEnabled(Method method) {
    boolean enabled = true;
    QueryDescriptor queryDescriptor = getQueryDescriptor(method);
    if (queryDescriptor != null) {
        IASEjbCMPEntityDescriptor cmpDescriptor = (IASEjbCMPEntityDescriptor) getDescriptor();
        PrefetchDisabledDescriptor pdDescriptor = cmpDescriptor.getPrefetchDisabledDescriptor();
        if (pdDescriptor != null) {
            MethodDescriptor methodDescriptor = queryDescriptor.getQueryMethodDescriptor();
            enabled = !pdDescriptor.isPrefetchDisabledFor(methodDescriptor);
        }
    }
    return enabled;
}
Also used : IASEjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor) PrefetchDisabledDescriptor(org.glassfish.ejb.deployment.descriptor.runtime.PrefetchDisabledDescriptor) QueryDescriptor(org.glassfish.ejb.deployment.descriptor.QueryDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 4 with QueryDescriptor

use of org.glassfish.ejb.deployment.descriptor.QueryDescriptor 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 5 with QueryDescriptor

use of org.glassfish.ejb.deployment.descriptor.QueryDescriptor 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;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) PersistenceDescriptor(org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor) QueryDescriptor(org.glassfish.ejb.deployment.descriptor.QueryDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)

Aggregations

MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)5 QueryDescriptor (org.glassfish.ejb.deployment.descriptor.QueryDescriptor)5 Iterator (java.util.Iterator)3 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)3 PersistenceDescriptor (org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor)3 Method (java.lang.reflect.Method)2 Set (java.util.Set)2 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)1 MethodPermission (com.sun.enterprise.deployment.MethodPermission)1 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)1 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)1 RoleReference (com.sun.enterprise.deployment.RoleReference)1 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)1 EjbReference (com.sun.enterprise.deployment.types.EjbReference)1 MessageDestinationReferencer (com.sun.enterprise.deployment.types.MessageDestinationReferencer)1 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)1 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)1 EJBQLException (com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException)1 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)1 IASEjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor)1