Beispiel #1
0
 public boolean registerActionModel(ActionModel model, boolean withChild) {
   boolean result = false;
   SQLiteDatabase db = null;
   try {
     db = getWritableDatabase();
     db.beginTransaction();
     if (model.getId() == null) {
       result = (ActionModelHandler.insert(db, model) > 0);
     } else {
       result = (ActionModelHandler.update(db, model) > 0);
     }
     if (withChild) {
       db.delete(
           PoseModelHandler.TABLE_NAME,
           PoseModelHandler.COL_NAME_ACTION_ID + "=?",
           new String[] {model.getId().toString()});
       for (PoseModel child : model.getPoseModels()) {
         child.setId(null);
         child.setActionId(model.getId());
         PoseModelHandler.insert(db, child);
       }
     }
     db.setTransactionSuccessful();
   } finally {
     if (db != null) {
       db.endTransaction();
       db.close();
     }
   }
   return result;
 }
Beispiel #2
0
 public Long findMaxActionSort() {
   SQLiteDatabase db = null;
   try {
     db = getReadableDatabase();
     List<ActionModel> models = ActionModelHandler.findOrderBySortDesc(db, 1);
     ActionModel model = (models.size() > 0) ? models.get(0) : null;
     return (model != null) ? model.getSort() : null;
   } finally {
     if (db != null) {
       db.close();
     }
   }
 }
Beispiel #3
0
 public ActionModel findActionModel(String name, boolean withChild) {
   SQLiteDatabase db = null;
   try {
     db = getReadableDatabase();
     ActionModel model = ActionModelHandler.findByName(db, name);
     if (model != null && withChild) {
       model.setPoseModels(PoseModelHandler.findByActionIdOrderBySortAsc(db, 0, model.getId()));
     }
     return model;
   } finally {
     if (db != null) {
       db.close();
     }
   }
 }
Beispiel #4
0
 public List<ActionModel> findActions(boolean withChild) {
   SQLiteDatabase db = null;
   try {
     db = getReadableDatabase();
     List<ActionModel> models = ActionModelHandler.findOrderBySortAsc(db, 0);
     if (withChild) {
       for (ActionModel model : models) {
         model.setPoseModels(PoseModelHandler.findByActionIdOrderBySortAsc(db, 0, model.getId()));
       }
     }
     return models;
   } finally {
     if (db != null) {
       db.close();
     }
   }
 }
Beispiel #5
0
 public boolean deleteActionModel(long id) {
   boolean result = false;
   SQLiteDatabase db = null;
   try {
     db = getWritableDatabase();
     db.beginTransaction();
     result = (ActionModelHandler.delete(db, id) > 0);
     PoseModelHandler.delete(db, id);
     db.setTransactionSuccessful();
   } finally {
     if (db != null) {
       db.endTransaction();
       db.close();
     }
   }
   return result;
 }