From 93dfb68e4f97786006592d0f70a8d488162976d6 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Fri, 5 Oct 2012 12:14:32 -0400 Subject: [PATCH] Updated database to use an easier to use format. Added 3 more tables to store id's of forums, topics, and threads. I also renamed existing tables to better describe their job. the following tables are now used: forums stores ids of forums topics stores ids of topics, and parent forums threads stores ids of threads, and parent topics & forums forum_info stores key value pairs topic_info stores key value pairs thread_info stores key value pairs Signed-off-by: Ricky Barrette --- OSJ Forum/AndroidManifest.xml | 2 +- .../osj/forum/database/ForumDatabase.java | 76 ++++++++++++++----- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/OSJ Forum/AndroidManifest.xml b/OSJ Forum/AndroidManifest.xml index 99fcb8f..cc9164c 100644 --- a/OSJ Forum/AndroidManifest.xml +++ b/OSJ Forum/AndroidManifest.xml @@ -1,5 +1,5 @@ contentHash = (HashMap) element; - upsertForumTable((String) contentHash.get("forum_id"), convertHashMapToContentValues(contentHash)); + id = (String) contentHash.get("forum_id"); + upsertForumTable(id, convertHashMapToContentValues(contentHash)); if (isRecursive) saveTopics(client, contentHash.get("forum_id"), isRecursive); } + } } /** @@ -466,10 +491,14 @@ public class ForumDatabase { private void upsertForumTable(final String forumId, final List values) throws NullPointerException { if (values == null) throw new NullPointerException("values was null"); + + ContentValues id = new ContentValues(); + id.put(KEY_ID, forumId); + upsertTable(TABLE_FORUMS, KEY_ID +" = "+ forumId, id); for (final ContentValues item : values) { item.put(KEY_FORUM_ID, forumId); - upsertTable(FORUM_TABLE, + upsertTable(TABLE_FORUM_INFO, KEY + " = " + DatabaseUtils.sqlEscapeString(item.getAsString(KEY) + " AND " + KEY_FORUM_ID + " = " + DatabaseUtils.sqlEscapeString(forumId)), item); } } @@ -501,13 +530,19 @@ public class ForumDatabase { private void upsertThreadTable(final String forumId, final String topicId, final String postId, final List values) throws NullPointerException { if (values == null) throw new NullPointerException("values was null"); + + ContentValues id = new ContentValues(); + id.put(KEY_ID, postId); + id.put(KEY_FORUM_ID, forumId); + id.put(KEY_TOPIC_ID, topicId); + upsertTable(TABLE_THREADS, KEY_ID +" = "+ postId, id); for (final ContentValues item : values) { item.put(KEY_FORUM_ID, forumId); item.put(KEY_TOPIC_ID, topicId); item.put(KEY_POST_ID, postId); upsertTable( - THREAD_TABLE, + TABLE_THREAD_INFO, KEY + " = " + DatabaseUtils.sqlEscapeString(item.getAsString(KEY)) + " AND " + KEY_FORUM_ID + " = " + DatabaseUtils.sqlEscapeString(forumId) + " AND " + KEY_TOPIC_ID + " = " + DatabaseUtils.sqlEscapeString(topicId) + " AND " + KEY_POST_ID + " = " + DatabaseUtils.sqlEscapeString(postId), item); @@ -526,11 +561,16 @@ public class ForumDatabase { private void upsertTopicTable(final String forumId, final String topicId, final List values) throws NullPointerException { if (values == null) throw new NullPointerException("values was null"); + + ContentValues id = new ContentValues(); + id.put(KEY_ID, topicId); + id.put(KEY_FORUM_ID, forumId); + upsertTable(TABLE_TOPICS, KEY_ID +" = "+ topicId, id); for (final ContentValues item : values) { item.put(KEY_FORUM_ID, forumId); item.put(KEY_TOPIC_ID, topicId); - upsertTable(TOPIC_TABLE, + upsertTable(TABLE_TOPIC_INFO, KEY + " = " + DatabaseUtils.sqlEscapeString(item.getAsString(KEY)) + " AND " + KEY_FORUM_ID + " = " + DatabaseUtils.sqlEscapeString(forumId) + " AND " + KEY_TOPIC_ID + " = " + DatabaseUtils.sqlEscapeString(topicId), item); }