Esempio n. 1
0
 private List<Tweet> getTweets(final String where, final String[] whereArgs, final int numberOf) {
   if (!checkDbOpen()) return null;
   Cursor c = null;
   try {
     c =
         this.mDb.query(
             true,
             TBL_TW,
             new String[] {
               TBL_TW_ID,
               TBL_TW_SID,
               TBL_TW_USERNAME,
               TBL_TW_FULLNAME,
               TBL_TW_BODY,
               TBL_TW_TIME,
               TBL_TW_AVATAR
             },
             where,
             whereArgs,
             null,
             null,
             TBL_TW_TIME + " desc",
             String.valueOf(numberOf));
     return readTweets(c);
   } finally {
     IoHelper.closeQuietly(c);
   }
 }
Esempio n. 2
0
  @Override
  public String getValue(final String key) {
    if (!checkDbOpen()) return null;
    String ret = null;
    Cursor c = null;
    try {
      c =
          this.mDb.query(
              true,
              TBL_KV,
              new String[] {TBL_KV_VAL},
              TBL_KV_KEY + "=?",
              new String[] {key},
              null,
              null,
              null,
              null);

      if (c != null && c.moveToFirst()) {
        final int colVal = c.getColumnIndex(TBL_KV_VAL);
        ret = c.getString(colVal);
      }
    } finally {
      IoHelper.closeQuietly(c);
    }
    if (ret == null) {
      this.log.d("Read KV: '%s' = null.", key);
    } else {
      this.log.d("Read KV: '%s' = '%s'.", key, ret);
    }
    return ret;
  }
Esempio n. 3
0
 @Override
 public List<Tweet> findTweetsWithMeta(
     final MetaType metaType, final String data, final int numberOf) {
   if (!checkDbOpen()) return null;
   Cursor c = null;
   try {
     final SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
     qb.setTables(
         TBL_TW
             + " INNER JOIN "
             + TBL_TM
             + " ON "
             + TBL_TW
             + "."
             + TBL_TW_ID
             + " = "
             + TBL_TM_TWID);
     qb.setDistinct(true);
     c =
         qb.query(
             this.mDb,
             new String[] {
               TBL_TW + "." + TBL_TW_ID,
               TBL_TW_SID,
               TBL_TW_USERNAME,
               TBL_TW_FULLNAME,
               TBL_TW_BODY,
               TBL_TW_TIME,
               TBL_TW_AVATAR
             },
             TBL_TW
                 + "."
                 + TBL_TW_ID
                 + "="
                 + TBL_TM_TWID
                 + " AND "
                 + TBL_TM_TYPE
                 + "="
                 + metaType.getId()
                 + " AND "
                 + TBL_TM_DATA
                 + "=?",
             new String[] {data},
             TBL_TW_SID,
             null,
             TBL_TW_TIME + " desc",
             String.valueOf(numberOf));
     return readTweets(c);
   } finally {
     IoHelper.closeQuietly(c);
   }
 }
Esempio n. 4
0
 private static boolean isTableExists(final SQLiteDatabase db, final String tableName) {
   Cursor c = null;
   try {
     c =
         db.rawQuery(
             "SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name=?",
             new String[] {tableName});
     if (c.getCount() > 0) return true;
     return false;
   } finally {
     IoHelper.closeQuietly(c);
   }
 }
Esempio n. 5
0
  @Override
  public ScrollState getScroll(final int columnId) {
    if (!checkDbOpen()) return null;
    ScrollState ret = null;
    Cursor c = null;
    try {
      c =
          this.mDb.query(
              true,
              TBL_SC,
              new String[] {TBL_SC_ITEMID, TBL_SC_TOP, TBL_SC_TIME, TBL_SC_UNREAD},
              TBL_TW_COLID + "=?",
              new String[] {String.valueOf(columnId)},
              null,
              null,
              null,
              null);

      if (c != null && c.moveToFirst()) {
        final int colItemId = c.getColumnIndex(TBL_SC_ITEMID);
        final int colTop = c.getColumnIndex(TBL_SC_TOP);
        final int colTime = c.getColumnIndex(TBL_SC_TIME);
        final int colUnread = c.getColumnIndex(TBL_SC_UNREAD);

        final long itemId = c.getLong(colItemId);
        final int top = c.getInt(colTop);
        final long time = c.getLong(colTime);
        final long unread = c.getLong(colUnread);
        ret = new ScrollState(itemId, top, time, unread);
      }
    } finally {
      IoHelper.closeQuietly(c);
    }

    this.log.d("Read scroll for col %d: %s", columnId, ret);
    return ret;
  }
