Android Open Source - Gradulator Course Db Helper






From Project

Back to project page Gradulator.

License

The source code is released under:

MIT License

If you think the Android project Gradulator 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

/*
The MIT License (MIT)//w  ww .j  a  va 2 s . c om

Copyright (c) 2014 Gannon Lawlor

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.gannon.gradulator.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.gannon.gradulator.database.CourseContract.CourseEntry;

public class CourseDbHelper extends SQLiteOpenHelper {

    private static CourseDbHelper sInstance;
    private static final String TEXT_TYPE = " TEXT";
    private static final String REAL_TYPE = " REAL";
    private static final String INT_TYPE = " INTEGER";
    private static final String COMMA_SEP = ",";

    // Create a table to hold all the courses
    private static final String SQL_CREATE_COURSES_TABLE =
            "CREATE TABLE " + CourseEntry.TABLE_COURSES + " (" +
                    CourseEntry._ID + " INTEGER PRIMARY KEY," +
                    CourseEntry.COLUMN_COURSE_NAME + TEXT_TYPE + COMMA_SEP +
                    CourseEntry.COLUMN_COURSE_GRADE + REAL_TYPE +
                    " )";

    // Create a table to hold all the evaluations
    private static final String SQL_CREATE_EVALUATION_TABLE =
            "CREATE TABLE " + CourseEntry.TABLE_EVALUATION + " (" +
                    CourseEntry._ID + " INTEGER PRIMARY KEY," +
                    CourseEntry.COLUMN_COURSE_ID + INT_TYPE + COMMA_SEP +
                    CourseEntry.COLUMN_EVALUATION_NAME + TEXT_TYPE + COMMA_SEP +
                    CourseEntry.COLUMN_EVALUATION_GRADE + REAL_TYPE + COMMA_SEP +
                    CourseEntry.COLUMN_EVALUATION_VALUE + REAL_TYPE +
                    " )";



    private static final String SQL_DELETE_COURSE_TABLE = "DROP TABLE IF EXISTS " + CourseEntry.TABLE_COURSES;
    private static final String SQL_DELETE_EVALUATION_TABLE = "DROP TABLE IF EXISTS " + CourseEntry.TABLE_EVALUATION;
    // If you chang ethe database schema, you must increment the database version
    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "Gradulator.db";

    public static CourseDbHelper getInstance(Context context) {
        if (sInstance == null) {
            sInstance = new CourseDbHelper(context.getApplicationContext());
        }
        return sInstance;
    }

    private CourseDbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_COURSES_TABLE);
        db.execSQL(SQL_CREATE_EVALUATION_TABLE);
    }

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SQL_DELETE_COURSE_TABLE);
        db.execSQL(SQL_DELETE_EVALUATION_TABLE);
        onCreate(db);
    }

    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        onUpgrade(db, oldVersion, newVersion);
    }


}




Java Source Code List

com.gannon.gradulator.ApplicationTest.java
com.gannon.gradulator.CourseActivity.java
com.gannon.gradulator.EvaluationActivity.java
com.gannon.gradulator.MainActivity.java
com.gannon.gradulator.adapters.CourseAdapter.java
com.gannon.gradulator.adapters.EvaluationAdapter.java
com.gannon.gradulator.database.CourseContract.java
com.gannon.gradulator.database.CourseDataSource.java
com.gannon.gradulator.database.CourseDbHelper.java
com.gannon.gradulator.database.EvaluationDataSource.java
com.gannon.gradulator.dialogfragments.AddCourseDialogFragment.java
com.gannon.gradulator.dialogfragments.DeleteCourseDialogFragment.java
com.gannon.gradulator.dialogfragments.DeleteEvaluationDialogFragment.java
com.gannon.gradulator.models.Course.java
com.gannon.gradulator.models.Evaluation.java