Search in sources :

Example 76 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class ContainerTransactionNode method writeDescriptor.

/**
 * write the descriptor class to a DOM tree and return it
 *
 * @param parent node in the DOM tree
 * @param nodeName name for the root element of this xml fragment
 * @param ejb the descriptor to write
 * @return the DOM tree top node
 */
public Node writeDescriptor(Node parent, String nodeName, EjbDescriptor ejb) {
    Map methodToTransactions = ejb.getMethodContainerTransactions();
    MethodNode mn = new MethodNode();
    for (Object o : methodToTransactions.entrySet()) {
        Map.Entry entry = (Map.Entry) o;
        MethodDescriptor md = (MethodDescriptor) entry.getKey();
        Node ctNode = super.writeDescriptor(parent, nodeName, ejb);
        ContainerTransaction ct = (ContainerTransaction) entry.getValue();
        appendTextChild(ctNode, EjbTagNames.DESCRIPTION, ct.getDescription());
        mn.writeDescriptor(ctNode, EjbTagNames.METHOD, md, ejb.getName());
        appendTextChild(ctNode, EjbTagNames.TRANSACTION_ATTRIBUTE, ct.getTransactionAttribute());
    }
    return null;
}
Also used : MethodNode(com.sun.enterprise.deployment.node.MethodNode) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) MethodNode(com.sun.enterprise.deployment.node.MethodNode) DeploymentDescriptorNode(com.sun.enterprise.deployment.node.DeploymentDescriptorNode) Node(org.w3c.dom.Node) Map(java.util.Map) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 77 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor 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 78 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class HasValidEjbTimeoutDescriptor method check.

/**
 * Run a verifier test to check the transaction attributes of the
 * ejbTimeout method. The allowed attributes are -
 * RequiresNew or NotSupported.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor.isTimedObject()) {
        if (descriptor.getTransactionType().equals(EjbDescriptor.CONTAINER_TRANSACTION_TYPE)) {
            MethodDescriptor methodDesc = descriptor.getEjbTimeoutMethod();
            ContainerTransaction txAttr = descriptor.getContainerTransactionFor(methodDesc);
            String version = getVerifierContext().getJavaEEVersion();
            if (txAttr != null) {
                String ta = txAttr.getTransactionAttribute();
                if ((version.compareTo(SpecVersionMapper.JavaEEVersion_5) >= 0) && !(ContainerTransaction.REQUIRES_NEW.equals(ta) || ContainerTransaction.NOT_SUPPORTED.equals(ta) || ContainerTransaction.REQUIRED.equals(ta))) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error : Bean [ {0} ] Transaction attribute for timeout method" + "must be Required, RequiresNew or NotSupported", new Object[] { descriptor.getName() }));
                } else if ((version.compareTo(SpecVersionMapper.JavaEEVersion_5) < 0) && !(ContainerTransaction.REQUIRES_NEW.equals(ta) || ContainerTransaction.NOT_SUPPORTED.equals(ta))) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed2", "Error : Bean [ {0} ] Transaction attribute for ejbTimeout " + "must be RequiresNew or NotSupported", new Object[] { descriptor.getName() }));
                }
            } else if (version.compareTo(SpecVersionMapper.JavaEEVersion_5) < 0) {
                // Transaction attribute for ejbTimeout not specified in the DD
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failed3", "Transaction attribute for Timeout is not specified for [ {0} ]", new Object[] { descriptor.getName() }));
            }
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Transaction attributes are properly specified"));
    }
    return result;
}
Also used : ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 79 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor 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 80 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor 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)97 Method (java.lang.reflect.Method)37 Iterator (java.util.Iterator)25 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)23 Set (java.util.Set)18 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)17 Enumeration (java.util.Enumeration)16 ArrayList (java.util.ArrayList)12 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)11 MethodPermission (com.sun.enterprise.deployment.MethodPermission)10 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)10 Result (com.sun.enterprise.tools.verifier.Result)9 HashSet (java.util.HashSet)9 Vector (java.util.Vector)7 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)7 MethodNode (com.sun.enterprise.deployment.node.MethodNode)6 Collection (java.util.Collection)6 HashMap (java.util.HashMap)6 ScheduledTimerDescriptor (org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor)6