public abstract class KittyDatabase<M extends KittyModel>
extends java.lang.Object
KITTY_DATABASE
annotation.
Also it can be annotated with KITTY_DATABASE_HELPER
annotation.Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
AME_NO_KDB_ANNO_PRESENT |
protected static java.lang.String |
AME_NULLED |
protected android.content.Context |
context |
protected KittyDatabaseConfiguration |
databaseConfiguration |
protected KittyDatabaseHelper |
databaseHelper |
protected java.lang.String |
databasePassword |
protected static java.lang.String |
DBB_INFO |
protected static java.lang.String |
DBH_NOT_ACQUIRE_YET |
protected KittyDBHelperConfiguration |
helperConfiguration |
protected static java.lang.String |
LI_DB_CONFIGURATION_ACQUIRED |
protected static java.lang.String |
LI_DB_HELPER_ACQUIRED |
protected static java.lang.String |
LI_DB_HELPER_ACQUIRING |
protected static java.lang.String |
LI_DB_MMFACTORY_INITIATED |
protected static java.lang.String |
LI_DB_PWD_SET |
protected static java.lang.String |
LI_HC_INFO |
protected static java.lang.String |
LI_MM_INSTANCE_STORAGE_GENERATED |
protected static java.lang.String |
LI_MM_INSTANCE_STORAGE_GENERATING |
protected static java.lang.String |
LI_SETTING_AUTOGENERATED_REGISTRY |
protected static java.lang.String |
LI_STATIC_MM_SET |
protected static java.lang.String |
LI_STATIC_REGISTRY_SET |
protected boolean |
logOn |
protected java.lang.String |
logTag |
protected KittyMMEntryFactory |
modelMapperEntryFactory |
protected java.util.Map<java.lang.Class<M>,KittyMMEntry> |
modelMapperInstanceStorage
Map of Model classes as keys and ready to use pairs of instances of Models and Mappers
May be generated automatically or set manually for faster initialization by implementing
getStaticRegistry() |
protected static java.lang.String |
PR_MESSAGE |
protected java.util.Map<java.lang.Class<M>,java.lang.Class<KittyMapper>> |
registry
Map of Models\Mappers classes to be used with this instance of KittyDatabase
May be generated automatically or set manually for faster initialization by implementing
getStaticModelMapperInstancesStorage() |
protected static java.lang.String |
SN_NOT_ACQUIRE_YET |
protected static java.lang.String |
SV_NOT_ACQUIRE_YET |
Modifier | Constructor and Description |
---|---|
protected |
KittyDatabase(android.content.Context ctx)
KittyORM main database class that represents bootstrap and holder for all related with database
components.
|
protected |
KittyDatabase(android.content.Context ctx,
java.lang.String databasePassword)
KittyORM main database class that represents bootstrap and holder for all related with database
components.
|
Modifier and Type | Method and Description |
---|---|
KittySQLiteDumpScript |
afterCreateScript()
Override this method if you want to run custom script SQLite sequence after schema creation
This method has higher priority than script that may be returned from any stored script |
KittySQLiteDumpScript |
afterMigrateScript()
Override this method of you want to run custom script sequence after schema migration
This method has higher priority than script that may be returned from any stored script |
boolean |
deleteDatabase()
Deletes current database, make sure that all connections would be closed
|
boolean |
deleteDatabase(java.lang.String schemaName)
Deletes requested database, make sure that all connections to this database would be closed
|
protected <M extends KittyModel> |
generateMMInstanceStorageFromRegistry(java.util.Map<java.lang.Class<M>,java.lang.Class<KittyMapper>> registry,
KittyMMEntryFactory entryFactory,
KittyDatabaseConfiguration databaseConfiguration) |
protected KittyConfigurator |
getConfigurator(android.content.Context ctx,
java.util.Map<java.lang.Class<M>,java.lang.Class<KittyMapper>> registry)
Returns KittyConfigurator to be used with this database
By default would be created
KittyConfiguratorADC , however
you can implement any configuration storage you want. |
protected KittyDBHelperConfiguration |
getDBHelperConfiguration() |
<D extends KittyMapper,M extends KittyModel> |
getMapper(java.lang.Class<M> recordClass) |
<M extends KittyModel> |
getModel(java.lang.Class<M> recordClass) |
protected KittyMMEntryFactory |
getModelMapperFactory(KittyDatabaseConfiguration configuration,
java.lang.String dbPwd) |
protected java.util.LinkedList<KittySQLiteQuery> |
getPreGeneratedCreateStatements(KittyDatabaseConfiguration dbConf)
By implementing this vias static collection of queries you would speed up KittyORM initialization.
|
protected java.util.LinkedList<KittySQLiteQuery> |
getPreGeneratedDropStatements(KittyDatabaseConfiguration dbConf)
By implementing this via static collection of queries you would speed up KittyORM initialization.
|
protected java.util.Map<java.lang.Class<M>,KittyMMEntry> |
getStaticModelMapperInstancesStorage()
Returns static map where keys are model's classes and entries are pairs of models and mappers
instances.
|
protected java.util.Map<java.lang.Class<M>,java.lang.Class<KittyMapper>> |
getStaticRegistry()
Method used for getting static registry of mappers.
|
protected java.lang.String |
log(KittyLog.LOG_LEVEL level,
java.lang.String message,
boolean useDefaultFormatter,
java.lang.Throwable tr)
Simple method for logging in this db class if log is on.
|
protected KittyDatabaseHelper |
newDatabaseHelper() |
void |
printPregeneratedCreateSchemaToLog(java.lang.String logTag) |
void |
printPregeneratedDropSchemaToLog(java.lang.String logTag) |
void |
printRegistryToLog(KittyLog.LOG_LEVEL logLevel)
Prints registry to serial if logOn = true
|
protected java.util.Map<java.lang.Class<M extends KittyModel>,java.lang.Class<KittyMapper>> registry
getStaticModelMapperInstancesStorage()
protected java.util.Map<java.lang.Class<M extends KittyModel>,KittyMMEntry> modelMapperInstanceStorage
getStaticRegistry()
protected static final java.lang.String AME_NULLED
protected static final java.lang.String AME_NO_KDB_ANNO_PRESENT
protected static java.lang.String LI_DB_PWD_SET
protected static java.lang.String LI_STATIC_REGISTRY_SET
protected static java.lang.String LI_STATIC_MM_SET
protected static java.lang.String LI_DB_CONFIGURATION_ACQUIRED
protected static java.lang.String LI_DB_HELPER_ACQUIRING
protected static java.lang.String LI_DB_HELPER_ACQUIRED
protected static java.lang.String LI_DB_MMFACTORY_INITIATED
protected static java.lang.String LI_SETTING_AUTOGENERATED_REGISTRY
protected static java.lang.String LI_MM_INSTANCE_STORAGE_GENERATING
protected static java.lang.String LI_MM_INSTANCE_STORAGE_GENERATED
protected static java.lang.String LI_HC_INFO
protected final KittyDatabaseConfiguration databaseConfiguration
protected final KittyDBHelperConfiguration helperConfiguration
protected KittyDatabaseHelper databaseHelper
protected final android.content.Context context
protected final KittyMMEntryFactory modelMapperEntryFactory
protected final java.lang.String databasePassword
protected final boolean logOn
protected final java.lang.String logTag
protected static java.lang.String PR_MESSAGE
protected static java.lang.String SN_NOT_ACQUIRE_YET
protected static java.lang.String SV_NOT_ACQUIRE_YET
protected static java.lang.String DBH_NOT_ACQUIRE_YET
protected static java.lang.String DBB_INFO
protected KittyDatabase(android.content.Context ctx)
KittyDatabase(Context, String)
for more info.ctx
- protected KittyDatabase(android.content.Context ctx, java.lang.String databasePassword)
KittyDatabaseHelper
, so, you have to implement it yourself.
getStaticRegistry()
. his method is not implemented here, you have to implement it
yourself. It just sets registry storage to null, so it can be filled via reflection at
database configuration routine.
But it is expensive operation and after designing your database it would be good point to optimise it and create
registry storage manually via overriding getStaticRegistry()
.
getStaticModelMapperInstancesStorage()
. This method is not implemented here, you have to implement it
yourself. It just sets Model-Mapper storage to null, so it can be filled via reflection with
generateMMInstanceStorageFromRegistry(Map, KittyMMEntryFactory, KittyDatabaseConfiguration)
.
But it is expensive operation and after designing your database it would be good point to optimise it and create
model mapper instance storage manually via overriding getStaticModelMapperInstancesStorage()
.
KittyDatabaseConfiguration
from getConfigurator(Context, Map)
. If
you want to use your own configurator than you should override getConfigurator(Context, Map)
in your implementation to use your own implementation of KittyConfigurator
.
getDBHelperConfiguration()
. You can also override it
for your personal purposes if necessary.
getStaticRegistry()
returned null before.
generateMMInstanceStorageFromRegistry(Map, KittyMMEntryFactory, KittyDatabaseConfiguration)
.
Would be called only if getStaticModelMapperInstancesStorage()
returned null before;
newDatabaseHelper()
. If you want to use your own
implementation of KittyDatabaseHelper
, for example, for implementing database encryption,
override newDatabaseHelper()
.
getPreGeneratedCreateStatements(KittyDatabaseConfiguration)
.
If you want some performance optimisation, you can override it to use static collection of create schema statements sequence.
getPreGeneratedDropStatements(KittyDatabaseConfiguration)
.
If you want some performance optimisation, you can override it to use static collection of drop schema statements sequence.ctx
- Anroid context, not null.databasePassword
- database password, note that you have to use your own implementation of
KittyDatabaseHelper
that supports database encryption as well as
you have to override newDatabaseHelper()
to pass it into
KittyDatabase implementation.protected KittyConfigurator getConfigurator(android.content.Context ctx, java.util.Map<java.lang.Class<M>,java.lang.Class<KittyMapper>> registry)
KittyConfiguratorADC
, however
you can implement any configuration storage you want.
ctx
- application contextregistry
- application registryprotected KittyDatabaseHelper newDatabaseHelper()
protected java.util.Map<java.lang.Class<M>,KittyMMEntry> getStaticModelMapperInstancesStorage()
protected java.util.Map<java.lang.Class<M>,java.lang.Class<KittyMapper>> getStaticRegistry()
protected KittyDBHelperConfiguration getDBHelperConfiguration()
protected KittyMMEntryFactory getModelMapperFactory(KittyDatabaseConfiguration configuration, java.lang.String dbPwd)
public final <M extends KittyModel> M getModel(java.lang.Class<M> recordClass)
public final <D extends KittyMapper,M extends KittyModel> D getMapper(java.lang.Class<M> recordClass)
protected <M extends KittyModel> java.util.Map<java.lang.Class<M>,KittyMMEntry> generateMMInstanceStorageFromRegistry(java.util.Map<java.lang.Class<M>,java.lang.Class<KittyMapper>> registry, KittyMMEntryFactory entryFactory, KittyDatabaseConfiguration databaseConfiguration)
protected java.util.LinkedList<KittySQLiteQuery> getPreGeneratedCreateStatements(KittyDatabaseConfiguration dbConf)
dbConf
- public KittySQLiteDumpScript afterCreateScript()
public KittySQLiteDumpScript afterMigrateScript()
public void printPregeneratedCreateSchemaToLog(java.lang.String logTag)
public void printPregeneratedDropSchemaToLog(java.lang.String logTag)
protected java.util.LinkedList<KittySQLiteQuery> getPreGeneratedDropStatements(KittyDatabaseConfiguration dbConf)
dbConf
- public final void printRegistryToLog(KittyLog.LOG_LEVEL logLevel)
logLevel
- public final boolean deleteDatabase()
public final boolean deleteDatabase(java.lang.String schemaName)
schemaName
- protected java.lang.String log(KittyLog.LOG_LEVEL level, java.lang.String message, boolean useDefaultFormatter, java.lang.Throwable tr)
Object.getClass()
canonical name
KittyDBHelperConfiguration.schemaName
KittyDBHelperConfiguration.schemaVersion
KittyDatabaseHelper
used with this bootstrap class.
KittyDatabaseHelper
, so I would rewrite it without CP (copy-paste, lol) in future.level
- message
- useDefaultFormatter
- tr
- any throwable, may be null