コード例 #1
0
  @Override
  public int add(DBFriendGroupMapping mapping) {
    db = getTransactionDB();

    // 查找user
    DBUser user = userDao.findByAccount(mapping.getUser().getAccount());
    if (user == null) {
      return DBColumns.ERROR_USER_NOT_FOUND;
    }

    // 查找group
    DBFriendGroup fg = fgDao.findByAccount(mapping.getFriendGroup().getAccount());
    if (fg == null) {
      fgDao.add(mapping.getFriendGroup());
    }

    // 是否已经存在
    if (isExists(mapping.getUser().getAccount(), mapping.getFriendGroup().getAccount())) {
      return DBColumns.ERROR_FRIEND_STATE_EXISTS;
    }

    // 添加
    db.execSQL(
        "INSERT INTO "
            + DBColumns.FRIEND_STATE_TABLE_NAME
            + "("
            + DBColumns.FRIEND_STATE_ACCOUNT
            + ","
            + DBColumns.FRIEND_STATE_USER_ACCOUNT
            + ","
            + DBColumns.FRIEND_STATE_FRIEND_GROUP_ACCOUNT
            + ","
            + DBColumns.FRIEND_STATE_LOGIN_STATE
            + ","
            + DBColumns.FRIEND_STATE_LOGIN_CHANNEL
            + ","
            + DBColumns.FRIEND_STATE_POSITION
            + ","
            + DBColumns.FRIEND_STATE_REMARK
            + ") VALUES(?,?,?,?,?,?,?)",
        new String[] {
          mapping.getAccount(),
          mapping.getUser().getAccount(),
          mapping.getFriendGroup().getAccount(),
          mapping.getLoginState() + "",
          mapping.getLoginChannel() + "",
          mapping.getPosition() + "",
          mapping.getRemark()
        });

    return DBColumns.RESULT_OK;
  }
コード例 #2
0
  @Override
  public int update(DBFriendGroupMapping mapping) {
    db = getTransactionDB();

    // 查找是否存在
    DBFriendGroupMapping mp = findByAccount(mapping.getAccount());
    if (mp == null) {
      return DBColumns.ERROR_FRIEND_STATE_NOT_FOUND;
    }

    // 更新
    db.execSQL(
        "UPDATE "
            + DBColumns.FRIEND_STATE_TABLE_NAME
            + " SET "
            + DBColumns.FRIEND_STATE_USER_ACCOUNT
            + "=?,"
            + DBColumns.FRIEND_STATE_FRIEND_GROUP_ACCOUNT
            + "=?,"
            + DBColumns.FRIEND_STATE_LOGIN_STATE
            + "=?,"
            + DBColumns.FRIEND_STATE_LOGIN_CHANNEL
            + "=?,"
            + DBColumns.FRIEND_STATE_POSITION
            + "=?,"
            + DBColumns.FRIEND_STATE_REMARK
            + "=? WHERE "
            + DBColumns.FRIEND_STATE_ACCOUNT
            + "=?",
        new Object[] {
          mapping.getUser().getAccount(),
          mapping.getFriendGroup().getAccount(),
          mapping.getLoginState(),
          mapping.getLoginChannel(),
          mapping.getPosition(),
          mapping.getRemark(),
          mapping.getAccount()
        });

    return DBColumns.RESULT_OK;
  }