All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.easimart.EasimartSQLiteOpenHelper Maven / Gradle / Ivy

package co.easimart;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import bolts.Task;

/** package */ abstract class EasimartSQLiteOpenHelper {

  private final SQLiteOpenHelper helper;

  public EasimartSQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
                                  int version) {
    helper = new SQLiteOpenHelper(context, name, factory, version) {
      @Override
      public void onOpen(SQLiteDatabase db) {
        super.onOpen(db);
        EasimartSQLiteOpenHelper.this.onOpen(db);
      }

      @Override
      public void onCreate(SQLiteDatabase db) {
        EasimartSQLiteOpenHelper.this.onCreate(db);
      }

      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        EasimartSQLiteOpenHelper.this.onUpgrade(db, oldVersion, newVersion);
      }
    };
  }

  public Task getReadableDatabaseAsync() {
    return getDatabaseAsync(false);
  }

  public Task getWritableDatabaseAsync() {
    return getDatabaseAsync(true);
  }

  private Task getDatabaseAsync(final boolean writable) {
    return EasimartSQLiteDatabase.openDatabaseAsync(
            helper, !writable ? SQLiteDatabase.OPEN_READONLY : SQLiteDatabase.OPEN_READWRITE);
  }

  public void onOpen(SQLiteDatabase db) {
    // do nothing
  }

  public abstract void onCreate(SQLiteDatabase db);
  public abstract void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy