Ejemplo n.º 1
0
  private void update(FeedType feedType, UpdateType updateType) {
    ArticleDao articleDao = DbConnection.getSession().getArticleDao();
    SQLiteDatabase db = articleDao.getDatabase();

    db.beginTransaction();
    try {

      Integer latestID = null;
      if (feedType == FeedType.Main || feedType == FeedType.Archive) {
        WhereCondition cond =
            feedType == FeedType.Main
                ? ArticleDao.Properties.Archive.notEq(true)
                : ArticleDao.Properties.Archive.eq(true);
        List<Article> l =
            articleDao
                .queryBuilder()
                .where(cond)
                .orderDesc(ArticleDao.Properties.ArticleId)
                .limit(1)
                .list();

        if (!l.isEmpty()) {
          latestID = l.get(0).getArticleId();
        }
      }

      if (!updateByFeed(articleDao, feedType, updateType, latestID)) {
        return;
      }

      db.setTransactionSuccessful();
    } finally {
      db.endTransaction();
    }
  }
Ejemplo n.º 2
0
  private void updateAllFeeds() {
    Log.i(TAG, "updateAllFeeds() started");

    ArticleDao articleDao = DbConnection.getSession().getArticleDao();
    SQLiteDatabase db = articleDao.getDatabase();

    Log.d(TAG, "updateAllFeeds() beginning transaction");
    db.beginTransaction();
    try {
      Log.d(TAG, "updateAllFeeds() deleting old articles");
      articleDao.deleteAll();

      Log.d(TAG, "updateAllFeeds() updating Main feed");
      if (!updateByFeed(articleDao, FeedType.Main, UpdateType.Full, 0)) {
        Log.w(TAG, "updateAllFeeds() Main feed update failed; exiting");
        return;
      }

      Log.d(TAG, "updateAllFeeds() updating Archive feed");
      if (!updateByFeed(articleDao, FeedType.Archive, UpdateType.Full, 0)) {
        Log.w(TAG, "updateAllFeeds() Archive feed update failed; exiting");
        return;
      }

      Log.d(TAG, "updateAllFeeds() updating Favorite feed");
      if (!updateByFeed(articleDao, FeedType.Favorite, UpdateType.Fast, 0)) {
        Log.w(TAG, "updateAllFeeds() Favorite feed update failed; exiting");
        return;
      }

      Log.d(TAG, "updateAllFeeds() setting transaction successful");
      db.setTransactionSuccessful();
    } finally {
      Log.d(TAG, "updateAllFeeds() ending transaction");
      db.endTransaction();
    }

    Log.d(TAG, "updateAllFeeds() finished");
  }