@Test public void testGetPrimaryField() { AuditableField ninjaPrimaryField = new AuditableField("getCompleteName", "Name"); Ninja ninja = new Ninja(); assertEquals(ninjaPrimaryField, CacheUtil.getPrimaryField(ninja)); AuditableField systemCodesPrimaryField = new AuditableField("value"); SystemCodes systemCodes = new SystemCodes(); assertEquals(systemCodesPrimaryField, CacheUtil.getPrimaryField(systemCodes)); }
public static AuditableField getPrimaryField(BaseEntity obj) { Class<?> clazz = obj.getClass(); AuditableField ret = primaryField.get(clazz); if (ret == null) { final List<Field> fields = CrudUtil.getAllFields(clazz, true); AuditableField pf = null; for (Field field : fields) { if (field.isAnnotationPresent(PrimaryField.class)) { PrimaryField annot = field .getAnnotation(PrimaryField.class); if (StringUtil.isEmpty(annot.label())) { pf = new AuditableField(field.getName()); } else { pf = new AuditableField(field.getName(), annot.label()); } break; } } final List<Method> methods = CrudUtil.getAllMethods(clazz, true); for (Method method : methods) { if (method.isAnnotationPresent(PrimaryField.class)) { PrimaryField annot = method .getAnnotation(PrimaryField.class); if (StringUtil.isEmpty(annot.label())) { pf = new AuditableField(method.getName()); } else { pf = new AuditableField(method.getName(), annot.label()); } break; } } if (pf == null) pf = new AuditableField("", ""); primaryField.put(obj.getClass(), pf); ret = primaryField.get(obj.getClass()); if (_log.isDebugEnabled()) { _log.debug("Primary Field is " + ret.getTitle() + ":" + ret.getFieldName()); } } return ret; }
CacheUtil { public static AuditableField getPrimaryField(BaseEntity obj) { Class<?> clazz = obj.getClass(); AuditableField ret = primaryField.get(clazz); if (ret == null) { final List<Field> fields = CrudUtil.getAllFields(clazz, true); AuditableField pf = null; for (Field field : fields) { if (field.isAnnotationPresent(PrimaryField.class)) { PrimaryField annot = field .getAnnotation(PrimaryField.class); if (StringUtil.isEmpty(annot.label())) { pf = new AuditableField(field.getName()); } else { pf = new AuditableField(field.getName(), annot.label()); } break; } } final List<Method> methods = CrudUtil.getAllMethods(clazz, true); for (Method method : methods) { if (method.isAnnotationPresent(PrimaryField.class)) { PrimaryField annot = method .getAnnotation(PrimaryField.class); if (StringUtil.isEmpty(annot.label())) { pf = new AuditableField(method.getName()); } else { pf = new AuditableField(method.getName(), annot.label()); } break; } } if (pf == null) pf = new AuditableField("", ""); primaryField.put(obj.getClass(), pf); ret = primaryField.get(obj.getClass()); if (_log.isDebugEnabled()) { _log.debug("Primary Field is " + ret.getTitle() + ":" + ret.getFieldName()); } } return ret; } }
CacheUtil { public static AuditableField getPrimaryField(BaseEntity obj) { Class<?> clazz = obj.getClass(); AuditableField ret = primaryField.get(clazz); if (ret == null) { final List<Field> fields = CrudUtil.getAllFields(clazz, true); AuditableField pf = null; for (Field field : fields) { if (field.isAnnotationPresent(PrimaryField.class)) { PrimaryField annot = field .getAnnotation(PrimaryField.class); if (StringUtil.isEmpty(annot.label())) { pf = new AuditableField(field.getName()); } else { pf = new AuditableField(field.getName(), annot.label()); } break; } } final List<Method> methods = CrudUtil.getAllMethods(clazz, true); for (Method method : methods) { if (method.isAnnotationPresent(PrimaryField.class)) { PrimaryField annot = method .getAnnotation(PrimaryField.class); if (StringUtil.isEmpty(annot.label())) { pf = new AuditableField(method.getName()); } else { pf = new AuditableField(method.getName(), annot.label()); } break; } } if (pf == null) pf = new AuditableField("", ""); primaryField.put(obj.getClass(), pf); ret = primaryField.get(obj.getClass()); if (_log.isDebugEnabled()) { _log.debug("Primary Field is " + ret.getTitle() + ":" + ret.getFieldName()); } } return ret; } private  CacheUtil(); }
CacheUtil { public static AuditableField getPrimaryField(BaseEntity obj) { Class<?> clazz = obj.getClass(); AuditableField ret = primaryField.get(clazz); if (ret == null) { final List<Field> fields = CrudUtil.getAllFields(clazz, true); AuditableField pf = null; for (Field field : fields) { if (field.isAnnotationPresent(PrimaryField.class)) { PrimaryField annot = field .getAnnotation(PrimaryField.class); if (StringUtil.isEmpty(annot.label())) { pf = new AuditableField(field.getName()); } else { pf = new AuditableField(field.getName(), annot.label()); } break; } } final List<Method> methods = CrudUtil.getAllMethods(clazz, true); for (Method method : methods) { if (method.isAnnotationPresent(PrimaryField.class)) { PrimaryField annot = method .getAnnotation(PrimaryField.class); if (StringUtil.isEmpty(annot.label())) { pf = new AuditableField(method.getName()); } else { pf = new AuditableField(method.getName(), annot.label()); } break; } } if (pf == null) pf = new AuditableField("", ""); primaryField.put(obj.getClass(), pf); ret = primaryField.get(obj.getClass()); if (_log.isDebugEnabled()) { _log.debug("Primary Field is " + ret.getTitle() + ":" + ret.getFieldName()); } } 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 AuditableField getPrimaryField(BaseEntity obj) { Class<?> clazz = obj.getClass(); AuditableField ret = primaryField.get(clazz); if (ret == null) { final List<Field> fields = CrudUtil.getAllFields(clazz, true); AuditableField pf = null; for (Field field : fields) { if (field.isAnnotationPresent(PrimaryField.class)) { PrimaryField annot = field .getAnnotation(PrimaryField.class); if (StringUtil.isEmpty(annot.label())) { pf = new AuditableField(field.getName()); } else { pf = new AuditableField(field.getName(), annot.label()); } break; } } final List<Method> methods = CrudUtil.getAllMethods(clazz, true); for (Method method : methods) { if (method.isAnnotationPresent(PrimaryField.class)) { PrimaryField annot = method .getAnnotation(PrimaryField.class); if (StringUtil.isEmpty(annot.label())) { pf = new AuditableField(method.getName()); } else { pf = new AuditableField(method.getName(), annot.label()); } break; } } if (pf == null) pf = new AuditableField("", ""); primaryField.put(obj.getClass(), pf); ret = primaryField.get(obj.getClass()); if (_log.isDebugEnabled()) { _log.debug("Primary Field is " + ret.getTitle() + ":" + ret.getFieldName()); } } 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; }