org.hermit.android.provider
Class DatabaseHelper

java.lang.Object
  extended by SQLiteOpenHelper
      extended by org.hermit.android.provider.DatabaseHelper

public class DatabaseHelper
extends SQLiteOpenHelper

This class helps open, create, and upgrade the database file.

Applications may use this class as is, or override it, for example to provide a database upgrade handler. If you don't wish to override it, nothing need be done. If you wish to subclass it, then create your subclass and override TableProvider.getHelper() to return it.


Constructor Summary
DatabaseHelper(Context context, DbSchema schema)
          Creater a helper instance.
 
Method Summary
protected  DbSchema getSchema()
          Get the database schema.
 void onCreate(SQLiteDatabase db)
          Called when the database is created for the first time.
 void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
          Called when the database needs to be upgraded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseHelper

public DatabaseHelper(Context context,
                      DbSchema schema)
Creater a helper instance.

Parameters:
context - Application context.
schema - Schema for this database.
Method Detail

onCreate

public void onCreate(SQLiteDatabase db)
Called when the database is created for the first time. This is where the creation of tables and the initial population of the tables should happen.

The default implementation creates all the fields specified in all of the table schemas. Subclasses may override this, for example to add special fields.

Parameters:
db - The new database.

onUpgrade

public void onUpgrade(SQLiteDatabase db,
                      int oldVersion,
                      int newVersion)
Called when the database needs to be upgraded. The implementation should use this method to drop tables, add tables, or do anything else it needs to upgrade to the new schema version.

The default implementation simply deletes all tables and calls #onOpen(SQLiteDatabase). Subclasses may override this method to do a more intelligent upgrade.

If you add new columns you can use ALTER TABLE to insert them into a live table. If you rename or remove columns you can use ALTER TABLE to rename the old table, then create the new table and then populate the new table with the contents of the old table.

Parameters:
db - The new database.
oldVersion - The old database version.
newVersion - The new database version.

getSchema

protected DbSchema getSchema()
Get the database schema.

Returns:
The schema for this database.