Esempio n. 6
0
  private List<OutboxTweet> getOutboxEntries(final String where, final String[] whereArgs) {
    if (!checkDbOpen()) return null;
    Cursor c = null;
    try {
      c =
          this.mDb.query(
              true,
              TBL_OB,
              new String[] {
                TBL_OB_ID,
                TBL_OB_ACCOUNT_ID,
                TBL_OB_SERVICES,
                TBL_OB_BODY,
                TBL_OB_IN_REPLY_TO_SID,
                TBL_OB_ATTACHMENT,
                TBL_OB_STATUS,
                TBL_OB_ATTEMPT_COUNT,
                TBL_OB_LAST_ERROR
              },
              where,
              whereArgs,
              null,
              null,
              TBL_OB_ID + " asc",
              null);

      if (c != null && c.moveToFirst()) {
        final int colId = c.getColumnIndex(TBL_OB_ID);
        final int colAccountId = c.getColumnIndex(TBL_OB_ACCOUNT_ID);
        final int colServices = c.getColumnIndex(TBL_OB_SERVICES);
        final int colBody = c.getColumnIndex(TBL_OB_BODY);
        final int colInReplyToSid = c.getColumnIndex(TBL_OB_IN_REPLY_TO_SID);
        final int colAttachment = c.getColumnIndex(TBL_OB_ATTACHMENT);
        final int colStatus = c.getColumnIndex(TBL_OB_STATUS);
        final int colAttemptCount = c.getColumnIndex(TBL_OB_ATTEMPT_COUNT);
        final int colLastError = c.getColumnIndex(TBL_OB_LAST_ERROR);

        final List<OutboxTweet> ret = new ArrayList<OutboxTweet>();
        do {
          final long uid = c.getLong(colId);
          final String accountId = c.getString(colAccountId);
          final String svcMetas = c.getString(colServices);
          final String body = c.getString(colBody);
          final String inReplyToSid = c.getString(colInReplyToSid);
          final String attachment = c.getString(colAttachment);
          final Integer status = c.getInt(colStatus);
          final Integer attemptCount = c.getInt(colAttemptCount);
          final String lastError = c.getString(colLastError);
          ret.add(
              new OutboxTweet(
                  uid,
                  accountId,
                  svcMetas,
                  body,
                  inReplyToSid,
                  attachment,
                  status,
                  attemptCount,
                  lastError));
        } while (c.moveToNext());
        return ret;
      }
      return Collections.EMPTY_LIST;
    } finally {
      IoHelper.closeQuietly(c);
    }
  }
Esempio n. 7
0
  private Tweet getTweetDetails(final String selection, final String[] selectionArgs) {
    if (!checkDbOpen()) return null;
    Tweet ret = null;
    Cursor c = null;
    Cursor d = null;
    try {
      c =
          this.mDb.query(
              true,
              TBL_TW,
              new String[] {
                TBL_TW_ID,
                TBL_TW_SID,
                TBL_TW_USERNAME,
                TBL_TW_FULLNAME,
                TBL_TW_BODY,
                TBL_TW_TIME,
                TBL_TW_AVATAR
              },
              selection,
              selectionArgs,
              null,
              null,
              null,
              null);

      if (c != null && c.moveToFirst()) {
        final int colId = c.getColumnIndex(TBL_TW_ID);
        final int colSid = c.getColumnIndex(TBL_TW_SID);
        final int colUesrname = c.getColumnIndex(TBL_TW_USERNAME);
        final int colFullname = c.getColumnIndex(TBL_TW_FULLNAME);
        final int colBody = c.getColumnIndex(TBL_TW_BODY);
        final int colTime = c.getColumnIndex(TBL_TW_TIME);
        final int colAvatar = c.getColumnIndex(TBL_TW_AVATAR);

        final long uid = c.getLong(colId);
        final String sid = c.getString(colSid);
        final String username = c.getString(colUesrname);
        final String fullname = c.getString(colFullname);
        final String body = c.getString(colBody);
        final long time = c.getLong(colTime);
        final String avatar = c.getString(colAvatar);

        List<Meta> metas = null;
        try {
          d =
              this.mDb.query(
                  true,
                  TBL_TM,
                  new String[] {TBL_TM_TYPE, TBL_TM_DATA, TBL_TM_TITLE},
                  TBL_TM_TWID + "=?",
                  new String[] {String.valueOf(uid)},
                  null,
                  null,
                  null,
                  null);

          if (d != null && d.moveToFirst()) {
            final int colType = d.getColumnIndex(TBL_TM_TYPE);
            final int colData = d.getColumnIndex(TBL_TM_DATA);
            final int colTitle = d.getColumnIndex(TBL_TM_TITLE);

            metas = new ArrayList<Meta>();
            do {
              final int typeId = d.getInt(colType);
              final String data = d.getString(colData);
              final String title = d.getString(colTitle);
              metas.add(new Meta(MetaType.parseId(typeId), data, title));
            } while (d.moveToNext());
          }
        } finally {
          IoHelper.closeQuietly(d);
        }

        ret = new Tweet(uid, sid, username, fullname, body, time, avatar, metas);
      }
    } finally {
      IoHelper.closeQuietly(c);
    }
    return ret;
  }