com.j256.ormlite.android.apptools
Class OrmLiteSqliteOpenHelper

java.lang.Object
  extended by android.database.sqlite.SQLiteOpenHelper
      extended by com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper

public abstract class OrmLiteSqliteOpenHelper
extends android.database.sqlite.SQLiteOpenHelper

SQLite database open helper which can be extended by your application to help manage when the application needs to create or upgrade its database.

Author:
kevingalligan, graywatson

Field Summary
protected  AndroidConnectionSource connectionSource
           
protected static com.j256.ormlite.logger.Logger logger
           
 
Constructor Summary
OrmLiteSqliteOpenHelper(android.content.Context context, String databaseName, android.database.sqlite.SQLiteDatabase.CursorFactory factory, int databaseVersion)
           
OrmLiteSqliteOpenHelper(android.content.Context context, String databaseName, android.database.sqlite.SQLiteDatabase.CursorFactory factory, int databaseVersion, File configFile)
          Same as the other constructor with the addition of a config-file.
OrmLiteSqliteOpenHelper(android.content.Context context, String databaseName, android.database.sqlite.SQLiteDatabase.CursorFactory factory, int databaseVersion, InputStream stream)
          Same as the other constructor with the addition of a input stream to the table config-file.
OrmLiteSqliteOpenHelper(android.content.Context context, String databaseName, android.database.sqlite.SQLiteDatabase.CursorFactory factory, int databaseVersion, int configFileId)
          Same as the other constructor with the addition of a file-id of the table config-file.
 
Method Summary
 void close()
          Close any open connections.
 com.j256.ormlite.support.ConnectionSource getConnectionSource()
          Get the connection source associated with the helper.
<D extends com.j256.ormlite.dao.Dao<T,?>,T>
D
getDao(Class<T> clazz)
          Get a DAO for our class.
<D extends com.j256.ormlite.dao.RuntimeExceptionDao<T,?>,T>
D
getRuntimeExceptionDao(Class<T> clazz)
          Get a RuntimeExceptionDao for our class.
 boolean isOpen()
          Return true if the helper is still open.
 void onCreate(android.database.sqlite.SQLiteDatabase db)
          Satisfies the SQLiteOpenHelper.onCreate(SQLiteDatabase) interface method.
abstract  void onCreate(android.database.sqlite.SQLiteDatabase database, com.j256.ormlite.support.ConnectionSource connectionSource)
          What to do when your database needs to be created.
abstract  void onUpgrade(android.database.sqlite.SQLiteDatabase database, com.j256.ormlite.support.ConnectionSource connectionSource, int oldVersion, int newVersion)
          What to do when your database needs to be updated.
 void onUpgrade(android.database.sqlite.SQLiteDatabase db, int oldVersion, int newVersion)
          Satisfies the SQLiteOpenHelper.onUpgrade(SQLiteDatabase, int, int) interface method.
 String toString()
           
 
Methods inherited from class android.database.sqlite.SQLiteOpenHelper
getReadableDatabase, getWritableDatabase, onOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected static com.j256.ormlite.logger.Logger logger

connectionSource

protected AndroidConnectionSource connectionSource
Constructor Detail

OrmLiteSqliteOpenHelper

public OrmLiteSqliteOpenHelper(android.content.Context context,
                               String databaseName,
                               android.database.sqlite.SQLiteDatabase.CursorFactory factory,
                               int databaseVersion)

OrmLiteSqliteOpenHelper

public OrmLiteSqliteOpenHelper(android.content.Context context,
                               String databaseName,
                               android.database.sqlite.SQLiteDatabase.CursorFactory factory,
                               int databaseVersion,
                               int configFileId)
Same as the other constructor with the addition of a file-id of the table config-file. See OrmLiteConfigUtil for details.

Parameters:
configFileId - file-id which probably should be a R.raw.ormlite_config.txt or some static value.

OrmLiteSqliteOpenHelper

public OrmLiteSqliteOpenHelper(android.content.Context context,
                               String databaseName,
                               android.database.sqlite.SQLiteDatabase.CursorFactory factory,
                               int databaseVersion,
                               File configFile)
Same as the other constructor with the addition of a config-file. See OrmLiteConfigUtil for details.

Parameters:
configFile - Configuration file to be loaded.

OrmLiteSqliteOpenHelper

public OrmLiteSqliteOpenHelper(android.content.Context context,
                               String databaseName,
                               android.database.sqlite.SQLiteDatabase.CursorFactory factory,
                               int databaseVersion,
                               InputStream stream)
Same as the other constructor with the addition of a input stream to the table config-file. See OrmLiteConfigUtil for details.

Parameters:
stream - Stream opened to the configuration file to be loaded.
Method Detail

onCreate

public abstract void onCreate(android.database.sqlite.SQLiteDatabase database,
                              com.j256.ormlite.support.ConnectionSource connectionSource)
What to do when your database needs to be created. Usually this entails creating the tables and loading any initial data.

NOTE: You should use the connectionSource argument that is passed into this method call or the one returned by getConnectionSource(). If you use your own, a recursive call or other unexpected results may result.

Parameters:
database - Database being created.
connectionSource - To use get connections to the database to be created.

onUpgrade

public abstract void onUpgrade(android.database.sqlite.SQLiteDatabase database,
                               com.j256.ormlite.support.ConnectionSource connectionSource,
                               int oldVersion,
                               int newVersion)
What to do when your database needs to be updated. This could mean careful migration of old data to new data. Maybe adding or deleting database columns, etc..

NOTE: You should use the connectionSource argument that is passed into this method call or the one returned by getConnectionSource(). If you use your own, a recursive call or other unexpected results may result.

Parameters:
database - Database being upgraded.
connectionSource - To use get connections to the database to be updated.
oldVersion - The version of the current database so we can know what to do to the database.
newVersion - The version that we are upgrading the database to.

getConnectionSource

public com.j256.ormlite.support.ConnectionSource getConnectionSource()
Get the connection source associated with the helper.


onCreate

public final void onCreate(android.database.sqlite.SQLiteDatabase db)
Satisfies the SQLiteOpenHelper.onCreate(SQLiteDatabase) interface method.

Specified by:
onCreate in class android.database.sqlite.SQLiteOpenHelper

onUpgrade

public final void onUpgrade(android.database.sqlite.SQLiteDatabase db,
                            int oldVersion,
                            int newVersion)
Satisfies the SQLiteOpenHelper.onUpgrade(SQLiteDatabase, int, int) interface method.

Specified by:
onUpgrade in class android.database.sqlite.SQLiteOpenHelper

close

public void close()
Close any open connections.

Overrides:
close in class android.database.sqlite.SQLiteOpenHelper

isOpen

public boolean isOpen()
Return true if the helper is still open. Once close() is called then this will return false.


getDao

public <D extends com.j256.ormlite.dao.Dao<T,?>,T> D getDao(Class<T> clazz)
                                               throws SQLException
Get a DAO for our class. This uses the DaoManager to cache the DAO for future gets.

NOTE: This routing does not return Dao because of casting issues if we are assigning it to a custom DAO. Grumble.

Throws:
SQLException

getRuntimeExceptionDao

public <D extends com.j256.ormlite.dao.RuntimeExceptionDao<T,?>,T> D getRuntimeExceptionDao(Class<T> clazz)
Get a RuntimeExceptionDao for our class. This uses the DaoManager to cache the DAO for future gets.

NOTE: This routing does not return RuntimeExceptionDao because of casting issues if we are assigning it to a custom DAO. Grumble.


toString

public String toString()
Overrides:
toString in class Object


This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.