Android Open Source - Mamytas Provider Db Helper






From Project

Back to project page Mamytas.

License

The source code is released under:

GNU General Public License

If you think the Android project Mamytas listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package mn.aug.restfulandroid.provider;
/*from w  w w  . j a va 2 s.c o m*/
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


/**
 * This creates, updates, and opens the database.  Opening is handled by the superclass, we handle
 * the create & upgrade steps
 */
public class ProviderDbHelper extends SQLiteOpenHelper {

     private int count=0;
     private SQLiteDatabase bdd=null;

    //Name of the database file
    public static final String DATABASE_NAME = "wunderlist.db";
    public static final int DATABASE_VERSION = 1;
    //Strings for the COMMENTS TABLE
    public static final String TABLE_COMMENTS = "comments";
    public static final String COMMENTS_ID = "_id";
    public static final String COMMENTS_STATE = "state";
    public static final String COMMENTS_TEXT = "text";
    public static final String COMMENTS_TASK_ID = "task_id";
    // COMMENTS database creation sql statement
    public static final String COMMENTS_CREATE =
            "create table " + TABLE_COMMENTS + "("
                    + COMMENTS_ID + " integer primary key autoincrement, "
                    + COMMENTS_STATE + " text, "
                    + COMMENTS_TEXT + " text, "
                    + COMMENTS_TASK_ID + " integer "
                    + ");";
    //Strings for the LISTS TABLE
    public static final String TABLE_LISTS = "lists";
    public static final String LISTS_ID = "_id";
    public static final String LISTS_STATE = "state";
    public static final String LISTS_TITLE = "title";
    // LISTS database creation sql statement
    public static final String LISTS_CREATE =
            "create table " + TABLE_LISTS + "("
                    + LISTS_ID + " integer primary key autoincrement, "
                    + LISTS_STATE + " text, "
                    + LISTS_TITLE + " text "
                    + ");";

    //Strings for the OWNERSHIP TABLE
    public static final String TABLE_OWNERSHIP = "ownership";
    public static final String OWNERSHIP_ID = "_id";
    public static final String OWNERSHIP_STATE = "state";
    public static final String OWNERSHIP_TYPE = "type";
    public static final String OWNERSHIP_OWNER = "owner";
    public static final String OWNERSHIP_EFFECTIVE_ID = "effective_id";
    public static final String OWNERSHIP_TIMER = "timer";
    public static final String OWNERSHIP_TIMER_START = "timer_start";
    // OWNERSHIP database creation sql statement
    public static final String OWNERSHIP_CREATE =
            "create table " + TABLE_OWNERSHIP + "("
                    + OWNERSHIP_ID + " integer primary key autoincrement, "
                    + OWNERSHIP_TYPE + " text, "
                    + OWNERSHIP_OWNER + " text, "
                    + OWNERSHIP_EFFECTIVE_ID + " integer, "
                    + OWNERSHIP_STATE + " text, "
                    + OWNERSHIP_TIMER + " text, "
                    + OWNERSHIP_TIMER_START + " text "
                    + ");";
    //Strings for the REMINDERS TABLE
    public static final String TABLE_REMINDERS = "reminders";
    public static final String REMINDERS_ID = "_id";
    public static final String REMINDERS_STATE = "state";
    public static final String REMINDERS_DATE = "date";
    public static final String REMINDERS_OWNER = "owner";
    public static final String REMINDERS_TASK_ID = "task_id";
    // REMINDERS database creation sql statement
    public static final String REMINDERS_CREATE =
            "create table " + TABLE_REMINDERS + "("
                    + REMINDERS_ID + " integer primary key autoincrement, "
                    + REMINDERS_STATE + " text, "
                    + REMINDERS_OWNER + " text , "
                    + REMINDERS_DATE + " text, "
                    + REMINDERS_TASK_ID + " integer "
                    + ");";
    //Strings for the TODOS TABLE
    public static final String TABLE_TODOS = "todos";
    public static final String TODOS_ID = "_id";
    public static final String TODOS_STATE = "state";
    public static final String TODOS_TITLE = "title";
    public static final String TODOS_DUE_DATE = "due_date";
    public static final String TODOS_LIST_ID = "list_id";
    // TODOS database creation sql statement
    public static final String TODOS_CREATE =
            "create table " + TABLE_TODOS + "("
                    + TODOS_ID + " integer primary key autoincrement, "
                    + TODOS_STATE + " text, "
                    + TODOS_TITLE + " text, "
                    + TODOS_DUE_DATE + " text, "
                    + TODOS_LIST_ID + " integer "
                    + ");";
    //Strings for the USERS TABLE
    public static final String TABLE_USERS = "users";
    public static final String USERS_ID = "_id";
    public static final String USERS_STATE = "state";
    public static final String USERS_NAME = "name";
    public static final String USERS_PASSWORD = "password";
    // USERS database creation sql statement
    public static final String USERS_CREATE =
            "create table " + TABLE_USERS + "("
                    + USERS_ID + " integer primary key autoincrement, "
                    + USERS_STATE + " text, "
                    + USERS_NAME + " text, "
                    + USERS_PASSWORD + " text "
                    + ")";
    public final String TAG = getClass().getSimpleName();


