Exemplo n.º 1
0
  public LocalGroup save(LocalAccount account, Group group) {
    if (isNull(account) || isNull(group)) {
      return null;
    }

    LocalGroup result = getGroup(account, group);
    if (result != null) {
      return result;
    }

    SQLiteDatabase sqLiteDatabase = dbHelper.getWritableDatabase();
    sqLiteDatabase.beginTransaction();
    try {
      long remoteGroupId = 0l;
      Date createdAt = new Date();
      int state = LocalGroup.STATE_ADDED;
      if (group instanceof LocalGroup) {
        LocalGroup localGroup = (LocalGroup) group;
        remoteGroupId = localGroup.getRemoteGroupId();
        createdAt = localGroup.getCreatedAt();
        state = localGroup.getState();

        result = localGroup;
      } else {
        result = new LocalGroup();
      }

      ContentValues values = new ContentValues();
      values.put("SP_Group_ID", group.getId());
      values.put("Remote_Group_ID", remoteGroupId);
      values.put("Group_Name", group.getName());
      values.put("Created_At", createdAt.getTime());
      values.put("State", state);
      values.put("Account_ID", account.getAccountId());

      long rowId = sqLiteDatabase.replace(TABLE, null, values);
      if (group instanceof LocalGroup) {
        result.setGroupId(rowId);
        result.setId(group.getId());
        result.setRemoteGroupId(remoteGroupId);
        result.setName(group.getName());
        result.setCreatedAt(createdAt);
        result.setState(state);
        result.setAccountId(account.getAccountId());
      }
      sqLiteDatabase.setTransactionSuccessful();
    } finally {
      sqLiteDatabase.endTransaction();
    }

    return result;
  }
Exemplo n.º 2
0
  public int delete(LocalAccount account, Group group) {
    if (isNull(account) || isNull(group)) {
      return -1;
    }

    SQLiteDatabase sqLiteDatabase = dbHelper.getWritableDatabase();
    String whereClause =
        "SP_Group_ID = " + group.getId() + " and Account_ID = " + account.getAccountId();
    int rowsAffected = sqLiteDatabase.delete(TABLE, whereClause, null);
    return rowsAffected;
  }
Exemplo n.º 3
0
 public LocalGroup getGroup(LocalAccount account, Group group) {
   if (account == null || group == null) {
     return null;
   }
   String groupName = group.getName();
   if (StringUtil.isNotEmpty(groupName)) {
     groupName = groupName.replace("'", "''");
   }
   String sql =
       "select * from Group_Info where SP_Group_ID = '"
           + group.getId()
           + "' and Account_ID = "
           + account.getAccountId()
           + " and Group_Name = '"
           + groupName
           + "'";
   return (LocalGroup) this.query(sql);
 }