Class AnnotationAndReflectionHelper


  • public class AnnotationAndReflectionHelper
    extends Object
    User: Stephan Bösebeck Date: 07.03.13 Time: 11:10

    This class will encapsulate all calls to the reflection API. Specially getting all the annotations from entities is done here. For performance increase (and because the structure of the code usually does not change during runtime) those results are being cached.

    this class is ThreadSafe!

    • Constructor Detail

      • AnnotationAndReflectionHelper

        public AnnotationAndReflectionHelper​(boolean convertCamelCase)
      • AnnotationAndReflectionHelper

        public AnnotationAndReflectionHelper​(boolean convertCamelCase,
                                             Map<Class<?>,​Class<?>> realClassCache)
    • Method Detail

      • getTypeIdForClass

        public String getTypeIdForClass​(Class cls)
      • isAnnotationPresentInHierarchy

        public <T extends Annotation> boolean isAnnotationPresentInHierarchy​(Class<?> aClass,
                                                                             Class<? extends T> annotationClass)
      • isAnnotationOnAnyField

        public boolean isAnnotationOnAnyField​(Class<?> aClass,
                                              Class<? extends Annotation> annotationClass)
      • getAnnotationFromHierarchy

        public <T extends Annotation> T getAnnotationFromHierarchy​(Class<?> superClass,
                                                                   Class<? extends T> annotationClass)
        returns annotations, even if in class hierarchy or lazyloading proxy
        Parameters:
        superClass - class
        Returns:
        the Annotation
      • getAnnotationFromClass

        public <T extends Annotation> T getAnnotationFromClass​(Class<?> cls,
                                                               Class<? extends T> annotationClass)
      • getRealClass

        public <T> Class<? extends T> getRealClass​(Class<? extends T> superClass)
      • isBufferedWrite

        public boolean isBufferedWrite​(Class<?> aClass)
      • hasAdditionalData

        public boolean hasAdditionalData​(Class aClass)
      • getMongoFieldName

        public String getMongoFieldName​(Class clz,
                                        String field)
        get the fieldname used in Mongo for the corresponding field depending on whether camelcase-conversion is enabled globally and whether it is enabled for this specific property also takes "." as path separator into account
        Parameters:
        clz -
        field -
        Returns:
      • getMongoFieldName

        public String getMongoFieldName​(Class clz,
                                        String field,
                                        boolean ignoreUnknownField)
      • createCamelCase

        public String createCamelCase​(String n,
                                      boolean capitalize)
        converts a sql/javascript-Name to Java, e.g. converts document_id to documentId.
        Parameters:
        n - - string to convert
        capitalize - : if true, first letter will be capitalized
        Returns:
        the translated name (capitalized or camel_case => camelCase)
      • convertCamelCase

        public String convertCamelCase​(String n)
        turns documentId into document_id
        Parameters:
        n - - string to convert
        Returns:
        converted string (camelCase becomes camel_case)
      • getAllFields

        public List<Field> getAllFields​(Class clz)
        return list of fields in class - including hierachy!!!
        Parameters:
        clz - class to get all fields for
        Returns:
        list of fields in that class
      • getField

        public Field getField​(Class clz,
                              String fld)
        extended logic: Fld may be, the java field name, the name of the specified value in Property-Annotation or the translated underscored lowercase name (mongoId => mongo_id) or a name specified in the Aliases-Annotation of this field
        Parameters:
        clz - - class to search
        fld - - field name
        Returns:
        field, if found, null else
      • isEntity

        public boolean isEntity​(Object o)
      • getConvertMethod

        public static Method getConvertMethod​(Class<?> fieldType)
      • getIdFieldName

        public String getIdFieldName​(Object o)
      • getFields

        public List<String> getFields​(Class cls,
                                      Class<? extends Annotation>... annotations)
        get a list of valid fields of a given record as they are in the MongoDB so, if you have a field Mapping, the mapped Property-name will be used returns all fields, which have at least one of the given annotations if no annotation is given, all fields are returned Does not take the @Aliases-annotation int account
        Parameters:
        cls - - the class to geht ghe Fields from
        Returns:
        List of Strings, each a field name (as described in @Property or determined by name)
      • getRealObject

        public <T> T getRealObject​(T o)
      • getTypeOfField

        public final Class getTypeOfField​(Class<?> cls,
                                          String fld)
      • storesLastChange

        public boolean storesLastChange​(Class<?> cls)
      • storesLastAccess

        public boolean storesLastAccess​(Class<?> cls)
      • storesCreation

        public boolean storesCreation​(Class<?> cls)
      • getLastChangeField

        public String getLastChangeField​(Class<?> cls)
      • getLastAccessField

        public String getLastAccessField​(Class<?> cls)
      • getAdditionalDataField

        public String getAdditionalDataField​(Class<?> cls)
      • getCreationTimeField

        public String getCreationTimeField​(Class<?> cls)
      • callLifecycleMethod

        public void callLifecycleMethod​(Class<? extends Annotation> type,
                                        Object on)
      • isAsyncWrite

        public boolean isAsyncWrite​(Class<?> cls)