private void initFieldsTypes(Class type) { if (types.containsKey(type)) return; // TODO: Checks the connections - handle them differently Map<String, Class> tMap = new HashMap<String, Class>(); Method[] getters = CommonStatic.getGetters(type); for (Method m : getters) if (!m.isAnnotationPresent(Connection.class)) tMap.put(fieldName(m), m.getReturnType()); /* In inheritance case */ if (extendsModels(type)) { List<Class> supers = getSupers(type); for (Class c : supers) tMap.put(/*tableName(c)+*/ getModelId(type), c); } tMap.put("CreatedAt", java.sql.Timestamp.class); tMap.put("UpdatedAt", java.sql.Timestamp.class); types.put(type, tMap); }
/** * Returns all the classes related to <code>type</code> by a {@link Connection} * * @param type The given {@link Model} interface. * @return A list that contains all the models in a relationship with <code>type</code> interface. */ protected List<Class> getAllReleatedClasses(Class type) { if (relatedClasses.containsKey(type)) return relatedClasses.get(type); List<Class> related = new ArrayList<Class>(); Method[] getters = CommonStatic.getDeclaredGetters(type); for (Method g : getters) if (g.isAnnotationPresent(Connection.class)) { Class t = g.getReturnType(); t = t.isArray() ? t.getComponentType() : t; if (!related.contains(t)) related.add(t); } relatedClasses.put(type, related); return related; }