Created conversations list database contract

This commit is contained in:
Pierre 2017-12-13 18:05:34 +01:00
parent 32757d3f35
commit 6c0ea90ff8
3 changed files with 71 additions and 10 deletions

View File

@ -55,7 +55,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -15,8 +15,8 @@ public final class DatabaseContract {
public DatabaseContract(){} public DatabaseContract(){}
/* Database basic information */ /* Database basic information */
public static final int DATABASE_VERSION = 2; static final int DATABASE_VERSION = 3;
public static final String DATABASE_NAME = "database.db"; static final String DATABASE_NAME = "database.db";
/* Users info table */ /* Users info table */
public static abstract class UsersInfoSchema implements BaseColumns { public static abstract class UsersInfoSchema implements BaseColumns {
@ -40,4 +40,17 @@ public final class DatabaseContract {
} }
/* Conversations list table */
public static abstract class ConversationsListSchema implements BaseColumns {
public static final String TABLE_NAME = "conversations_list";
public static final String COLUMN_NAME_CONVERSATION_ID = "conversation_id";
public static final String COLUMN_NAME_CONVERSATION_ID_OWNER = "id_owner";
public static final String COLUMN_NAME_CONVERSATION_LAST_ACTIVE = "last_active";
public static final String COLUMN_NAME_CONVERSATION_NAME = "name";
public static final String COLUMN_NAME_CONVERSATION_FOLLOWING = "following";
public static final String COLUMN_NAME_CONVERSATION_SAW_LAST_MESSAGES = "saw_last_message";
public static final String COLUMN_NAME_CONVERSATION_MEMBERS = "members";
}
} }

View File

@ -6,6 +6,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import org.communiquons.android.comunic.client.data.DatabaseContract.FriendsListSchema; import org.communiquons.android.comunic.client.data.DatabaseContract.FriendsListSchema;
import org.communiquons.android.comunic.client.data.DatabaseContract.UsersInfoSchema; import org.communiquons.android.comunic.client.data.DatabaseContract.UsersInfoSchema;
import org.communiquons.android.comunic.client.data.DatabaseContract.ConversationsListSchema;
/** /**
* Database helper. This file handles the creation / upgrade of the local database * Database helper. This file handles the creation / upgrade of the local database
@ -54,6 +55,26 @@ public class DatabaseHelper extends SQLiteOpenHelper {
private static final String SQL_DELETE_FRIENDS_LIST_TABLE = "DROP TABLE IF EXISTS " + private static final String SQL_DELETE_FRIENDS_LIST_TABLE = "DROP TABLE IF EXISTS " +
FriendsListSchema.TABLE_NAME; FriendsListSchema.TABLE_NAME;
/**
* Creation and deletion of the conversations list table
*/
private static final String SQL_CREATE_CONVERSATIONS_LIST_TABLE =
"CREATE TABLE " + ConversationsListSchema.TABLE_NAME + " (" +
ConversationsListSchema._ID + " INTEGER PRIMARY KEY," +
ConversationsListSchema.COLUMN_NAME_CONVERSATION_ID + INTEGER_TYPE + COMMA_SEP +
ConversationsListSchema.COLUMN_NAME_CONVERSATION_ID_OWNER + INTEGER_TYPE + COMMA_SEP +
ConversationsListSchema.COLUMN_NAME_CONVERSATION_LAST_ACTIVE + INTEGER_TYPE + COMMA_SEP +
ConversationsListSchema.COLUMN_NAME_CONVERSATION_NAME + TEXT_TYPE + COMMA_SEP +
ConversationsListSchema.COLUMN_NAME_CONVERSATION_FOLLOWING + INTEGER_TYPE + COMMA_SEP +
ConversationsListSchema.COLUMN_NAME_CONVERSATION_SAW_LAST_MESSAGES + INTEGER_TYPE + COMMA_SEP +
ConversationsListSchema.COLUMN_NAME_CONVERSATION_MEMBERS + TEXT_TYPE + COMMA_SEP +
" )";
private static final String SQL_DELETE_CONVERSATIONS_LIST_TABLE = "DROP TABLE IF EXISTS " +
ConversationsListSchema.TABLE_NAME;
/** /**
* Public constructor * Public constructor
* @param context The context where the database is used * @param context The context where the database is used
@ -63,27 +84,54 @@ public class DatabaseHelper extends SQLiteOpenHelper {
} }
/** /**
* Handles database creation * Initialize the database
* @param db The database *
* @param db Database object
*/ */
@Override public void init_db(SQLiteDatabase db){
public void onCreate(SQLiteDatabase db) {
//Create user informations table //Create user informations table
db.execSQL(SQL_CREATE_USERS_INFOS_TABLE); db.execSQL(SQL_CREATE_USERS_INFOS_TABLE);
//Create friends list table //Create friends list table
db.execSQL(SQL_CREATE_FRIENDS_LIST_TABLE); db.execSQL(SQL_CREATE_FRIENDS_LIST_TABLE);
//Create conversations list table
db.execSQL(SQL_CREATE_CONVERSATIONS_LIST_TABLE);
} }
@Override /**
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { * Clear the whole content of the database
*
* @param db The database
*/
public void clear_db(SQLiteDatabase db){
//Delete users informations table //Delete users informations table
db.execSQL(SQL_DELETE_USERS_INFOS_TABLE); db.execSQL(SQL_DELETE_USERS_INFOS_TABLE);
//Delete friends list table //Delete friends list table
db.execSQL(SQL_DELETE_FRIENDS_LIST_TABLE); db.execSQL(SQL_DELETE_FRIENDS_LIST_TABLE);
//Perform creation table //Delete conversations list table
db.execSQL(SQL_DELETE_CONVERSATIONS_LIST_TABLE);
}
/**
* Handles database creation
* @param db The database
*/
@Override
public void onCreate(SQLiteDatabase db) {
init_db(db);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//Clear the database
clear_db(db);
//Perform tables creation
onCreate(db); onCreate(db);
} }