Android Open Source - Abstract-Model My Database Open Helper






From Project

Back to project page Abstract-Model.

License

The source code is released under:

Apache License

If you think the Android project Abstract-Model 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.logician.abstractModel.examples;
/*from   w w w .  j a va  2s.  c  om*/
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public final class MyDatabaseOpenHelper extends SQLiteOpenHelper {

  private static final String NAME = "mydatabase";
  private static final int VERSION = 3;
  
  // To avoid concurrency issues, you should use the singleton model.
  // See this blog post about the issue:
  // http://www.androiddesignpatterns.com/2012/05/correctly-managing-your-sqlite-database.html
  private static MyDatabaseOpenHelper singleton = null;
  
  private MyDatabaseOpenHelper(Context context) {
    super(context, NAME, null, VERSION);
    
  }

  public static MyDatabaseOpenHelper getInstance(Context context){
    if(singleton == null)
      /**
       * It is best to use the Application context so
       * you don't accidentally leak the context
       * of an Activity or Service. 
       */
      singleton = new MyDatabaseOpenHelper(context.getApplicationContext());
    
    return singleton;
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {    
    db.execSQL(new User().getTableSQL());

  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    

  }

}




Java Source Code List

com.logician.abstractModel.AsyncModelFactory.java
com.logician.abstractModel.BinarySerializable.java
com.logician.abstractModel.Column.java
com.logician.abstractModel.JSONSerializable.java
com.logician.abstractModel.ModelListAdapter.java
com.logician.abstractModel.Model.java
com.logician.abstractModel.Util.java
com.logician.abstractModel.examples.MyDatabaseOpenHelper.java
com.logician.abstractModel.examples.User.java
com.logician.abstractModel.examples.UsersActivity.java