示例#1
0
 /**
  * スコアの登録.
  *
  * @param input スコア情報
  */
 public void register(Map<String, Object> input) {
   Score score = new Score();
   BeanUtil.copy(input, score);
   Transaction tx = Datastore.beginTransaction();
   Datastore.put(score);
   tx.commit();
 }
示例#2
0
文件: ModelUtil.java 项目: mino8/cnmv
 /**
  * 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);
   }
 }
示例#3
0
文件: ModelUtil.java 项目: mino8/cnmv
 /**
  * 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;
   }
 }
示例#4
0
文件: ModelUtil.java 项目: mino8/cnmv
 /**
  * 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;
 }
示例#5
0
 /*
  * (non-Javadoc)
  *
  * @see yanitime4u.yanitime.logic.UserLogic#create(yanitime4u.yanitime.model.Users)
  */
 @Override
 public Users create(Users users) {
   AssertionUtil.assertNotNull(users);
   Transaction tx = Datastore.beginTransaction();
   try {
     Users register = new Users();
     BeanUtil.copy(users, register);
     Datastore.put(register);
     tx.commit();
     return register;
   } catch (ConcurrentModificationException e) {
     if (tx.isActive()) {
       tx.rollback();
     }
     throw e;
   }
 }
示例#6
0
  /*
   * (non-Javadoc)
   *
   * @see yanitime4u.yanitime.logic.UserLogic#update(com.google.appengine.api.datastore.Key,
   * java.lang.Long, java.util.Map)
   */
  @Override
  public Users update(Key key, Long version, Map<String, Object> input) {
    AssertionUtil.assertNotNull(key);
    AssertionUtil.assertNotNull(version);
    AssertionUtil.assertNotNull(input);

    Transaction tx = Datastore.beginTransaction();
    try {
      Users latest = Datastore.get(meta, key, version);
      BeanUtil.copy(input, latest);
      Datastore.put(tx, latest);
      tx.commit();
      return latest;
    } catch (ConcurrentModificationException e) {
      if (tx.isActive()) {
        tx.rollback();
      }
      throw e;
    }
  }
示例#7
0
文件: ModelUtil.java 项目: mino8/cnmv
 /**
  * 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;
 }