Class ClassKeyHelper


  • public final class ClassKeyHelper
    extends java.lang.Object
    Methods to read and manage keys for classes. Keys define how certain classes are identified and are used in defining bag creation.
    Author:
    rns
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void addKey​(java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys, java.lang.String clsName, FieldDescriptor key)
      Add a key to set of keys for a given class.
      static java.util.List<java.lang.String> getKeyFieldNames​(java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys, java.lang.String clsName)
      Return names of the key fields for a given class.
      static java.util.List<FieldDescriptor> getKeyFields​(java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys, java.lang.String clsName)
      Return the key fields of a given class.
      static java.lang.Object getKeyFieldValue​(FastPathObject obj, java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys)
      Get a key field value for the given object.
      static java.util.List<java.lang.Object> getKeyFieldValues​(FastPathObject obj, java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys)
      Get a list of key field values for the given object.
      static boolean hasKeyFields​(java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys, java.lang.String clsName)
      For a given classreturn true if it has any identifying fields.
      static boolean isKeyField​(java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys, java.lang.String clsName, java.lang.String fieldName)
      For a given class/field return true if it is an 'identifying' field.
      static ClassKeys readKeys​(Model model, java.util.Properties props)
      Read class keys from a properties into a map from classname to set of available keys.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • readKeys

        public static ClassKeys readKeys​(Model model,
                                         java.util.Properties props)
        Read class keys from a properties into a map from classname to set of available keys.
        Parameters:
        model - the data model
        props - a properties object describing class keys
        Returns:
        map from class name to set of available keys
      • addKey

        protected static void addKey​(java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys,
                                     java.lang.String clsName,
                                     FieldDescriptor key)
        Add a key to set of keys for a given class.
        Parameters:
        classKeys - existing map of classname to set of keys
        clsName - class name for key
        key - a FieldDescriptor that describes the key
      • isKeyField

        public static boolean isKeyField​(java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys,
                                         java.lang.String clsName,
                                         java.lang.String fieldName)
        For a given class/field return true if it is an 'identifying' field. An identifying field is an attribute (not a reference or collection) of the class that is part of any key defined for that class.
        Parameters:
        classKeys - map of classname to set of keys
        clsName - the class name to look up
        fieldName - the field name to look up
        Returns:
        true if the field is an 'identifying' field for the class.
      • hasKeyFields

        public static boolean hasKeyFields​(java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys,
                                           java.lang.String clsName)
        For a given classreturn true if it has any identifying fields. An identifying field is an attribute (not a reference or collection) of the class that is part of any key defined for that class.
        Parameters:
        classKeys - map of classname to set of keys
        clsName - the class name to look up
        Returns:
        true if the class has any key fields
      • getKeyFields

        public static java.util.List<FieldDescriptor> getKeyFields​(java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys,
                                                                   java.lang.String clsName)
        Return the key fields of a given class.
        Parameters:
        classKeys - map of classname to set of keys
        clsName - the class name to look up
        Returns:
        the fields that are class keys for the class
      • getKeyFieldNames

        public static java.util.List<java.lang.String> getKeyFieldNames​(java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys,
                                                                        java.lang.String clsName)
        Return names of the key fields for a given class.
        Parameters:
        classKeys - map of classname to set of keys
        clsName - the class name to look up
        Returns:
        the names of fields that are class keys for the class
      • getKeyFieldValue

        public static java.lang.Object getKeyFieldValue​(FastPathObject obj,
                                                        java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys)
        Get a key field value for the given object. This will return null if there are no key fields for the object's class or if there are no non-null values for the key fields. The key fields are kept in a consistent order with inherited fields appearing before those defined in a subclass.
        Parameters:
        obj - an object from the model
        classKeys - the key field definition for this model
        Returns:
        the first available key field value or null
      • getKeyFieldValues

        public static java.util.List<java.lang.Object> getKeyFieldValues​(FastPathObject obj,
                                                                         java.util.Map<java.lang.String,​java.util.List<FieldDescriptor>> classKeys)
        Get a list of key field values for the given object. This will return null if there are no key fields for the object's class or if there are no non-null values for the key fields. The key fields are kept in a consistent order with inherited fields appearing before those defined in a subclass.
        Parameters:
        obj - an object from the model
        classKeys - the key field definition for this model
        Returns:
        the first available key field value or null