Search in sources :

Example 6 with PersistenceDescriptor

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

the class NameMapper method initGeneratedRelationshipMaps.

private void initGeneratedRelationshipMaps() {
    EjbBundleDescriptorImpl bundleDescriptor = getBundleDescriptor();
    Set relationships = bundleDescriptor.getRelationships();
    _generatedRelToInverseRelMap = new HashMap();
    _relToInverseGeneratedRelMap = new HashMap();
    // null check
    if (relationships != null) {
        Iterator iterator = relationships.iterator();
        List generatedRels = new ArrayList();
        int counter = 0;
        // gather list of generated cmr fields by examining source and sink
        while (iterator.hasNext()) {
            RelationshipDescriptor relationship = (RelationshipDescriptor) iterator.next();
            if (relationship.getSource().getCMRField() == null)
                generatedRels.add(relationship);
            if (relationship.getSink().getCMRField() == null)
                generatedRels.add(relationship);
        }
        // now update the maps to contain this info
        iterator = generatedRels.iterator();
        while (iterator.hasNext()) {
            RelationshipDescriptor relationship = (RelationshipDescriptor) iterator.next();
            RelationRoleDescriptor source = relationship.getSource();
            String sourceEjbName = source.getOwner().getName();
            String sourceCMRField = source.getCMRField();
            boolean sourceIsNull = (sourceCMRField == null);
            RelationRoleDescriptor sink = relationship.getSink();
            String sinkEjbName = sink.getOwner().getName();
            String ejbName = (sourceIsNull ? sourceEjbName : sinkEjbName);
            String otherEjbName = (sourceIsNull ? sinkEjbName : sourceEjbName);
            List ejbField = Arrays.asList(new String[] { otherEjbName, (sourceIsNull ? sink.getCMRField() : sourceCMRField) });
            PersistenceDescriptor pDescriptor = ((EjbCMPEntityDescriptor) bundleDescriptor.getEjbByName(ejbName)).getPersistenceDescriptor();
            List generatedField = null;
            String uniqueName = null;
            // with this name
            do {
                counter++;
                uniqueName = GENERATED_CMR_FIELD_PREFIX + counter;
            } while (hasField(pDescriptor, uniqueName));
            generatedField = Arrays.asList(new String[] { ejbName, uniqueName });
            _generatedRelToInverseRelMap.put(generatedField, ejbField);
            _relToInverseGeneratedRelMap.put(ejbField, generatedField);
        }
    }
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RelationshipDescriptor(org.glassfish.ejb.deployment.descriptor.RelationshipDescriptor) RelationRoleDescriptor(org.glassfish.ejb.deployment.descriptor.RelationRoleDescriptor) PersistenceDescriptor(org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 7 with PersistenceDescriptor

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

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

EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)8 PersistenceDescriptor (org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor)8 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)4 Iterator (java.util.Iterator)4 Set (java.util.Set)3 QueryDescriptor (org.glassfish.ejb.deployment.descriptor.QueryDescriptor)3 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)2 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)2 EjbReference (com.sun.enterprise.deployment.types.EjbReference)2 MessageDestinationReferencer (com.sun.enterprise.deployment.types.MessageDestinationReferencer)2 Method (java.lang.reflect.Method)2 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)1 InjectionCapable (com.sun.enterprise.deployment.InjectionCapable)1 MethodPermission (com.sun.enterprise.deployment.MethodPermission)1 RoleReference (com.sun.enterprise.deployment.RoleReference)1 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)1 Result (com.sun.enterprise.tools.verifier.Result)1 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)1 EJBQLException (com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException)1 Serializable (java.io.Serializable)1