Ejemplo n.º 1
0
  public static void saveToDatabase(Context context, final List<Account> items) {
    final DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);

    try {
      final Dao<Account, String> dao = helper.getAccountDao();
      dao.callBatchTasks(
          new Callable<Void>() {

            public Void call() throws Exception {
              // Delete all
              int removed = dao.delete(dao.deleteBuilder().prepare());
              if (Flags.DEBUG) {
                Log.d(LOG_TAG, "Deleted " + removed + " from database");
              }

              for (Account item : items) {
                dao.create(item);
              }
              if (Flags.DEBUG) {
                Log.d(LOG_TAG, "Inserted " + items.size() + " into database");
              }
              return null;
            }
          });
    } catch (Exception e) {
      if (Flags.DEBUG) {
        e.printStackTrace();
      }
    } finally {
      OpenHelperManager.releaseHelper();
    }
  }
Ejemplo n.º 2
0
 /**
  * 更新位置信息
  *
  * @param list
  */
 public void create(final List<Locations> list) {
   try {
     locationsesDao.callBatchTasks(
         new Callable<Void>() {
           @Override
           public Void call() throws Exception {
             for (Locations locations : list) {
               deleteByLocationNum(locations);
               locationsesDao.createOrUpdate(locations);
             }
             return null;
           }
         });
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 3
0
 public void addAll(final List<Interest> listOfData) {
   if (listOfData.size() > 0) {
     try {
       final Dao<Interest, String> dao = this.getController();
       dao.callBatchTasks(
           new Callable<Void>() {
             public Void call() throws SQLException {
               for (Interest obj : listOfData) {
                 dao.create(obj);
               }
               return null;
             }
           });
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }