@Test public void testGetSearchableFields() { Ninja ninja = new Ninja(); assertEquals(getNinjaExpectedPersistentFields(), CacheUtil.getSearchableFields(ninja)); BaseUser baseUser = new BaseUser(); List<String> expected = new ArrayList<String>(); expected.add("firstName"); expected.add("lastName"); expected.add("emailAddress"); expected.add("credential.username"); assertEquals(expected, CacheUtil.getSearchableFields(baseUser)); }
@SuppressWarnings("unchecked") public static List<String> getSearchableFields(BaseEntity obj) { Class<?> clazz = obj.getClass(); List<String> ret = searchableFields.get(clazz); if (ret == null) { List<String> fields = null; for (Method m : clazz.getDeclaredMethods()) { if (m.isAnnotationPresent(SearchableFields.class)) { try { fields = (List<String>) m.invoke(obj); } catch (Exception e) { _log.warn( "Unable to execute annotated method @SearchableFields of " + obj.getClass().getSimpleName(), e); } break; } } if (fields == null) { fields = CacheUtil.getPersistentFields(obj); } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " contains the following searchable fields"); for (String field : fields) { _log.debug(field); } } searchableFields.put(obj.getClass(), fields); ret = searchableFields.get(obj.getClass()); } return ret; }
CacheUtil { @SuppressWarnings("unchecked") public static List<String> getSearchableFields(BaseEntity obj) { Class<?> clazz = obj.getClass(); List<String> ret = searchableFields.get(clazz); if (ret == null) { List<String> fields = null; for (Method m : clazz.getDeclaredMethods()) { if (m.isAnnotationPresent(SearchableFields.class)) { try { fields = (List<String>) m.invoke(obj); } catch (Exception e) { _log.warn( "Unable to execute annotated method @SearchableFields of " + obj.getClass().getSimpleName(), e); } break; } } if (fields == null) { fields = CacheUtil.getPersistentFields(obj); } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " contains the following searchable fields"); for (String field : fields) { _log.debug(field); } } searchableFields.put(obj.getClass(), fields); ret = searchableFields.get(obj.getClass()); } return ret; } }
CacheUtil { @SuppressWarnings("unchecked") public static List<String> getSearchableFields(BaseEntity obj) { Class<?> clazz = obj.getClass(); List<String> ret = searchableFields.get(clazz); if (ret == null) { List<String> fields = null; for (Method m : clazz.getDeclaredMethods()) { if (m.isAnnotationPresent(SearchableFields.class)) { try { fields = (List<String>) m.invoke(obj); } catch (Exception e) { _log.warn( "Unable to execute annotated method @SearchableFields of " + obj.getClass().getSimpleName(), e); } break; } } if (fields == null) { fields = CacheUtil.getPersistentFields(obj); } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " contains the following searchable fields"); for (String field : fields) { _log.debug(field); } } searchableFields.put(obj.getClass(), fields); ret = searchableFields.get(obj.getClass()); } return ret; } private  CacheUtil(); }
CacheUtil { @SuppressWarnings("unchecked") public static List<String> getSearchableFields(BaseEntity obj) { Class<?> clazz = obj.getClass(); List<String> ret = searchableFields.get(clazz); if (ret == null) { List<String> fields = null; for (Method m : clazz.getDeclaredMethods()) { if (m.isAnnotationPresent(SearchableFields.class)) { try { fields = (List<String>) m.invoke(obj); } catch (Exception e) { _log.warn( "Unable to execute annotated method @SearchableFields of " + obj.getClass().getSimpleName(), e); } break; } } if (fields == null) { fields = CacheUtil.getPersistentFields(obj); } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " contains the following searchable fields"); for (String field : fields) { _log.debug(field); } } searchableFields.put(obj.getClass(), fields); ret = searchableFields.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 { @SuppressWarnings("unchecked") public static List<String> getSearchableFields(BaseEntity obj) { Class<?> clazz = obj.getClass(); List<String> ret = searchableFields.get(clazz); if (ret == null) { List<String> fields = null; for (Method m : clazz.getDeclaredMethods()) { if (m.isAnnotationPresent(SearchableFields.class)) { try { fields = (List<String>) m.invoke(obj); } catch (Exception e) { _log.warn( "Unable to execute annotated method @SearchableFields of " + obj.getClass().getSimpleName(), e); } break; } } if (fields == null) { fields = CacheUtil.getPersistentFields(obj); } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " contains the following searchable fields"); for (String field : fields) { _log.debug(field); } } searchableFields.put(obj.getClass(), fields); ret = searchableFields.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; }