Klasse AnnotationAndReflectionHelper

java.lang.Object
de.caluga.morphium.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!

  • Konstruktordetails

    • AnnotationAndReflectionHelper

      public AnnotationAndReflectionHelper(boolean convertCamelCase)
    • AnnotationAndReflectionHelper

      public AnnotationAndReflectionHelper(boolean convertCamelCase, Map<Class<?>,Class<?>> realClassCache)
  • Methodendetails

    • getTypeIdForClassName

      public String getTypeIdForClassName(String n) throws ClassNotFoundException
      Löst aus:
      ClassNotFoundException
    • getTypeIdForClass

      public String getTypeIdForClass(Class cls)
    • getClassForTypeId

      public Class getClassForTypeId(String typeId) throws ClassNotFoundException
      Löst aus:
      ClassNotFoundException
    • 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
      Parameter:
      superClass - class
      Gibt zurück:
      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
      Parameter:
      clz -
      field -
      Gibt zurück:
    • 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.
      Parameter:
      n - - string to convert
      capitalize - : if true, first letter will be capitalized
      Gibt zurück:
      the translated name (capitalized or camel_case => camelCase)
    • convertCamelCase

      public String convertCamelCase(String n)
      turns documentId into document_id
      Parameter:
      n - - string to convert
      Gibt zurück:
      converted string (camelCase becomes camel_case)
    • getAllFields

      public List<Field> getAllFields(Class clz)
      return list of fields in class - including hierachy!!!
      Parameter:
      clz - class to get all fields for
      Gibt zurück:
      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
      Parameter:
      clz - - class to search
      fld - - field name
      Gibt zurück:
      field, if found, null else
    • isEntity

      public boolean isEntity(Object o)
    • getValue

      public Object getValue(Object o, String fld)
    • setValue

      public void setValue(Object o, Object value, String fld)
    • convertType

      public static Object convertType(Object value, String fieldName, Class<?> fieldType)
    • getConvertMethod

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

      public Object getId(Object o)
    • getIdFieldName

      public String getIdFieldName(Object o)
    • getIdField

      public Field getIdField(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
      Parameter:
      cls - - the class to geht ghe Fields from
      Gibt zurück:
      List of Strings, each a field name (as described in @Property or determined by name)
    • getFields

      public List<String> getFields(Class cls, boolean ignoreEntity, Class<? extends Annotation>... annotations)
    • 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)
    • getLongValue

      public Long getLongValue(Object o, String fld)
    • getStringValue

      public String getStringValue(Object o, String fld)
    • getDateValue

      public Date getDateValue(Object o, String fld)
    • getDoubleValue

      public Double getDoubleValue(Object o, String fld)
    • getAllAnnotationsFromHierachy

      public List<Annotation> getAllAnnotationsFromHierachy(Class<?> cls, Class<? extends Annotation>... anCls)
    • 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)