public class KittyDatabaseHelper
extends android.database.sqlite.SQLiteOpenHelper
implements java.lang.Cloneable
KITTY_DATABASE_HELPER
annotation.
KITTY_DATABASE_HELPER
annotation should be applied only to implementations of KittyDatabase
. Modifier and Type | Field and Description |
---|---|
protected KittySQLiteDumpScript |
afterCreateScript |
protected KittySQLiteDumpScript |
afterMigrateScript |
protected android.content.Context |
context |
protected java.util.LinkedList<KittySQLiteQuery> |
createSchemaAutogeneratedScript |
protected KittyDatabaseConfiguration |
databaseConfiguration |
protected static java.lang.String |
DC_CE_NO_CREATE_SEQUENCE |
protected static java.lang.String |
DC_CE_NO_DROP_SEQUENCE |
protected java.util.LinkedList<KittySQLiteQuery> |
dropSchemaAutogeneratedScript |
protected KittyDBHelperConfiguration |
helperConfiguration |
(package private) static int |
JELLY_BEAN_ANDROID_VERSION_CODE |
protected static java.lang.String |
PRAGMA_ON |
protected static java.lang.String |
QE_RIT |
Constructor and Description |
---|
KittyDatabaseHelper(android.content.Context context,
KittyDBHelperConfiguration helperCfg,
KittyDatabaseConfiguration conf)
Create a KittyORM helper object to create, open, and/or manage a database.
|
KittyDatabaseHelper(android.content.Context context,
KittyDBHelperConfiguration helperCfg,
KittyDatabaseConfiguration conf,
android.database.sqlite.SQLiteDatabase.CursorFactory cursorFactory)
Create a helper object to create, open, and/or manage a database.
|
KittyDatabaseHelper(android.content.Context context,
KittyDBHelperConfiguration helperCfg,
KittyDatabaseConfiguration conf,
android.database.sqlite.SQLiteDatabase.CursorFactory cursorFactory,
java.util.LinkedList<KittySQLiteQuery> createSchemaAutogeneratedScript,
java.util.LinkedList<KittySQLiteQuery> dropSchemaAutogeneratedScript,
KittySQLiteDumpScript afterCreateScript,
KittySQLiteDumpScript afterMigrateScript)
Create a helper object to create, open, and/or manage a database.
|
Modifier and Type | Method and Description |
---|---|
protected java.util.LinkedList<KittySQLiteQuery> |
acquireBestCreateScriptSequence()
Returns best create script sequence available.
|
protected java.util.LinkedList<KittySQLiteQuery> |
acquireBestDropScriptSequence(int oldDatabaseVersion,
android.database.sqlite.SQLiteDatabase database)
Returns drop tables sequence following those priority:
1) Returning old drop script stored as file in database's assets directory using pattern '{0}-v-{1}-drop.sql' where {0} is schema name and {1} is schema version.. |
KittyDatabaseHelper |
clone() |
<T extends KittyDatabaseHelper> |
clone(java.lang.Class<T> recordClass) |
protected java.util.LinkedList<KittySQLiteQuery> |
generateDropTablesScript(java.lang.String schemaName,
android.database.sqlite.SQLiteDatabase database)
Returns drop script generated from list of tables acquired via
SelectTableNamesQuery . |
protected KittySQLiteDumpScript |
getAssetsScript(java.lang.String assetPath)
Creates and returns KittySQLiteDumpScript implementation designed to be used
with this databaseClass helper (from assets) |
KittyORMVersionMigrator |
getCustomMigratorImplementation(android.database.sqlite.SQLiteDatabase database,
int oldVersion,
int newVersion)
Method for getting custom
KittyORMVersionMigrator implementation for this
KittyORM database. |
protected KittyORMVersionMigrator |
getDropCreateVersionMigrator(int oldVersion,
int currentVersion,
android.database.sqlite.SQLiteDatabase database)
Returns default DropCreate migrator that contains only one Migration generated
from create and drop statements fetched from acquireBestDropScriptSequence(int, SQLiteDatabase)
and acquireBestCreateScriptSequence() if possible (if drop script for old schema version
doesn't exists than for getting drop dumped script would be used generateDropTablesScript(String, SQLiteDatabase) ) |
protected KittySQLiteDumpScript |
getFileScript(java.lang.String fileUriString,
boolean newDump)
Creates and returns KittySQLiteDumpScript implementation designed to be used
with this databaseClass helper (from fs) |
protected KittyORMVersionMigrator |
getFileVersionMigrator(int oldVersion,
int currentVersion)
Returns version migrator from version oldVersion to version currentVersion
|
protected java.lang.String |
getOldDropScriptLocation(KittyDBHelperConfiguration configuration,
int oldVersion)
Return path (assets or fs) for old drop script using pattern '{0}-v-{1}-drop.sql' where {0} is databaseClass name
and {1} is old version integer code with prefix as absolute path to assets schema directory If old script was stored as fs file and new as assets, would be returned path to assets |
android.database.sqlite.SQLiteDatabase |
getReadableDatabase(java.lang.String pwd)
Returns readable databaseClass object created and\or getWritableDatabase with r access and with use of
databaseClass encryption implementation |
protected java.util.LinkedList<KittySQLiteQuery> |
getScriptSequenceFromFileDump(java.lang.String pathToFiledScript)
Returns SQLite script sequence from provided file path if possible or null.
|
protected KittyORMVersionMigrator |
getSimpleMigrator(int oldVersion,
int currentVersion,
android.database.sqlite.SQLiteDatabase database) |
android.database.sqlite.SQLiteDatabase |
getWritableDatabase(java.lang.String pwd)
Returns writable databaseClass object created and\or getWritableDatabase with w access and with use of
databaseClass encryption implementation |
protected java.lang.String |
log(KittyLog.LOG_LEVEL level,
java.lang.String pattern,
boolean useDefaultFormatter,
java.lang.Throwable tr)
Simple method for logging in this helper if log is on.
|
protected void |
logQuery(java.lang.String executor,
KittySQLiteQuery query) |
protected void |
migrate(android.database.sqlite.SQLiteDatabase database,
KittyORMVersionMigrator migrator,
int oldVersion,
int currentVersion)
Tries to migrate from old db version to current with usage of custom migrator
|
void |
onConfigure(android.database.sqlite.SQLiteDatabase database)
Called when the database connection is being configured.
|
void |
onCreate(android.database.sqlite.SQLiteDatabase database)
Called when the database is created for the first time.
|
void |
onOpen(android.database.sqlite.SQLiteDatabase database)
Called when the database has been opened.
|
void |
onUpgrade(android.database.sqlite.SQLiteDatabase database,
int oldVersion,
int newVersion)
Called when the database needs to be upgraded.
|
protected void |
runScriptSequenceInTransaction(java.util.LinkedList<KittySQLiteQuery> scriptSequence,
android.database.sqlite.SQLiteDatabase database)
Tries to start transaction and end it.
|
void |
setAfterCreateScript(KittySQLiteDumpScript afterCreateScript)
Sets after create schema script sequence as dump script.
|
void |
setAfterMigrateScript(KittySQLiteDumpScript afterMigrateScript)
Sets after migrate schema script sequence as dump script.
|
void |
setCreateSchemaAutogeneratedScript(java.util.LinkedList<KittySQLiteQuery> createSchemaAutogeneratedScript)
Sets CREATE schema script sequence wrapped into instances of
KittySQLiteQuery to be used
in onCreate(SQLiteDatabase) and onUpgrade(SQLiteDatabase, int, int) . |
void |
setDropSchemaAutogeneratedScript(java.util.LinkedList<KittySQLiteQuery> dropSchemaAutogeneratedScript)
Sets DROP schema script sequence wrapped into instances of
KittySQLiteQuery to be used
in onUpgrade(SQLiteDatabase, int, int) . |
protected void |
setPragmaKeysAPI15AndLower(android.database.sqlite.SQLiteDatabase db,
boolean pragmaKeys)
Sets pragma key for Android API 15 and lower
If API higher than 15 than nothing happens
|
protected static java.lang.String DC_CE_NO_DROP_SEQUENCE
protected static java.lang.String DC_CE_NO_CREATE_SEQUENCE
static int JELLY_BEAN_ANDROID_VERSION_CODE
protected static final java.lang.String PRAGMA_ON
protected final KittyDBHelperConfiguration helperConfiguration
protected final KittyDatabaseConfiguration databaseConfiguration
protected final android.content.Context context
protected java.util.LinkedList<KittySQLiteQuery> createSchemaAutogeneratedScript
protected java.util.LinkedList<KittySQLiteQuery> dropSchemaAutogeneratedScript
protected KittySQLiteDumpScript afterCreateScript
protected KittySQLiteDumpScript afterMigrateScript
protected static final java.lang.String QE_RIT
public KittyDatabaseHelper(android.content.Context context, KittyDBHelperConfiguration helperCfg, KittyDatabaseConfiguration conf)
getWritableDatabase(java.lang.String)
or
getReadableDatabase(java.lang.String)
is called.
KITTY_DATABASE_HELPER
annotation.
KITTY_DATABASE_HELPER
annotation should be applied only to implementations of KittyDatabase
. context
- Android context.helperCfg
- KittyORM helper configuration instance.public KittyDatabaseHelper(android.content.Context context, KittyDBHelperConfiguration helperCfg, KittyDatabaseConfiguration conf, android.database.sqlite.SQLiteDatabase.CursorFactory cursorFactory)
getWritableDatabase(java.lang.String)
or
getReadableDatabase(java.lang.String)
is called.
KITTY_DATABASE_HELPER
annotation.
KITTY_DATABASE_HELPER
annotation should be applied only to implementations of KittyDatabase
. context
- Android context.helperCfg
- KittyORM helper configuration instance.cursorFactory
- cursor factory to use instead default one.public KittyDatabaseHelper(android.content.Context context, KittyDBHelperConfiguration helperCfg, KittyDatabaseConfiguration conf, android.database.sqlite.SQLiteDatabase.CursorFactory cursorFactory, java.util.LinkedList<KittySQLiteQuery> createSchemaAutogeneratedScript, java.util.LinkedList<KittySQLiteQuery> dropSchemaAutogeneratedScript, KittySQLiteDumpScript afterCreateScript, KittySQLiteDumpScript afterMigrateScript)
getWritableDatabase(java.lang.String)
or
getReadableDatabase(java.lang.String)
is called.context
- Android context.helperCfg
- KittyORM helper configuration instance.cursorFactory
- cursor factory to use instead default one.createSchemaAutogeneratedScript
- predefined create script sequence for this database.
See setCreateSchemaAutogeneratedScript(LinkedList)
for more details.dropSchemaAutogeneratedScript
- predefined drop script sequence for this database.
See setDropSchemaAutogeneratedScript(LinkedList)
for more details.public void setCreateSchemaAutogeneratedScript(java.util.LinkedList<KittySQLiteQuery> createSchemaAutogeneratedScript)
KittySQLiteQuery
to be used
in onCreate(SQLiteDatabase)
and onUpgrade(SQLiteDatabase, int, int)
.
onCreate(SQLiteDatabase)
if getFileScript(String, boolean)
returned null (buy default this method returns LinkedList of KittySQLiteQuery
fetched from
dump file)
onUpgrade(SQLiteDatabase, int, int)
if getFileVersionMigrator(int, int)
returned
null or helper forced by helper configuration to use drop and created migratorcreateSchemaAutogeneratedScript
- public void setAfterCreateScript(KittySQLiteDumpScript afterCreateScript)
afterCreateScript
- public void setAfterMigrateScript(KittySQLiteDumpScript afterMigrateScript)
afterMigrateScript
- public void setDropSchemaAutogeneratedScript(java.util.LinkedList<KittySQLiteQuery> dropSchemaAutogeneratedScript)
KittySQLiteQuery
to be used
in onUpgrade(SQLiteDatabase, int, int)
.
onUpgrade(SQLiteDatabase, int, int)
if getFileVersionMigrator(int, int)
returned
null or helper forced by helper configuration to use drop and created migrator
setCreateSchemaAutogeneratedScript(LinkedList)
)
should be set.dropSchemaAutogeneratedScript
- public android.database.sqlite.SQLiteDatabase getWritableDatabase(java.lang.String pwd)
pwd
- databaseClass passwordKittyRuntimeException
- if call from KittyDatabaseHelper
(not implemented here)public android.database.sqlite.SQLiteDatabase getReadableDatabase(java.lang.String pwd)
pwd
- databaseClass passwordKittyRuntimeException
- if call from KittyDatabaseHelper
(not implemented here)public void onOpen(android.database.sqlite.SQLiteDatabase database)
onOpen
in class android.database.sqlite.SQLiteOpenHelper
database
- public void onConfigure(android.database.sqlite.SQLiteDatabase database)
setPragmaKeysAPI16(SQLiteDatabase, boolean)
onConfigure
in class android.database.sqlite.SQLiteOpenHelper
database
- database instance.public void onCreate(android.database.sqlite.SQLiteDatabase database)
acquireBestCreateScriptSequence()
, if it would
be null than exception (KittyRuntimeException
) would be thrown.
runScriptSequenceInTransaction(LinkedList, SQLiteDatabase)
,
if it failed than exception (KittyRuntimeException
) would be thrown.onCreate
in class android.database.sqlite.SQLiteOpenHelper
database
- The database.public void onUpgrade(android.database.sqlite.SQLiteDatabase database, int oldVersion, int newVersion)
KITTY_DATABASE_HELPER
starts upgrading routine. If something failed than KittyRuntimeException
would be thrown.
KittyDBHelperConfiguration.onUpgradeBehavior
it would
try to get simple DropCreate migrator with getDropCreateVersionMigrator(int, int, SQLiteDatabase)
or file dump migrator with getFileVersionMigrator(int, int)
or user predefined migrator
with implemented by developer getCustomMigratorImplementation(SQLiteDatabase, int, int)
.
migrate(SQLiteDatabase, KittyORMVersionMigrator, int, int)
method. If something failed than KittyRuntimeException
would be thrown.onUpgrade
in class android.database.sqlite.SQLiteOpenHelper
database
- The database.oldVersion
- The old database version.newVersion
- The new database version.public KittyORMVersionMigrator getCustomMigratorImplementation(android.database.sqlite.SQLiteDatabase database, int oldVersion, int newVersion)
KittyORMVersionMigrator
implementation for this
KittyORM database. Not implemented in this helper implementation and usage of this method
would cause KittyRuntimeException
be thrown. To use this method you should manually
overload this method in child implementation.database
- The database.oldVersion
- The old database version.newVersion
- The new database version.protected void migrate(android.database.sqlite.SQLiteDatabase database, KittyORMVersionMigrator migrator, int oldVersion, int currentVersion)
database
- databaseClass objectmigrator
- to useoldVersion
- old version of databaseClasscurrentVersion
- current version of databaseClassKittyRuntimeException
- if migration sequence not applicable for input db and schema versionsprotected KittyORMVersionMigrator getFileVersionMigrator(int oldVersion, int currentVersion)
oldVersion
- old databaseClass versioncurrentVersion
- current databaseClass versionprotected KittyORMVersionMigrator getSimpleMigrator(int oldVersion, int currentVersion, android.database.sqlite.SQLiteDatabase database)
protected KittyORMVersionMigrator getDropCreateVersionMigrator(int oldVersion, int currentVersion, android.database.sqlite.SQLiteDatabase database)
acquireBestDropScriptSequence(int, SQLiteDatabase)
acquireBestCreateScriptSequence()
if possible (if drop script for old schema version
generateDropTablesScript(String, SQLiteDatabase)
)oldVersion
- old databaseClass versioncurrentVersion
- current databaseClass versionprotected java.util.LinkedList<KittySQLiteQuery> acquireBestCreateScriptSequence()
protected java.util.LinkedList<KittySQLiteQuery> acquireBestDropScriptSequence(int oldDatabaseVersion, android.database.sqlite.SQLiteDatabase database)
generateDropTablesScript(String, SQLiteDatabase)
.
If not possible than step 4.
protected java.util.LinkedList<KittySQLiteQuery> generateDropTablesScript(java.lang.String schemaName, android.database.sqlite.SQLiteDatabase database)
SelectTableNamesQuery
.
database
- protected void runScriptSequenceInTransaction(java.util.LinkedList<KittySQLiteQuery> scriptSequence, android.database.sqlite.SQLiteDatabase database)
scriptSequence
- database
- protected java.lang.String getOldDropScriptLocation(KittyDBHelperConfiguration configuration, int oldVersion)
configuration
- helper configurationoldVersion
- old version integer codeprotected java.util.LinkedList<KittySQLiteQuery> getScriptSequenceFromFileDump(java.lang.String pathToFiledScript)
pathToFiledScript
- protected KittySQLiteDumpScript getAssetsScript(java.lang.String assetPath)
assetPath
- protected KittySQLiteDumpScript getFileScript(java.lang.String fileUriString, boolean newDump)
fileUriString
- fileUriString object that contains path to readable fileUriString with dumped scriptnewDump
- flag that shows if this dump fileUriString is new and can be empty\not existingprotected java.lang.String log(KittyLog.LOG_LEVEL level, java.lang.String pattern, boolean useDefaultFormatter, java.lang.Throwable tr)
Object.getClass()
canonical name
KittyDBHelperConfiguration.schemaName
KittyDBHelperConfiguration.schemaVersion
level
- pattern
- useDefaultFormatter
- tr
- any throwable, may be nullprotected final void setPragmaKeysAPI15AndLower(android.database.sqlite.SQLiteDatabase db, boolean pragmaKeys)
db
- databaseClass objectpragmaKeys
- pragma on flagprotected final void logQuery(java.lang.String executor, KittySQLiteQuery query)
public final <T extends KittyDatabaseHelper> T clone(java.lang.Class<T> recordClass)
public KittyDatabaseHelper clone()
clone
in class java.lang.Object