@Test public void testGetAuditable() { Ninja ninja = new Ninja(); assertEquals(getNinjaExpectedAuditableFields(), CacheUtil.getAuditable(ninja)); SystemCodes systemCodes = new SystemCodes(); assertEquals(getSystemCodesExpectedAuditableFields(), CacheUtil.getAuditable(systemCodes)); }
public static List<AuditableField> getAuditable(BaseEntity obj) { Class<?> clazz = obj.getClass(); List<AuditableField> ret = auditable.get(clazz); if (ret == null) { List<AuditableField> auditableFields = new ArrayList<AuditableField>(); Auditable annotation = clazz.getAnnotation(Auditable.class); if (annotation != null) { final List<Field> fields = CrudUtil.getAllFields(clazz, annotation.includeParentFields()); List<String> exclude = Arrays .asList(annotation.excludeFields()); for (Field field : fields) { if (CacheUtil.isPersistent(field) && (!exclude.contains(field.getName())) && (!excludeFields.contains(field.getName()))) { auditableFields .add(new AuditableField(field.getName())); } } } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " contains the following auditable fields"); for (AuditableField audit : auditableFields) { _log.debug(audit.getTitle() + ":" + audit.getFieldName()); } } auditable.put(obj.getClass(), auditableFields); ret = auditable.get(obj.getClass()); } return ret; }
CacheUtil { public static List<AuditableField> getAuditable(BaseEntity obj) { Class<?> clazz = obj.getClass(); List<AuditableField> ret = auditable.get(clazz); if (ret == null) { List<AuditableField> auditableFields = new ArrayList<AuditableField>(); Auditable annotation = clazz.getAnnotation(Auditable.class); if (annotation != null) { final List<Field> fields = CrudUtil.getAllFields(clazz, annotation.includeParentFields()); List<String> exclude = Arrays .asList(annotation.excludeFields()); for (Field field : fields) { if (CacheUtil.isPersistent(field) && (!exclude.contains(field.getName())) && (!excludeFields.contains(field.getName()))) { auditableFields .add(new AuditableField(field.getName())); } } } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " contains the following auditable fields"); for (AuditableField audit : auditableFields) { _log.debug(audit.getTitle() + ":" + audit.getFieldName()); } } auditable.put(obj.getClass(), auditableFields); ret = auditable.get(obj.getClass()); } return ret; } }
CacheUtil { public static List<AuditableField> getAuditable(BaseEntity obj) { Class<?> clazz = obj.getClass(); List<AuditableField> ret = auditable.get(clazz); if (ret == null) { List<AuditableField> auditableFields = new ArrayList<AuditableField>(); Auditable annotation = clazz.getAnnotation(Auditable.class); if (annotation != null) { final List<Field> fields = CrudUtil.getAllFields(clazz, annotation.includeParentFields()); List<String> exclude = Arrays .asList(annotation.excludeFields()); for (Field field : fields) { if (CacheUtil.isPersistent(field) && (!exclude.contains(field.getName())) && (!excludeFields.contains(field.getName()))) { auditableFields .add(new AuditableField(field.getName())); } } } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " contains the following auditable fields"); for (AuditableField audit : auditableFields) { _log.debug(audit.getTitle() + ":" + audit.getFieldName()); } } auditable.put(obj.getClass(), auditableFields); ret = auditable.get(obj.getClass()); } return ret; } private  CacheUtil(); }
CacheUtil { public static List<AuditableField> getAuditable(BaseEntity obj) { Class<?> clazz = obj.getClass(); List<AuditableField> ret = auditable.get(clazz); if (ret == null) { List<AuditableField> auditableFields = new ArrayList<AuditableField>(); Auditable annotation = clazz.getAnnotation(Auditable.class); if (annotation != null) { final List<Field> fields = CrudUtil.getAllFields(clazz, annotation.includeParentFields()); List<String> exclude = Arrays .asList(annotation.excludeFields()); for (Field field : fields) { if (CacheUtil.isPersistent(field) && (!exclude.contains(field.getName())) && (!excludeFields.contains(field.getName()))) { auditableFields .add(new AuditableField(field.getName())); } } } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " contains the following auditable fields"); for (AuditableField audit : auditableFields) { _log.debug(audit.getTitle() + ":" + audit.getFieldName()); } } auditable.put(obj.getClass(), auditableFields); ret = auditable.get(obj.getClass()); } return ret; } private  CacheUtil(); static String getReadableName(BaseEntity obj); static List<AuditableField> getAuditable(BaseEntity obj); static AuditableField getPrimaryField(BaseEntity obj); static List<String> getPersistentFields(BaseEntity obj); static List<String> getPersistentFields(BaseEntity obj, Class<?> clazz); static List<String> getPersistentFields(BaseEntity obj, Class<?> clazz, boolean includeParent); static Map<String, String> getColumnNames(BaseEntity obj); static Map<String, String> getColumnNames(BaseEntity obj, Class<?> clazz); static Map<String, String> getColumnNames(BaseEntity obj, Class<?> clazz, boolean includeParent); @SuppressWarnings("unchecked") static List<String> getSearchableFields(BaseEntity obj); @SuppressWarnings("unchecked") static List<String> getSynchronizableFields(BaseEntity obj); @SuppressWarnings("unchecked") static List<String> getSynchronizableFields(BaseEntity obj, Class<?> clazz); static JoinTable getJoinTableFields(BaseEntity owner, Class<?> collection); static Method getNewFormBindMethod(Class<?> clazz); static Method getUpdateFormBindMethod(Class<?> clazz); static Method getInsertMethod(Class<?> clazz); static Method getUpdateMethod(Class<?> clazz); static Method getDeleteMethod(Class<?> clazz); }
CacheUtil { public static List<AuditableField> getAuditable(BaseEntity obj) { Class<?> clazz = obj.getClass(); List<AuditableField> ret = auditable.get(clazz); if (ret == null) { List<AuditableField> auditableFields = new ArrayList<AuditableField>(); Auditable annotation = clazz.getAnnotation(Auditable.class); if (annotation != null) { final List<Field> fields = CrudUtil.getAllFields(clazz, annotation.includeParentFields()); List<String> exclude = Arrays .asList(annotation.excludeFields()); for (Field field : fields) { if (CacheUtil.isPersistent(field) && (!exclude.contains(field.getName())) && (!excludeFields.contains(field.getName()))) { auditableFields .add(new AuditableField(field.getName())); } } } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " contains the following auditable fields"); for (AuditableField audit : auditableFields) { _log.debug(audit.getTitle() + ":" + audit.getFieldName()); } } auditable.put(obj.getClass(), auditableFields); ret = auditable.get(obj.getClass()); } return ret; } private  CacheUtil(); static String getReadableName(BaseEntity obj); static List<AuditableField> getAuditable(BaseEntity obj); static AuditableField getPrimaryField(BaseEntity obj); static List<String> getPersistentFields(BaseEntity obj); static List<String> getPersistentFields(BaseEntity obj, Class<?> clazz); static List<String> getPersistentFields(BaseEntity obj, Class<?> clazz, boolean includeParent); static Map<String, String> getColumnNames(BaseEntity obj); static Map<String, String> getColumnNames(BaseEntity obj, Class<?> clazz); static Map<String, String> getColumnNames(BaseEntity obj, Class<?> clazz, boolean includeParent); @SuppressWarnings("unchecked") static List<String> getSearchableFields(BaseEntity obj); @SuppressWarnings("unchecked") static List<String> getSynchronizableFields(BaseEntity obj); @SuppressWarnings("unchecked") static List<String> getSynchronizableFields(BaseEntity obj, Class<?> clazz); static JoinTable getJoinTableFields(BaseEntity owner, Class<?> collection); static Method getNewFormBindMethod(Class<?> clazz); static Method getUpdateFormBindMethod(Class<?> clazz); static Method getInsertMethod(Class<?> clazz); static Method getUpdateMethod(Class<?> clazz); static Method getDeleteMethod(Class<?> clazz); static final Map<Class<?>, List<AuditableField>> auditable; static final Map<Class<?>, AuditableField> primaryField; static final Map<Class<?>, String> readableName; static final Map<String, List<String>> persistentFields; static final Map<Class<?>, List<String>> synchronizeFields; static final Map<Class<?>, List<String>> searchableFields; static final Map<String, JoinTable> joinTableFields; static final Map<String, Map<String, String>> columnNames; }