示例#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;
  }
示例#2
0
  public List<Group> getGroups(LocalAccount account, Paging<Group> paging) {
    List<Group> groupList = null;
    if (account == null || paging == null) {
      return groupList;
    }

    String sql =
        "select "
            + "    * "
            + "from "
            + "    Group_Info "
            + "where "
            + "    State != "
            + LocalGroup.STATE_DELETED
            + " and "
            + "    Account_ID = "
            + account.getAccountId()
            + " "
            + "order by Created_At asc";

    groupList = find(sql, paging.getPageIndex(), paging.getPageSize());
    if (ListUtil.isEmpty(groupList) || groupList.size() < paging.getPageSize() / 2) {
      paging.setLastPage(true);
    }

    return groupList;
  }
示例#3
0
 public List<Group> findAll(LocalAccount account) {
   if (account == null) {
     return null;
   }
   String sql =
       "select * from Group_Info where Account_ID = "
           + account.getAccountId()
           + " and State != "
           + LocalGroup.STATE_DELETED;
   return find(sql);
 }
示例#4
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;
  }
示例#5
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);
 }
示例#6
0
 public void push_back(LocalAccount _obj) {
   VISHNUJNI.ELocalAccList_push_back(swigCPtr, this, LocalAccount.getCPtr(_obj), _obj);
 }
示例#7
0
 public void insert_at(long _pos, LocalAccount _obj) {
   VISHNUJNI.ELocalAccList_insert_at(swigCPtr, this, _pos, LocalAccount.getCPtr(_obj), _obj);
 }