Search in sources :

Example 1 with NameMapper

use of com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper in project Payara by payara.

the class DeploymentDescriptorModel method getField.

/**
 * Returns a wrapped field element for the specified fieldName in the
 * class with the specified className.  If the specified className
 * represents a persistence-capable class, a field representing the
 * field in the abstract bean class for the corresponding ejb is always
 * returned (even if there is a Field object available for the
 * persistence-capable).  If there is an ejb name and an abstract bean
 * class with the same name, the abstract bean class which is associated
 * with the ejb will be used, not the abstract bean class which
 * corresponds to the supplied name (directly).
 * @param className the fully qualified name of the class which contains
 * the field to be checked
 * @param fieldName the name of the field to be checked
 * @return the wrapped field element for the specified fieldName
 */
public Object getField(final String className, String fieldName) {
    String testClass = className;
    Object returnObject = null;
    if (className != null) {
        NameMapper nameMapper = getNameMapper();
        boolean isPCClass = isPCClassName(className);
        boolean isPKClassName = false;
        String searchClassName = className;
        String searchFieldName = fieldName;
        // ejb name's abstract bean equivalents if necessary
        if (isPCClass) {
            searchFieldName = nameMapper.getEjbFieldForPersistenceField(className, fieldName);
            searchClassName = getEjbName(className);
        } else // check if it's a pk class without a user defined key class
        {
            String ejbName = nameMapper.getEjbNameForPersistenceKeyClass(className);
            switch(getPersistenceKeyClassType(className)) {
                // abstract bean (translated below from ejbName)
                case NameMapper.PRIMARY_KEY_FIELD:
                    testClass = ejbName;
                    searchClassName = ejbName;
                    isPKClassName = true;
                    break;
                // code, so we configure it here
                case NameMapper.UNKNOWN_KEY_CLASS:
                    testClass = nameMapper.getPersistenceClassForEjbName(ejbName);
                    isPCClass = true;
                    isPKClassName = true;
                    break;
            }
        }
        if (nameMapper.isEjbName(searchClassName)) {
            searchClassName = nameMapper.getAbstractBeanClassForEjbName(searchClassName);
        }
        returnObject = super.getField(searchClassName, searchFieldName);
        if (// try getting it from the descriptor
        returnObject == null)
            returnObject = getFieldWrapper(testClass, searchFieldName);
        else if (// wrap it
        returnObject instanceof Field)
            returnObject = new MemberWrapper((Field) returnObject);
        if (isPCClass) {
            returnObject = updateFieldWrapper((MemberWrapper) returnObject, testClass, fieldName);
        }
        // public modifier which will be generated in the inner class
        if (isPKClassName && (returnObject instanceof MemberWrapper))
            ((MemberWrapper) returnObject)._modifiers = Modifier.PUBLIC;
    }
    return returnObject;
}
Also used : Field(java.lang.reflect.Field) NameMapper(com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper)

Example 2 with NameMapper

use of com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper in project Payara by payara.

the class DeploymentDescriptorModel method getPersistenceKeyClassType.

private int getPersistenceKeyClassType(String className) {
    int returnValue = -1;
    if (getCMPDescriptor(className) == null) {
        NameMapper nameMapper = getNameMapper();
        String ejbName = nameMapper.getEjbNameForPersistenceKeyClass(className);
        if (ejbName != null)
            returnValue = nameMapper.getKeyClassTypeForEjbName(ejbName);
    }
    return returnValue;
}
Also used : NameMapper(com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper)

Example 3 with NameMapper

use of com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper in project Payara by payara.

the class DeploymentDescriptorModel method getFieldType.

/**
 * Returns the field type for the specified fieldName in the class
 * with the specified className.  This method is overrides the one in
 * Model in order to do special handling for non-collection relationship
 * fields.  If it's a generated relationship that case, the returned
 * MemberWrapper from getField contains a type of the abstract bean and
 * it's impossible to convert that into the persistence capable class name, so here
 * that case is detected, and if found, the ejb name is extracted and
 * used to find the corresponding persistence capable class.  For a
 * relationship which is of type of the local interface, we do the
 * conversion from local interface to persistence-capable class.  In the
 * case of a collection relationship (generated or not), the superclass'
 * implementation which provides the java type is sufficient.
 * @param className the fully qualified name of the class which contains
 * the field to be checked
 * @param fieldName the name of the field to be checked
 * @return the field type for the specified fieldName
 */
public String getFieldType(String className, String fieldName) {
    String returnType = super.getFieldType(className, fieldName);
    if (!isCollection(returnType) && isPCClassName(className)) {
        NameMapper nameMapper = getNameMapper();
        String ejbName = nameMapper.getEjbNameForPersistenceClass(className);
        String ejbField = nameMapper.getEjbFieldForPersistenceField(className, fieldName);
        if (nameMapper.isGeneratedEjbRelationship(ejbName, ejbField)) {
            String[] inverse = nameMapper.getEjbFieldForGeneratedField(ejbName, ejbField);
            returnType = nameMapper.getPersistenceClassForEjbName(inverse[0]);
        }
        if (nameMapper.isLocalInterface(returnType)) {
            returnType = nameMapper.getPersistenceClassForLocalInterface(className, fieldName, returnType);
        }
    }
    return returnType;
}
Also used : NameMapper(com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper)