    public ProviderDbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(COMMENTS_CREATE);
        db.execSQL(OWNERSHIP_CREATE);
        db.execSQL(LISTS_CREATE);
        db.execSQL(REMINDERS_CREATE);
        db.execSQL(TODOS_CREATE);
        db.execSQL(USERS_CREATE);


    }

    public SQLiteDatabase openBDD(){
        if (bdd==null)
            bdd = getWritableDatabase();
        count++;
        return bdd;
    }

    public boolean closeBDD(){
        count--;
        if (count==0) {
            bdd.close();
            bdd=null;
            return true;
        }else{
            return false;
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_COMMENTS);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_OWNERSHIP);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_LISTS);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_REMINDERS);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_TODOS);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
        onCreate(db);
    }

}




Java Source Code List

mn.aug.restfulandroid.activity.AboutActivity.java
mn.aug.restfulandroid.activity.LoginActivity.java
mn.aug.restfulandroid.activity.ProjectEditor.java
mn.aug.restfulandroid.activity.ProjectsActivity.java
mn.aug.restfulandroid.activity.ProjectsArrayAdapter.java
mn.aug.restfulandroid.activity.TaskActivity.java
mn.aug.restfulandroid.activity.TaskEditor.java
mn.aug.restfulandroid.activity.TasksActivity.java
mn.aug.restfulandroid.activity.TasksArrayAdapter.java
mn.aug.restfulandroid.activity.TimerServiceHelper.java
mn.aug.restfulandroid.activity.TimerService.java
mn.aug.restfulandroid.activity.TimersArrayAdapter.java
mn.aug.restfulandroid.activity.base.RESTfulActivity.java
mn.aug.restfulandroid.activity.base.RESTfulListActivity.java
mn.aug.restfulandroid.activity.base.UndoBarController.java
mn.aug.restfulandroid.provider.CommentsDBAccess.java
mn.aug.restfulandroid.provider.ListsDBAccess.java
mn.aug.restfulandroid.provider.OwnershipDBAccess.java
mn.aug.restfulandroid.provider.ProviderDbHelper.java
mn.aug.restfulandroid.provider.RemindersDBAccess.java
mn.aug.restfulandroid.provider.TasksDBAccess.java
mn.aug.restfulandroid.provider.UsersDBAccess.java
mn.aug.restfulandroid.rest.AbstractRestMethod.java
mn.aug.restfulandroid.rest.DeleteListRestMethod.java
mn.aug.restfulandroid.rest.DeleteTaskRestMethod.java
mn.aug.restfulandroid.rest.GetListsRestMethod.java
mn.aug.restfulandroid.rest.GetTasksRestMethod.java
mn.aug.restfulandroid.rest.GetTimersRestMethod.java
mn.aug.restfulandroid.rest.LoginRestMethod.java
mn.aug.restfulandroid.rest.PostListRestMethod.java
mn.aug.restfulandroid.rest.PostTaskRestMethod.java
mn.aug.restfulandroid.rest.PostTimerRestMethod.java
mn.aug.restfulandroid.rest.PutListRestMethod.java
mn.aug.restfulandroid.rest.PutTaskRestMethod.java
mn.aug.restfulandroid.rest.PutTimerRestMethod.java
mn.aug.restfulandroid.rest.Request.java
mn.aug.restfulandroid.rest.Response.java
mn.aug.restfulandroid.rest.RestClient.java
mn.aug.restfulandroid.rest.RestMethodFactory.java
mn.aug.restfulandroid.rest.RestMethodResult.java
mn.aug.restfulandroid.rest.RestMethod.java
mn.aug.restfulandroid.rest.ShareListRestMethod.java
mn.aug.restfulandroid.rest.resource.Comment.java
mn.aug.restfulandroid.rest.resource.Lists.java
mn.aug.restfulandroid.rest.resource.Listw.java
mn.aug.restfulandroid.rest.resource.Login.java
mn.aug.restfulandroid.rest.resource.Reminder.java
mn.aug.restfulandroid.rest.resource.Resource.java
mn.aug.restfulandroid.rest.resource.TaskList.java
mn.aug.restfulandroid.rest.resource.Task.java
mn.aug.restfulandroid.rest.resource.Tasks.java
mn.aug.restfulandroid.rest.resource.Timer.java
mn.aug.restfulandroid.rest.resource.Timers.java
mn.aug.restfulandroid.security.AuthorizationManager.java
mn.aug.restfulandroid.security.RequestSigner.java
mn.aug.restfulandroid.service.ListProcessor.java
mn.aug.restfulandroid.service.ListsProcessor.java
mn.aug.restfulandroid.service.LoginProcessor.java
mn.aug.restfulandroid.service.ProcessorCallback.java
mn.aug.restfulandroid.service.ShareProcessor.java
mn.aug.restfulandroid.service.TaskProcessor.java
mn.aug.restfulandroid.service.TasksProcessor.java
mn.aug.restfulandroid.service.TimersProcessor.java
mn.aug.restfulandroid.service.WunderlistServiceHelper.java
mn.aug.restfulandroid.service.WunderlistService.java
mn.aug.restfulandroid.util.DateHelper.java
mn.aug.restfulandroid.util.DatePickerFragment.java
mn.aug.restfulandroid.util.Logger.java
mn.aug.restfulandroid.util.TimePickerFragment.java