mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Created locale database contract and helper
This commit is contained in:
parent
029988fc71
commit
24aa80f63e
@ -0,0 +1,32 @@
|
||||
package org.communiquons.android.comunic.client.data;
|
||||
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
/**
|
||||
* Database contract schema. Contains the structure of the application database
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
* Created by pierre on 11/2/17.
|
||||
*/
|
||||
|
||||
public final class DatabaseContract {
|
||||
|
||||
//Empty constructor : avoid accidentally instantiations of the class
|
||||
public DatabaseContract(){}
|
||||
|
||||
/* Database basic information */
|
||||
public static final int DATABASE_VERSION = 1;
|
||||
public static final String DATABASE_NAME = "database.db";
|
||||
|
||||
/* Users info table */
|
||||
public static abstract class UsersInfo implements BaseColumns {
|
||||
public static final String TABLE_NAME = "users_info";
|
||||
|
||||
public static final String COLUMN_NAME_USER_ID = "user_id";
|
||||
public static final String COLUMN_NAME_USER_FIRSTNAME = "first_name";
|
||||
public static final String COLUMN_NAME_USER_LASTNAME = "last_name";
|
||||
public static final String COLUMN_NAME_USER_ACCOUNT_IMAGE = "account_image";
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package org.communiquons.android.comunic.client.data;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import org.communiquons.android.comunic.client.data.DatabaseContract.UsersInfo;
|
||||
|
||||
/**
|
||||
* Database helper. This file handles the creation / upgrade of the local database
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
* Created by pierre on 11/2/17.
|
||||
*/
|
||||
|
||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
/**
|
||||
* Generic definitions
|
||||
*/
|
||||
private static final String TEXT_TYPE = " TEXT";
|
||||
private static final String INTEGER_TYPE = " INTEGER";
|
||||
private static final String COMMA_SEP = ",";
|
||||
|
||||
/**
|
||||
* Creation and deletion of the users info table
|
||||
*/
|
||||
private static final String SQL_CREATE_USERS_INFOS_TABLE =
|
||||
"CREATE TABLE " + UsersInfo.TABLE_NAME + " (" +
|
||||
UsersInfo._ID + " INTEGER PRIMARY KEY," +
|
||||
UsersInfo.COLUMN_NAME_USER_ID + INTEGER_TYPE + COMMA_SEP +
|
||||
UsersInfo.COLUMN_NAME_USER_FIRSTNAME + TEXT_TYPE + COMMA_SEP +
|
||||
UsersInfo.COLUMN_NAME_USER_LASTNAME + TEXT_TYPE + COMMA_SEP +
|
||||
UsersInfo.COLUMN_NAME_USER_ACCOUNT_IMAGE + TEXT_TYPE
|
||||
+ " )";
|
||||
|
||||
private static final String SQL_DELETE_USERS_INFOS_TABLE = "DROP TABLE IF EXISTS " +
|
||||
UsersInfo.TABLE_NAME;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Public constructor
|
||||
* @param context The context where the database is used
|
||||
*/
|
||||
public DatabaseHelper(Context context){
|
||||
super(context, DatabaseContract.DATABASE_NAME, null, DatabaseContract.DATABASE_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles database creation
|
||||
* @param db The database
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
//Create user informations table
|
||||
db.execSQL(SQL_CREATE_USERS_INFOS_TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
//Delete users informations table
|
||||
db.execSQL(SQL_DELETE_USERS_INFOS_TABLE);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
onUpgrade(db, oldVersion, newVersion);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user