Android Open Source - android-location-notes Note Database Access






From Project

Back to project page android-location-notes.

License

The source code is released under:

Apache License

If you think the Android project android-location-notes 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 com.nearsoft.examenboom.database;
/*w w  w . j a  v a2  s  .com*/
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;


public final class NoteDatabaseAccess {

    private static SQLiteDatabase databaseAccess;
    private static Context context;

    public static SQLiteDatabase getDatabaseConnection(Context context) {
        NoteDatabaseAccess.context = context;

        if(databaseAccess == null || !databaseAccess.isOpen()) {
            try{
                openDatabaseConnection();
            } catch(SQLiteException e) {
                createDB();
                openDatabaseConnection();
            }
        }
        return databaseAccess;
    }

    private static void openDatabaseConnection() {
        databaseAccess = SQLiteDatabase.openDatabase(context.getDatabasePath(NotesSQLite.DB_NAME).toString(), null, SQLiteDatabase.OPEN_READWRITE);
    }

    public static void closeDatabaseConnection() {
        if(databaseAccess != null && databaseAccess.isOpen())
            databaseAccess.close();
    }

    private static void createDB(){
        NotesSQLite createDBObject = new NotesSQLite(context, NotesSQLite.DB_NAME, null, 1);
        SQLiteDatabase db = createDBObject.getWritableDatabase();
        db.close();
    }
}




Java Source Code List

com.nearsoft.examenboom.ApplicationTest.java
com.nearsoft.examenboom.DrawerAdapter.java
com.nearsoft.examenboom.ExamenApplication.java
com.nearsoft.examenboom.MainActivity.java
com.nearsoft.examenboom.NewNoteActivity.java
com.nearsoft.examenboom.NoteMapFragment.java
com.nearsoft.examenboom.NotesAdapter.java
com.nearsoft.examenboom.NotesFragment.java
com.nearsoft.examenboom.NotesMapFragment.java
com.nearsoft.examenboom.ViewNoteActivity.java
com.nearsoft.examenboom.common.Note.java
com.nearsoft.examenboom.database.NoteDatabaseAccess.java
com.nearsoft.examenboom.database.NotesSQLite.java
com.nearsoft.examenboom.database.repository.NoteRepositoryImpl.java
com.nearsoft.examenboom.database.repository.NoteRepository.java