Exemplo n.º 1
0
 /**
  * modelのpropertyNameプロパティにvalueをセットする.
  *
  * @param model model
  * @param propertyName プロパティ名
  * @param value セットするvalue
  */
 public static void setValue(Object model, String propertyName, Object value) {
   if (model == null || propertyName == null) return;
   checkSlim3Model(model.getClass());
   BeanDesc desc = BeanUtil.getBeanDesc(model.getClass());
   PropertyDesc pDesc = desc.getPropertyDesc(propertyName);
   if (pDesc.isWritable()) {
     pDesc.setValue(model, value);
   }
 }
Exemplo n.º 2
0
 /**
  * modelのpropertyNameプロパティの値を取得する.
  *
  * @param model model
  * @param propertyName プロパティ名
  * @return
  */
 @SuppressWarnings("unchecked")
 public static <T> T getValue(Object model, String propertyName) {
   if (model == null || propertyName == null) return null;
   checkSlim3Model(model.getClass());
   BeanDesc desc = BeanUtil.getBeanDesc(model.getClass());
   PropertyDesc pDesc = desc.getPropertyDesc(propertyName);
   if (pDesc.isReadable()) {
     return (T) pDesc.getValue(model);
   } else {
     return null;
   }
 }
Exemplo n.º 3
0
 /**
  * modelのPropertyDescリストを取得する.
  *
  * @param model
  * @return
  */
 public static List<PropertyDesc> getPropertyDescList(Object model) {
   if (model == null) return null;
   checkSlim3Model(model.getClass());
   BeanDesc desc = BeanUtil.getBeanDesc(model.getClass());
   int size = desc.getPropertyDescSize();
   List<PropertyDesc> propDescList = new ArrayList<PropertyDesc>();
   for (int i = 0; i < size; i++) {
     PropertyDesc prop = desc.getPropertyDesc(i);
     if (prop.isReadable() && prop.isWritable()) {
       propDescList.add(prop);
     }
   }
   return propDescList;
 }
Exemplo n.º 4
0
 /**
  * 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;
 }