/** * modelClassのPropertyTypeリストを取得する. PKになるkeyプロパティは必ず戻り値のリストの先頭に格納され返却されます。 * * @param modelClass slim3のモデルクラス * @return PropertyTypeリスト(先頭はプライマリキー) */ @SuppressWarnings("unchecked") public static List<PropertyType> getPropertyTypes(Class<?> modelClass) { if (modelClass == null) return null; checkSlim3Model(modelClass); // プロパティのソート順を担保するMapを生成 Map<String, PropertyType> sortedPropertyType = new LinkedHashMap<String, PropertyType>(); String pkName = null; String versionName = null; Set<String> lobNames = new HashSet<String>(); Map<String, Class> elementClassMap = new HashMap<String, Class>(); LinkedHashSet<Field> fields = getFields(modelClass); for (Field f : fields) { sortedPropertyType.put(f.getName(), null); putGenericType(f, elementClassMap); Attribute attr = f.getAnnotation(Attribute.class); if (attr == null) continue; else if (attr.primaryKey()) pkName = f.getName(); else if (attr.version()) versionName = f.getName(); else if (attr.lob()) lobNames.add(f.getName()); } BeanDesc desc = BeanUtil.getBeanDesc(modelClass); int size = desc.getPropertyDescSize(); for (int i = 0; i < size; i++) { PropertyDesc prop = desc.getPropertyDesc(i); if (prop.isReadable() && prop.isWritable()) { PropertyType pt = new PropertyType(prop.getPropertyClass(), prop.getName()); // このパラメータのメタ情報を追加 pt.setPrimaryKey(pt.getName().equals(pkName)); pt.setVersion(pt.getName().equals(versionName)); pt.setLob(lobNames.contains(pt.getName())); pt.setGenericType(elementClassMap.get(pt.getName())); // 予めソートされたMapにValueを設定 sortedPropertyType.put(pt.getName(), pt); } else if (prop.isReadable() && (ModelRef.class.isAssignableFrom(prop.getPropertyClass()) || InverseModelRef.class.isAssignableFrom(prop.getPropertyClass()) || InverseModelListRef.class.isAssignableFrom(prop.getPropertyClass()))) { PropertyType pt = new PropertyType(prop.getPropertyClass(), prop.getName()); // このパラメータのメタ情報を追加 pt.setPrimaryKey(false); pt.setVersion(false); pt.setLob(false); pt.setGenericType(elementClassMap.get(pt.getName())); // 予めソートされたMapにValueを設定 sortedPropertyType.put(pt.getName(), pt); } } List<PropertyType> lstResult = new ArrayList<PropertyType>(); for (PropertyType pt : sortedPropertyType.values()) { if (pt == null) { continue; } // プライマリキーは常に先頭へ if (pt.isPrimaryKey()) { lstResult.add(0, pt); } else { lstResult.add(pt); } } return lstResult; }