Package de.caluga.morphium
Class 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!
-
-
Constructor Summary
Constructors Constructor Description AnnotationAndReflectionHelper(boolean convertCamelCase)AnnotationAndReflectionHelper(boolean convertCamelCase, Map<Class<?>,Class<?>> realClassCache)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcallLifecycleMethod(Class<? extends Annotation> type, Object on)StringconvertCamelCase(String n)turns documentId into document_idstatic ObjectconvertType(Object value, String fieldName, Class<?> fieldType)StringcreateCamelCase(String n, boolean capitalize)converts a sql/javascript-Name to Java, e.g. converts document_id to documentId.StringgetAdditionalDataField(Class<?> cls)List<Annotation>getAllAnnotationsFromHierachy(Class<?> cls, Class<? extends Annotation>... anCls)List<Field>getAllFields(Class clz)return list of fields in class - including hierachy!!!<T extends Annotation>
TgetAnnotationFromClass(Class<?> cls, Class<? extends T> annotationClass)<T extends Annotation>
TgetAnnotationFromHierarchy(Class<?> superClass, Class<? extends T> annotationClass)returns annotations, even if in class hierarchy or lazyloading proxyClassgetClassForTypeId(String typeId)static MethodgetConvertMethod(Class<?> fieldType)StringgetCreationTimeField(Class<?> cls)DategetDateValue(Object o, String fld)DoublegetDoubleValue(Object o, String fld)FieldgetField(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 fieldList<String>getFields(Class cls, boolean ignoreEntity, Class<? extends Annotation>... annotations)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 accountObjectgetId(Object o)FieldgetIdField(Object o)StringgetIdFieldName(Object o)StringgetLastAccessField(Class<?> cls)StringgetLastChangeField(Class<?> cls)LonggetLongValue(Object o, String fld)StringgetMongoFieldName(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 accountStringgetMongoFieldName(Class clz, String field, boolean ignoreUnknownField)<T> Class<? extends T>getRealClass(Class<? extends T> superClass)<T> TgetRealObject(T o)StringgetStringValue(Object o, String fld)StringgetTypeIdForClass(Class cls)StringgetTypeIdForClassName(String n)ClassgetTypeOfField(Class<?> cls, String fld)ObjectgetValue(Object o, String fld)booleanhasAdditionalData(Class aClass)booleanisAnnotationOnAnyField(Class<?> aClass, Class<? extends Annotation> annotationClass)<T extends Annotation>
booleanisAnnotationPresentInHierarchy(Class<?> aClass, Class<? extends T> annotationClass)booleanisAsyncWrite(Class<?> cls)booleanisBufferedWrite(Class<?> aClass)booleanisEntity(Object o)voidsetValue(Object o, Object value, String fld)booleanstoresCreation(Class<?> cls)booleanstoresLastAccess(Class<?> cls)booleanstoresLastChange(Class<?> cls)
-
-
-
Method Detail
-
getTypeIdForClassName
public String getTypeIdForClassName(String n) throws ClassNotFoundException
- Throws:
ClassNotFoundException
-
getClassForTypeId
public Class getClassForTypeId(String typeId) throws ClassNotFoundException
- Throws:
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- Parameters:
superClass- class- Returns:
- the Annotation
-
getAnnotationFromClass
public <T extends Annotation> T getAnnotationFromClass(Class<?> cls, Class<? extends T> annotationClass)
-
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 convertcapitalize- : 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 searchfld- - field name- Returns:
- field, if found, null else
-
isEntity
public boolean isEntity(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)
-
getFields
public List<String> getFields(Class cls, boolean ignoreEntity, Class<? extends Annotation>... annotations)
-
getRealObject
public <T> T getRealObject(T o)
-
storesLastChange
public boolean storesLastChange(Class<?> cls)
-
storesLastAccess
public boolean storesLastAccess(Class<?> cls)
-
storesCreation
public boolean storesCreation(Class<?> cls)
-
getAllAnnotationsFromHierachy
public List<Annotation> getAllAnnotationsFromHierachy(Class<?> cls, Class<? extends Annotation>... anCls)
-
callLifecycleMethod
public void callLifecycleMethod(Class<? extends Annotation> type, Object on)
-
isAsyncWrite
public boolean isAsyncWrite(Class<?> cls)
-
-