Android Open Source - SpeechWriter Database Helper






From Project

Back to project page SpeechWriter.

License

The source code is released under:

MIT License

If you think the Android project SpeechWriter 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 edu.psu.rcy5017.speechwriter;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
//from   w w  w  .j a v a  2s  .  c om
/**
 * A helper class that is responsible for creating and updating the app database, 
 * and for creating all the tables in the database.
 * @author Ryan Yosua
 *
 */
public final class DatabaseHelper extends SQLiteOpenHelper {
    
    private static final String TAG = "DatabaseHelper";
    
    public static final int DATABASE_VERSION = 2;
    public static final String DATABASE_NAME = "PublicSpeakingAssistantDatabase";
    public static final String COLUMN_ID = "_id";

    // Speech Table
    public static final String SPEECH_TABLE_NAME = "Speech";
    public static final String SPEECH_TITLE = "Title";
    public static final String SPEECH_ORDER = "ListOrder";
    
    // NoteCard Table
    public static final String NOTECARD_TABLE_NAME = "Notecard";
    public static final String NOTECARD_TITLE = "Title";
    public static final String NOTECARD_ORDER = "ListOrder";
    public static final String SPEECH_ID = "SpeechID";
    
    // Note Table
    public static final String NOTE_TABLE_NAME = "Note";
    public static final String NOTE_TEXT = "Text";
    public static final String NOTE_ORDER = "ListOrder";
    public static final String NOTECARD_ID = "NoteCardID";
    
    // SpeechRecording Table
    public static final String SPEECH_RECORDING_TABLE_NAME = "SpeechRecording";
    public static final String SPEECH_RECORDING_TITLE = "Title";
    public static final String SPEECH_RECORDING_ORDER = "ListOrder";
    
    
    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    
    @Override
    public void onCreate(SQLiteDatabase db) {
        createSpeechTable(db);
        createNoteCardTable(db);
        createNoteTable(db);
        createSpeechRecording(db);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Do nothing.
    }
    
    @Override
    public void onConfigure(SQLiteDatabase db) {
        super.onConfigure(db);
        db.setForeignKeyConstraintsEnabled(true);
    }
    
    private void createSpeechTable(SQLiteDatabase db) {
        final String createStatement =
                    "CREATE TABLE " + SPEECH_TABLE_NAME + " (" +
                            COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                            SPEECH_TITLE + " TEXT NOT NULL," +
                            SPEECH_ORDER + " INTEGER NOT NULL" +
                    ");";
        
        db.execSQL(createStatement);
    }
    
    private void createNoteCardTable(SQLiteDatabase db) {
        final String createStatement =
                "CREATE TABLE " + NOTECARD_TABLE_NAME + " (" +
                        COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                        NOTECARD_TITLE + " TEXT NOT NULL," +
                        NOTECARD_ORDER + " INTEGER NOT NULL," +
                        SPEECH_ID + " INTEGER NOT NULL," +
                        "FOREIGN KEY("+ SPEECH_ID +") REFERENCES " + SPEECH_TABLE_NAME + "("+ COLUMN_ID +") ON DELETE CASCADE" + 
                ");";
            
        db.execSQL(createStatement);
    }
    
    private void createNoteTable(SQLiteDatabase db) {
        final String createStatement =
                "CREATE TABLE " + NOTE_TABLE_NAME + " (" +
                        COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                        NOTE_TEXT + " TEXT NOT NULL," +
                        NOTE_ORDER + " NOTE_ORDER NOT NULL," +
                        NOTECARD_ID + " INTEGER NOT NULL," +
                        "FOREIGN KEY("+ NOTECARD_ID +") REFERENCES " + NOTECARD_TABLE_NAME + "("+ COLUMN_ID +") ON DELETE CASCADE" + 
                ");";
            
        db.execSQL(createStatement);
    }
    
