@Override
 public boolean delete(AppModel model) {
   try {
     LOG.d("DB Delete id", model.getId());
     getRealDao().deleteById(model.getId());
   } catch (SQLException e) {
     LOG.e(e);
     return false;
   }
   return true;
 }
 @Override
 public boolean save(AppModel route) {
   try {
     LOG.d("DB Save");
     getRealDao().createOrUpdate(createDb(route));
   } catch (SQLException e) {
     LOG.e(e);
     return false;
   }
   return true;
 }
예제 #3
0
  public static <T> T toSimpleModel(String json, Type type) {
    Gson gson = createGSON(true);

    LOG.d("Gson to model: ", json, type);
    T fromJson = null;
    try {
      fromJson = gson.fromJson(json, type);
    } catch (Exception e) {
      fromJson = null;
      LOG.e(e);
    }
    return fromJson;
  }
 @Override
 public AppModel getById(int itemId) {
   try {
     LOG.d("get by id", itemId);
     DbModel db = getRealDao().queryForId(itemId);
     if (db != null) {
       return createApp(db);
     }
   } catch (SQLException e) {
     LOG.e(e);
     return null;
   }
   return null;
 }
예제 #5
0
 public static <T> T toModel(String json, Class<T> clazz) {
   Gson gson = createGSON(true);
   LOG.d("Gson to model: ", json, clazz);
   T fromJson = null;
   try {
     fromJson = gson.fromJson(json, clazz);
   } catch (Exception e) {
     LOG.e(e);
     try {
       fromJson = clazz.newInstance();
     } catch (Exception e1) {
       LOG.e(e);
       new RuntimeException("GsonConverter instance error");
     }
   }
   return fromJson;
 }
예제 #6
0
 public static String toJsonNoExclude(Object model, Type type) {
   Gson gson = createGSON(false);
   String json = gson.toJson(model, type);
   LOG.d("Model to gson: ", json, model);
   return json;
 }
예제 #7
0
 public static String toJson(Object model, Class<?> clazz) {
   Gson gson = createGSON(true);
   String json = gson.toJson(model, clazz);
   LOG.d("Model to gson: ", json, model);
   return json;
 }