public void insertNewItems(RssFile[] items) { database.beginTransaction(); List<Integer> rssItems = getRssItemsIds(); try { for (RssFile item : items) { if (item != null) { Integer itemId = Integer.parseInt(item.getItem_Id()); boolean isFeedAlreadyInDatabase = rssItems.contains(itemId); // doesRssItemAlreadyExsists(item.getItem_Id()); insertNewItem(item, !isFeedAlreadyInDatabase); } } database.setTransactionSuccessful(); } catch (SQLException e) { e.printStackTrace(); } finally { database.endTransaction(); } }
public void insertNewItem(RssFile item, boolean insertItem) { ContentValues contentValues = new ContentValues(); contentValues.put(RSS_ITEM_TITLE, item.getTitle()); contentValues.put(RSS_ITEM_LINK, item.getLink()); contentValues.put(RSS_ITEM_BODY, item.getDescription()); contentValues.put(RSS_ITEM_READ, item.getRead()); contentValues.put(RSS_ITEM_SUBSCRIPTION_ID, String.valueOf(item.getFeedID_Db())); contentValues.put(RSS_ITEM_RSSITEM_ID, item.getItem_Id()); contentValues.put(RSS_ITEM_PUBDATE, item.getDate().getTime()); contentValues.put(RSS_ITEM_STARRED, item.getStarred()); contentValues.put(RSS_ITEM_GUID, item.getGuid()); contentValues.put(RSS_ITEM_GUIDHASH, item.getGuidHash()); contentValues.put(RSS_ITEM_LAST_MODIFIED, item.getLastModified()); contentValues.put(RSS_ITEM_AUTHOR, item.getAuthor()); contentValues.put(RSS_ITEM_READ_TEMP, item.getRead()); contentValues.put(RSS_ITEM_STARRED_TEMP, item.getStarred()); long result; if (insertItem) result = database.insert(RSS_ITEM_TABLE, null, contentValues); else result = database.update( RSS_ITEM_TABLE, contentValues, RSS_ITEM_RSSITEM_ID + "=?", new String[] {item.getItem_Id()}); // Log.d("DatabaseConnection", "Inserted Rows: " + result); }