Esempio n. 1
0
 public ArrayList<Group> getGroupList(Long facultetId) {
   ArrayList<Group> result = new ArrayList<Group>();
   Cursor c =
       mDb.rawQuery(
           TextUtils.concat(
                   "SELECT * FROM ",
                   Group.TABLE_NAME,
                   " WHERE ",
                   Group.FACULTET_ID,
                   "=?",
                   " ORDER BY ",
                   Group.LEVEL,
                   ", ",
                   Group.GROUP_TITLE)
               .toString(),
           new String[] {facultetId.toString()});
   Group group = null;
   while (c.moveToNext()) {
     group = new Group();
     group.setId(c.getLong(c.getColumnIndex(Group.ID)));
     group.setTitle(c.getString(c.getColumnIndex(Group.GROUP_TITLE)));
     group.setLevel(c.getInt(c.getColumnIndex(Group.LEVEL)));
     group.setFacultetId(c.getLong(c.getColumnIndex(Group.FACULTET_ID)));
     result.add(group);
   }
   return result;
 }
Esempio n. 2
0
  public void saveGroup(Collection<Group> list, Long facultetId) {

    try {
      mDb.beginTransaction();
      for (Group group : list) {
        mSaveGroupStatement.clearBindings();
        mSaveGroupStatement.bindLong(1, group.getId());
        mSaveGroupStatement.bindString(2, group.getTitle().trim());
        mSaveGroupStatement.bindLong(3, group.getLevel());
        mSaveGroupStatement.bindLong(4, facultetId);
        mSaveGroupStatement.execute();
      }
      mDb.setTransactionSuccessful();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      mDb.endTransaction();
      notifyObservers();
    }
  }