Search in sources :

Example 1 with Transient

use of org.apache.openejb.jee.jpa.Transient in project tomee by apache.

the class CmpJpaConversion method mapFields.

/**
 * Build a mapping between a bean's CMP fields and the
 * particular subclass in the inheritance hierarchy that
 * defines the field.
 *
 * @param clazz            The bean implementation class.
 * @param persistantFields The set of container-managed fields.
 * @return A map of fieldname-to-defining class relationships.
 */
private Map<String, MappedSuperclass> mapFields(Class clazz, Set<String> persistantFields) {
    persistantFields = new TreeSet<>(persistantFields);
    final Map<String, MappedSuperclass> fields = new TreeMap<>();
    // or we've reached the Object class.
    while (!persistantFields.isEmpty() && !clazz.equals(Object.class)) {
        // This is a single target for the relationship mapping for each
        // class in the hierarchy.
        final MappedSuperclass superclass = new MappedSuperclass(clazz.getName());
        for (final Field field : clazz.getDeclaredFields()) {
            if (!field.isSynthetic()) {
                final String fieldName = field.getName();
                // if this is one of bean's persistence fields, create the mapping
                if (persistantFields.contains(fieldName)) {
                    fields.put(fieldName, superclass);
                    persistantFields.remove(fieldName);
                } else if (!ENHANCED_FIELDS.contains(fieldName)) {
                    // these are fields we need to identify as transient for the persistence engine.
                    final Transient transientField = new Transient(fieldName);
                    superclass.addField(transientField);
                }
            }
        }
        clazz = clazz.getSuperclass();
    }
    return fields;
}
Also used : RelationField(org.apache.openejb.jee.jpa.RelationField) CmpField(org.apache.openejb.jee.CmpField) Field(java.lang.reflect.Field) MappedSuperclass(org.apache.openejb.jee.jpa.MappedSuperclass) Transient(org.apache.openejb.jee.jpa.Transient) TreeMap(java.util.TreeMap)

Aggregations

Field (java.lang.reflect.Field)1 TreeMap (java.util.TreeMap)1 CmpField (org.apache.openejb.jee.CmpField)1 MappedSuperclass (org.apache.openejb.jee.jpa.MappedSuperclass)1 RelationField (org.apache.openejb.jee.jpa.RelationField)1 Transient (org.apache.openejb.jee.jpa.Transient)1