Example 4 with NameMapper

use of com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper in project Payara by payara.

the class DeploymentDescriptorModel method getClass.

/**
 * Returns the class element with the specified className.  If the
 * specified className represents a persistence-capable class, the
 * abstract bean class for the corresponding ejb is always returned
 * (even if there is a Class object available for the
 * persistence-capable).  If there is an ejb name and an abstract bean
 * class with the same name, the abstract bean class which is associated
 * with the ejb will be returned, not the abstract bean class which
 * corresponds to the supplied name (directly).  If the specified
 * className represents a persistence-capable key class name, the
 * corresponding bean's key class is returned.
 * @param className the fully qualified name of the class to be checked
 * @param classLoader the class loader used to find mapping information
 * @return the class element for the specified className
 */
public Object getClass(final String className, final ClassLoader classLoader) {
    String testClass = className;
    // bean or key class if necessary
    if (className != null) {
        NameMapper nameMapper = getNameMapper();
        String ejbName = (isPCClassName(className) ? getEjbName(className) : className);
        if (nameMapper.isEjbName(ejbName))
            testClass = nameMapper.getAbstractBeanClassForEjbName(ejbName);
        else {
            String keyClass = nameMapper.getKeyClassForPersistenceKeyClass(className);
            if (keyClass != null) {
                // dummy class
                if (NameMapper.PRIMARY_KEY_FIELD == getPersistenceKeyClassType(className)) {
                    if (isPrimitive(keyClass))
                        return JavaTypeHelper.getPrimitiveClass(keyClass);
                    if (isByteArray(keyClass) || keyClass.endsWith("[]"))
                        return byte[].class;
                }
                testClass = keyClass;
            }
        }
    }
    return super.getClass(testClass, getClassLoader());
}
Also used : NameMapper(com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper)

Example 5 with NameMapper

use of com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper in project Payara by payara.

the class DeploymentDescriptorModel method updateFieldWrapper.

private MemberWrapper updateFieldWrapper(MemberWrapper returnObject, String className, String fieldName) {
    NameMapper nameMapper = getNameMapper();
    if (returnObject == null) {
        // can't call isPersistent or isKey because that calls
        // hasField which calls getField and that would end up
        // in an endless loop
        PersistenceFieldElement field = getPersistenceFieldInternal(className, fieldName);
        if (field != null) {
            String ejbName = getEjbName(className);
            String ejbFieldName = nameMapper.getEjbFieldForPersistenceField(className, fieldName);
            // support.  If so, return a private field of type Long.
            if (field.isKey() && (ejbName != null) && (nameMapper.getKeyClassTypeForEjbName(ejbName) == NameMapper.UNKNOWN_KEY_CLASS)) {
                returnObject = new MemberWrapper(ejbFieldName, Long.class, Modifier.PRIVATE, (Class) getClass(className));
            } else // cardinality of the relationship.
            if ((field instanceof RelationshipElement) && nameMapper.isGeneratedEjbRelationship(ejbName, ejbFieldName)) {
                RelationshipElement rel = (RelationshipElement) field;
                Class classType = null;
                // figure out the type
                if (rel.getUpperBound() > 1)
                    classType = java.util.HashSet.class;
                else {
                    String[] inverse = nameMapper.getEjbFieldForGeneratedField(ejbName, ejbFieldName);
                    classType = (Class) getClass(inverse[0]);
                }
                if (classType != null) {
                    returnObject = new MemberWrapper(ejbFieldName, classType, Modifier.PRIVATE, (Class) getClass(className));
                }
            } else // If so, return a private field of type long.
            if (ejbFieldName.startsWith(NameMapper.GENERATED_VERSION_FIELD_PREFIX) && nameMapper.isGeneratedField(ejbName, ejbFieldName)) {
                returnObject = new MemberWrapper(ejbFieldName, Long.TYPE, Modifier.PRIVATE, (Class) getClass(className));
            }
        }
    }
    // non-primitive, non-wrapper type, convert it to byte[] here
    if (!isPersistentTypeAllowed(getType(returnObject), getClassLoader()) && isSerializable(returnObject)) {
        returnObject.setType(byte[].class);
    }
    return returnObject;
}
Also used : NameMapper(com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper) RelationshipElement(com.sun.jdo.api.persistence.model.jdo.RelationshipElement) PersistenceFieldElement(com.sun.jdo.api.persistence.model.jdo.PersistenceFieldElement)

Aggregations

NameMapper (com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper)6 PersistenceFieldElement (com.sun.jdo.api.persistence.model.jdo.PersistenceFieldElement)2 RelationshipElement (com.sun.jdo.api.persistence.model.jdo.RelationshipElement)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)1 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)1