    private void createSpeechRecording(SQLiteDatabase db) {
        final String createStatement =
                "CREATE TABLE " + SPEECH_RECORDING_TABLE_NAME + " (" +
                        COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                        SPEECH_RECORDING_TITLE + " TEXT NOT NULL," +
                        SPEECH_RECORDING_ORDER + " INTEGER NOT NULL," +
                        SPEECH_ID + " INTEGER NOT NULL," +
                        "FOREIGN KEY("+ SPEECH_ID +") REFERENCES " + SPEECH_TABLE_NAME + "("+ COLUMN_ID +") ON DELETE CASCADE" +  
                ");";
            
        db.execSQL(createStatement);
    }
    
}




Java Source Code List

com.ericharlow.DragNDrop.DragListener.java
com.ericharlow.DragNDrop.DragNDropAdapter.java
com.ericharlow.DragNDrop.DragNDropListView.java
com.ericharlow.DragNDrop.DropListener.java
com.ericharlow.DragNDrop.RemoveListener.java
edu.psu.rcy5017.speechwriter.DatabaseHelper.java
edu.psu.rcy5017.speechwriter.activity.EditTextActivity.java
edu.psu.rcy5017.speechwriter.activity.MainActivity.java
edu.psu.rcy5017.speechwriter.activity.NoteCardListActivity.java
edu.psu.rcy5017.speechwriter.activity.NoteListActivity.java
edu.psu.rcy5017.speechwriter.activity.OptionsActivity.java
edu.psu.rcy5017.speechwriter.activity.SpeechListActivity.java
edu.psu.rcy5017.speechwriter.activity.SpeechRecordingListActivity.java
edu.psu.rcy5017.speechwriter.activity.SplashScreenActivity.java
edu.psu.rcy5017.speechwriter.adapter.TabsPagerAdapter.java
edu.psu.rcy5017.speechwriter.constant.DefaultValues.java
edu.psu.rcy5017.speechwriter.constant.MiscConstants.java
edu.psu.rcy5017.speechwriter.constant.RequestCodes.java
edu.psu.rcy5017.speechwriter.controller.AudioCntl.java
edu.psu.rcy5017.speechwriter.controller.OptionsCntl.java
edu.psu.rcy5017.speechwriter.datasource.DataSource.java
edu.psu.rcy5017.speechwriter.datasource.NoteCardDataSource.java
edu.psu.rcy5017.speechwriter.datasource.NoteDataSource.java
edu.psu.rcy5017.speechwriter.datasource.SpeechDataSource.java
edu.psu.rcy5017.speechwriter.datasource.SpeechRecordingDataSource.java
edu.psu.rcy5017.speechwriter.fragment.NoteCardFragement.java
edu.psu.rcy5017.speechwriter.listener.ChangeFontSizeListener.java
edu.psu.rcy5017.speechwriter.listener.DragListenerImpl.java
edu.psu.rcy5017.speechwriter.listener.DropListenerImpl.java
edu.psu.rcy5017.speechwriter.listener.DropReorderListener.java
edu.psu.rcy5017.speechwriter.listener.RemoveListenerImpl.java
edu.psu.rcy5017.speechwriter.model.NoteCard.java
edu.psu.rcy5017.speechwriter.model.Note.java
edu.psu.rcy5017.speechwriter.model.SpeechRecording.java
edu.psu.rcy5017.speechwriter.model.Speech.java
edu.psu.rcy5017.speechwriter.task.ChangeNoteTextTask.java
edu.psu.rcy5017.speechwriter.task.CreateNoteCardTask.java
edu.psu.rcy5017.speechwriter.task.CreateNoteTask.java
edu.psu.rcy5017.speechwriter.task.CreateSpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.CreateSpeechTask.java
edu.psu.rcy5017.speechwriter.task.DeleteTask.java
edu.psu.rcy5017.speechwriter.task.GetAllTask.java
edu.psu.rcy5017.speechwriter.task.NoteCardTask.java
edu.psu.rcy5017.speechwriter.task.NoteTask.java
edu.psu.rcy5017.speechwriter.task.RenameNoteCardTask.java
edu.psu.rcy5017.speechwriter.task.RenameSpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.RenameSpeechTask.java
edu.psu.rcy5017.speechwriter.task.SpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.SpeechTask.java
edu.psu.rcy5017.speechwriter.task.UpdateOrderTask.java