public class KittyMapper
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Class and Description |
---|---|
static class |
KittyMapper.TRANSACTION_MODES
Transaction modes
|
Modifier and Type | Field and Description |
---|---|
protected KittyModel |
blankModelInstance
Blank model to be used with this mapper
|
protected java.util.HashMap<java.lang.String,KittyColumnConfiguration> |
columnConfigurations |
protected SQLiteConditionBuilder |
conditionBuilder
Condition builder
|
protected KittyModelCVFactory |
cursorToModelFactory
Cursor to model factory
|
protected android.database.sqlite.SQLiteDatabase |
database |
protected KittyDatabaseHelper |
databaseHelper |
protected java.lang.String |
databasePassword |
protected static java.lang.String |
DELETE_PL |
protected static java.lang.String |
DELETE_PL2 |
protected static java.lang.String |
INS_PL |
protected java.util.List<java.lang.String> |
insertPKExclusions |
protected static java.lang.String |
KE_DELETE_READ_ONLY |
protected static java.lang.String |
KE_INSERT_READ_ONLY |
protected static java.lang.String |
KE_SAVE_READ_ONLY |
protected static java.lang.String |
KE_UPDATE_READ_ONLY |
protected boolean |
logOn |
protected java.lang.String |
logTag |
static java.lang.String |
MODEL_LOG_PATTERN |
static java.lang.String |
MODEL_NOT_IMPL |
protected java.util.HashMap<KittyArrayKey,InsertValuesStatement> |
precompiledInserts |
protected static java.lang.String |
QE_COUNT |
protected static java.lang.String |
QE_DELETE_ALL |
protected static java.lang.String |
QE_DELETE_ALL_FAKE_QUERY |
protected static java.lang.String |
QE_DELETE_BY_WHERE |
protected static java.lang.String |
QE_DELETE_FAKE_QUERY |
protected static java.lang.String |
QE_EXECUTE_RAW_QUERY |
protected static java.lang.String |
QE_FIND_WITH_RAW_QUERY |
protected static java.lang.String |
QE_INSERT |
protected static java.lang.String |
QE_INSERT_FAKE_QUERY |
protected static java.lang.String |
QE_SUM |
protected static java.lang.String |
QE_UPDATE |
protected static java.lang.String |
QE_UPDATE_FAKE_QUERY |
static java.lang.String |
QUERY_LOG_PATTERN |
protected boolean |
returnNullNotEmptyCollection |
protected boolean |
rowidOn |
protected KittyTableConfiguration |
tableConfig
Table configuration
|
protected static java.lang.String |
UPDATE_PL |
Constructor and Description |
---|
KittyMapper(KittyTableConfiguration tableConfiguration,
M blankModelInstance,
java.lang.String databasePassword) |
Modifier and Type | Method and Description |
---|---|
KittyMapper |
clone()
Cloning implementation
|
<D extends KittyMapper> |
clone(java.lang.Class<D> recordClass)
Cloning implementation with generic
|
protected <M extends KittyModel> |
cloneModel(java.lang.Class<M> modelClass)
Clones blank model associated with this data mapper
|
void |
close()
Closes current db
|
protected SQLiteCondition |
conditionFromSQLString(java.lang.String condition,
java.lang.Object... params)
Generates instance of
SQLiteCondition from SQLite string and set of parameters. |
long |
countAll()
Counts all records in table.
|
long |
countAll(QueryParameters qParams)
Counts all records in table.
|
long |
countWhere(QueryParameters qParams,
java.lang.String condition,
java.lang.Object... conditionValues)
Counts record's amount of those records that suits provided condition.
|
long |
countWhere(SQLiteCondition where)
Counts record's amount of those records that suits provided condition.
|
long |
countWhere(SQLiteCondition where,
QueryParameters qParams)
Counts record's amount of those records that suits provided condition.
|
long |
countWhere(java.lang.String condition,
java.lang.Object... conditionValues)
Counts record's amount of those records that suits provided condition.
|
<M extends KittyModel> |
delete(KittyMapper.TRANSACTION_MODES txMode,
java.util.List<M> models)
Deletes all rows that represented by provided model's list.
|
<M extends KittyModel> |
delete(java.util.List<M> models)
Deletes all rows that represented by provided model's list.
|
<M extends KittyModel> |
delete(M model)
Deletes row that represented by provided model.
|
long |
deleteAll()
Deletes all rows in table associated with this data mapper.
|
long |
deleteByIPK(java.lang.Long id)
Deletes row in database's table depending on provided INTEGER PRIMARY KEY value.
|
long |
deleteByPK(KittyPrimaryKey pk)
Deletes row in database's table depending on values in provided PK.
|
long |
deleteByRowID(java.lang.Long rowid)
Deletes row in database's table depending on provided RowID.
|
<M extends KittyModel> |
deleteInTransaction(java.util.List<M> models)
Deletes all rows that represented by provided model's list.
|
long |
deleteWhere(SQLiteCondition condition)
Deletes all rows in table associated with this data mapper that suit provided condition.
|
long |
deleteWhere(java.lang.String condition,
java.lang.Object... conditionValues)
Deletes all rows in table associated with this data mapper that suit provided condition.
|
void |
executeRawQuery(java.lang.String querySQL,
java.lang.String... parameters)
Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
|
<M extends KittyModel> |
findAll()
Returns list of all models associated with records in backed database table.
|
<M extends KittyModel> |
findAll(QueryParameters qParams)
Returns list of all models associated with records in backed database table with usage of
passed qParams.
|
<M extends KittyModel> |
findByIPK(java.lang.Long ipk)
Returns model filled with data from database or null if no record with provided IPK found.
|
<M extends KittyModel> |
findByPK(KittyPrimaryKey primaryKey)
Returns model filled with data from database or null if no record with provided PK (
KittyPrimaryKey ) found. |
<M extends KittyModel> |
findByPKV(java.util.Map<java.lang.String,java.lang.String> pkv)
Returns model filled with data from database or null if no record with provided PK MAP (
KittyPrimaryKey.getPrimaryKeyColumnValues() ) found. |
<M extends KittyModel> |
findByRowID(java.lang.Long rowid)
Returns model filled with data from database or null if no record with provided rowid found.
|
<M extends KittyModel> |
findFirst()
Returns first record in KittyModel wrapper in database table that suits provided condition.
|
<M extends KittyModel> |
findFirst(SQLiteCondition where)
Returns first record in KittyModel wrapper in database table that suits provided condition.
|
<M extends KittyModel> |
findFirst(java.lang.String condition,
java.lang.Object... conditionValues)
Returns first record in KittyModel wrapper in database table that suits provided condition.
|
<M extends KittyModel> |
findLast()
Returns last record in KittyModel wrapper in database table that suits provided condition.
|
<M extends KittyModel> |
findLast(SQLiteCondition where)
Returns last record in KittyModel wrapper in database table that suits provided condition.
|
<M extends KittyModel> |
findLast(java.lang.String condition,
java.lang.Object... conditionValues)
Returns last record in KittyModel wrapper in database table that suits provided condition.
|
<M extends KittyModel> |
findWhere(QueryParameters qParams,
java.lang.String condition,
java.lang.Object... conditionValues)
Returns list of models that suits provided condition string and query parameters.
|
<M extends KittyModel> |
findWhere(SQLiteCondition where)
Returns list of models that suits provided conditions.
|
<M extends KittyModel> |
findWhere(SQLiteCondition where,
QueryParameters qParams)
Returns list of models that suits provided conditions and query parameters.
|
<M extends KittyModel> |
findWhere(java.lang.String condition,
java.lang.Object... conditionValues)
Returns list of models that suits provided condition string.
|
<M extends KittyModel> |
findWithRawQuery(boolean rowIdSupport,
KittySQLiteQuery query)
Tries to fetch data from database table with provided query and wrap it into collection of models.
|
void |
finishTransaction()
Trying to finish transaction, sets transaction successful and if failed than
throws
KittyRuntimeException that holds original exception. |
protected <M extends KittyModel> |
getBlankModelInstance()
Creates new model via default constructor
You should rewrite it, I suppose, for better performance
cause it uses one more reflection magic piece,
however, you know, it makes model classes more pretty to look
also, if you are big fan of entropy and want to make
death of universe closer, you also can rewrite this method
for parametrized models with
Context for serializing
objects to be stored in databaseClass (you're sick!) |
KittyColumnConfiguration |
getColumnByFieldName(java.lang.String fieldName)
Returns column name associated with model field name or null if nothing found
|
protected <M extends KittyModel> |
getInsertStatement(M model) |
protected SQLiteCondition |
getIPKCondition(java.lang.Long id)
Creates condition "WHERE {IPK} = ?"
|
protected <M extends KittyModel> |
getModelClass()
Returns model class associated with this mapper child
|
protected <M extends KittyModel> |
getPKCondition(M model,
SQLiteCondition defaultCondition)
Returns PK condition for provided model, there are following steps:
If provided default condition not null, it would be returned. |
protected <M extends KittyModel> |
getPrimaryKeyValuesForModel(M model)
Tries to return primary key values from provided model as map where keys are column names of PK
and values are string representations of PK's values from model's fields.
|
protected SQLiteCondition |
getRowIDCondition(java.lang.Long id)
Creates condition "WHERE rowid = ?"
|
protected <M extends KittyModel> |
getRowIDCondition(M model)
Creates condition "WHERE rowid = ?"
|
protected SQLiteCondition |
getSQLiteConditionForPK(KittyPrimaryKey primaryKey)
Returns SQLiteCondition from provided PK's map where keys of map are column's names of table and
values are values of those columns.
|
protected SQLiteCondition |
getSQLiteConditionForPKKeyValues(java.util.Map<java.lang.String,java.lang.String> pkKeyValues)
Returns SQLiteCondition from provided map where keys of map are column's names of table and
values are values of those columns.
|
void |
getWritableDatabase()
Opens current db
|
void |
getWritableDatabase(java.lang.String pwd)
Opens current encrypted db with provided password
|
<M extends KittyModel> |
insert(KittyMapper.TRANSACTION_MODES txMode,
java.util.List<M> models)
Inserts models in provided list into database table in new transaction. |
<M extends KittyModel> |
insert(java.util.List<M> models)
Inserts models in provided list into database table.
|
<M extends KittyModel> |
insert(M model)
Inserts into database provided model's values.
|
<M extends KittyModel> |
insertInTransaction(java.util.List<M> models)
Inserts models in provided list into database table in internal method transaction started with
transaction mode
KittyMapper.TRANSACTION_MODES.EXCLUSIVE_MODE . |
boolean |
isTransactionON()
Returns transaction state.
|
protected <M extends KittyModel> |
logModel(java.lang.String executor,
M model)
Logs model to log if logOn and !
|
static <M extends KittyModel> |
logModel(java.lang.String executor,
M model,
java.lang.String logTag,
boolean logOn,
boolean productionOn,
java.lang.Object helper,
java.lang.String schemaName,
int schemaVersion)
Logs model to log depends on parameter flags
|
protected void |
logQuery(java.lang.String executor,
KittySQLiteQuery query)
Logs query or fake query to log
|
static void |
logQuery(java.lang.String executor,
KittySQLiteQuery query,
java.lang.String logTag,
boolean logOn,
boolean productionMode,
java.lang.Object helper,
java.lang.String schemaName,
int schemaVersion)
Logs query to log depends on parameter flags
|
protected java.lang.String |
pkvMapToString(java.util.Map<java.lang.String,java.lang.String> pkv)
Returns string like '( key1 = value1 ; key2 = value2 )' for provided pkv.
|
<M extends KittyModel> |
save(KittyMapper.TRANSACTION_MODES txMode,
java.util.List<M> models)
Saves values from provided list of models into database.
|
<M extends KittyModel> |
save(java.util.List<M> models)
Saves values from provided list of models into database.
|
<M extends KittyModel> |
save(M model)
Saves data from provided model into database table.
|
<M extends KittyModel> |
saveInTransaction(java.util.List<M> models)
Saves values from provided list of models into database.
|
<H extends KittyDatabaseHelper> |
setDatabaseHelper(H helper) |
void |
setLogOn(boolean logOn) |
void |
setLogTag(java.lang.String logTag) |
void |
setReturnNullNotEmptyCollection(boolean returnNullNotEmptyCollection)
Defines what would be returned by fetch methods in cases when nothing found in
database table.
|
void |
setRowIDSupport(boolean rowIDSupport)
Sets rowid support.
|
void |
startTransaction()
Starts transaction on current database instance in
KittyMapper.TRANSACTION_MODES.EXCLUSIVE_MODE . |
void |
startTransaction(KittyMapper.TRANSACTION_MODES mode)
Starts transaction on current database instance.
|
long |
sum(java.lang.String sumColumn,
QueryParameters qParams,
java.lang.String condition,
java.lang.Object... conditionValues)
Sum all values in table in specified column that suits provided condition and additional query qParams.
|
long |
sum(java.lang.String sumColumn,
SQLiteCondition where)
Sum all values in table in specified column that suits provided condition.
|
long |
sum(java.lang.String sumColumn,
SQLiteCondition where,
QueryParameters qParams)
Sum all values in table in specified column that suits provided condition and additional query qParams.
|
long |
sum(java.lang.String sumColumn,
java.lang.String condition,
java.lang.Object... conditionValues)
Sum all values in table in specified column that suits provided condition and additional query qParams.
|
long |
sumAll(java.lang.String sumColumn)
Sum all values in table in specified column.
|
long |
sumAll(java.lang.String sumColumn,
QueryParameters qParams)
Sum all values in table in specified column that suits provided additional query qParams.
|
void |
throwExcReadOPWhileInTransaction()
Call this method in read OP to throw exception if in transaction
|
<M extends KittyModel> |
update(KittyMapper.TRANSACTION_MODES txMode,
java.util.List<M> models)
Updates values in database with values from models from provided list in new transaction..
|
<M extends KittyModel> |
update(java.util.List<M> models)
Update records from database with values from provided list of model.
|
<M extends KittyModel> |
update(M model)
Update records from database with values from provided model.
|
<M extends KittyModel> |
update(M model,
SQLiteCondition condition)
Update records from database with values from provided model that suits provided condition.
|
<M extends KittyModel> |
update(M model,
SQLiteCondition condition,
java.lang.String[] names,
int IEFlag)
Update records from database with values from provided model that suits provided condition.
|
<M extends KittyModel> |
update(M model,
java.lang.String[] names,
int IEFlag,
java.lang.String condition,
java.lang.Object... conditionValues)
See
update(KittyModel, SQLiteCondition, String[], int) for more info |
<M extends KittyModel> |
update(M model,
java.lang.String condition,
java.lang.Object... conditionValues) |
<M extends KittyModel> |
updateInTransaction(java.util.List<M> models)
Updates rows in database with models from provided list in internal method transaction started with
transaction mode
KittyMapper.TRANSACTION_MODES.EXCLUSIVE_MODE . |
protected final SQLiteConditionBuilder conditionBuilder
protected final java.util.List<java.lang.String> insertPKExclusions
protected final KittyTableConfiguration tableConfig
protected final KittyModelCVFactory cursorToModelFactory
protected final KittyModel blankModelInstance
protected KittyDatabaseHelper databaseHelper
protected final java.lang.String databasePassword
protected android.database.sqlite.SQLiteDatabase database
protected boolean rowidOn
protected boolean logOn
protected java.lang.String logTag
protected boolean returnNullNotEmptyCollection
protected final java.util.HashMap<KittyArrayKey,InsertValuesStatement> precompiledInserts
protected final java.util.HashMap<java.lang.String,KittyColumnConfiguration> columnConfigurations
protected static final java.lang.String QE_COUNT
protected static final java.lang.String QE_SUM
protected static final java.lang.String QE_INSERT
protected static final java.lang.String QE_INSERT_FAKE_QUERY
protected static java.lang.String INS_PL
protected static final java.lang.String KE_INSERT_READ_ONLY
protected static final java.lang.String QE_UPDATE
protected static final java.lang.String QE_UPDATE_FAKE_QUERY
protected static final java.lang.String UPDATE_PL
protected static final java.lang.String KE_UPDATE_READ_ONLY
protected static final java.lang.String KE_SAVE_READ_ONLY
protected static final java.lang.String QE_DELETE_ALL
protected static final java.lang.String QE_DELETE_ALL_FAKE_QUERY
protected static final java.lang.String QE_DELETE_BY_WHERE
protected static final java.lang.String QE_DELETE_FAKE_QUERY
protected static java.lang.String DELETE_PL2
protected static java.lang.String DELETE_PL
protected static final java.lang.String KE_DELETE_READ_ONLY
protected static final java.lang.String QE_FIND_WITH_RAW_QUERY
protected static final java.lang.String QE_EXECUTE_RAW_QUERY
public static final java.lang.String QUERY_LOG_PATTERN
public static final java.lang.String MODEL_LOG_PATTERN
public static final java.lang.String MODEL_NOT_IMPL
public KittyMapper(KittyTableConfiguration tableConfiguration, M blankModelInstance, java.lang.String databasePassword)
public final <H extends KittyDatabaseHelper> KittyMapper setDatabaseHelper(H helper)
public final void setReturnNullNotEmptyCollection(boolean returnNullNotEmptyCollection)
returnNullNotEmptyCollection
- public final void setLogOn(boolean logOn)
public final void setLogTag(java.lang.String logTag)
public final void setRowIDSupport(boolean rowIDSupport)
KittyModel.rowid
value set. Also, if rowid not null that means
that all operations with current models already fetched from db (delete\\update)
would be done through rowid (that faster than fecthing PK values via reflection)rowIDSupport
- flag if rowid on or off (by default rowid is ON)public void getWritableDatabase()
public void getWritableDatabase(java.lang.String pwd)
pwd
- public void close()
public final void startTransaction(KittyMapper.TRANSACTION_MODES mode)
finishTransaction()
).
KittyRuntimeException
.mode
- mode to start with, following modes are available:
KittyMapper.TRANSACTION_MODES.EXCLUSIVE_MODE
- starting with this mode would start
transaction in exclusive mode (SQLiteDatabase.beginTransaction()
)
KittyMapper.TRANSACTION_MODES.NON_EXCLUSIVE_MODE
- starting with this mode would start
transaction in immediate mode, this mode requires api 11 and higher
(SQLiteDatabase.beginTransactionNonExclusive()
). If current api level lower than
api 11 than transaction would be started in KittyMapper.TRANSACTION_MODES.EXCLUSIVE_MODE
KittyMapper.TRANSACTION_MODES.LOCKING_FALSE_MODE
- starting transaction with false
locking option (SQLiteDatabase.setLockingEnabled(boolean)
).KittyRuntimeException
- if trying to start transaction when transaction already startedprotected <M extends KittyModel> InsertValuesStatement getInsertStatement(M model)
public final void startTransaction()
KittyMapper.TRANSACTION_MODES.EXCLUSIVE_MODE
.
That means that all write operations on DB would be accumulated
to buffer and written to DB only after ending transaction (finishTransaction()
).
KittyRuntimeException
.public final void finishTransaction()
KittyRuntimeException
that holds original exception.public final boolean isTransactionON()
public final void throwExcReadOPWhileInTransaction()
public final <M extends KittyModel> java.util.List<M> findWhere(QueryParameters qParams, java.lang.String condition, java.lang.Object... conditionValues)
qParams
- additional query parameters (offset, limit, ordering etc), can be nullcondition
- sqlite condition string in format `column_name = ? AND #?fieldName = ?`conditionValues
- parameters for condition strKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> java.util.List<M> findWhere(java.lang.String condition, java.lang.Object... conditionValues)
condition
- sqlite condition string in format `column_name = ? AND #?fieldName = ?`conditionValues
- parameters for condition strKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> java.util.List<M> findWhere(SQLiteCondition where, QueryParameters qParams)
where
- condition, can be nullqParams
- additional query parameters (offset, limit, ordering etc), can be nullKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> java.util.List<M> findWhere(SQLiteCondition where)
findWhere(SQLiteCondition, QueryParameters)
(findWhere(where, null)where
- condition, can be nullKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> java.util.List<M> findAll(QueryParameters qParams)
findWhere(SQLiteCondition, QueryParameters)
(findWhere(null, qParams)qParams
- query params such as limit, offset etc, can be nullKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> java.util.List<M> findAll()
KittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> M findByRowID(java.lang.Long rowid)
getRowIDCondition(Long)
returned null, KittyRuntimeException would be thrown.
findWhere(SQLiteCondition, QueryParameters)
(findWhere("rowid = ?", null).get(0)
with check that resulting collection's size == 0 | 1rowid
- RowID of database table's record to fetchKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> M findByPK(KittyPrimaryKey primaryKey)
KittyPrimaryKey
) found.
getSQLiteConditionForPKKeyValues(Map)
returned null, KittyRuntimeException would be thrown.
findWhere(SQLiteCondition, QueryParameters)
(findWhere({PKCondition}, null).get(0)
with check that resulting collection's size == 0 | 1M
- instance of non abstract child of KittyModelprimaryKey
- primary key filled with values, also notice that there is no check for PKKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> M findByPKV(java.util.Map<java.lang.String,java.lang.String> pkv)
KittyPrimaryKey.getPrimaryKeyColumnValues()
) found.
getSQLiteConditionForPKKeyValues(Map)
returned null, KittyRuntimeException would be thrown.
findWhere(SQLiteCondition, QueryParameters)
(findWhere({PKCondition}, null).get(0)
with check that resulting collection's size == 0 | 1pkv
- primary key values map, also notice that there is no check for PK valuesKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> M findByIPK(java.lang.Long ipk)
getIPKCondition(Long)
returned null, KittyRuntimeException would be thrown.
findWhere(SQLiteCondition, QueryParameters)
(findWhere("{IPK} = ?", null).get(0)
with check that resulting collection's size == 0 | 1ipk
- INTEGER PRIMARY KEY value of database table's record to fetchKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> M findFirst(SQLiteCondition where)
findWhere(SQLiteCondition, QueryParameters)
(findWhere(conditions, {LIMIT = 1, ORDER BY rowid ASCENDING}where
- SQLiteCondition for selectKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> M findFirst(java.lang.String condition, java.lang.Object... conditionValues)
findWhere(QueryParameters, String, Object...)
(findWhere({LIMIT = 1, ORDER BY rowid ASCENDING}, conditionStr, conditionValues)condition
- sqlite condition string in format `column_name = ? AND #?fieldName = ?`conditionValues
- parameters for condition strKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> M findFirst()
findWhere(SQLiteCondition, QueryParameters)
(findWhere(null, {LIMIT = 1, ORDER BY rowid ASCENDING}KittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> M findLast(SQLiteCondition where)
findWhere(SQLiteCondition, QueryParameters)
(findWhere(conditions, {LIMIT = 1, ORDER BY rowid DESCENDING}M
- instance of non abstract child of KittyModelwhere
- SQLiteCondition for selectKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> M findLast(java.lang.String condition, java.lang.Object... conditionValues)
findWhere(SQLiteCondition, QueryParameters)
(findWhere({LIMIT = 1, ORDER BY rowid DESCENDING}, conditionStr, conditionValues))condition
- sqlite condition string in format `column_name = ? AND #?fieldName = ?`conditionValues
- parameters for condition strKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> M findLast()
findWhere(SQLiteCondition, QueryParameters)
(findWhere(null, {LIMIT = 1, ORDER BY rowid DESCENDING}M
- instance of non abstract child of KittyModelKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final long countWhere(SQLiteCondition where, QueryParameters qParams)
where
- SQLite condition, may be nullqParams
- query qParams, may be nullKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final long countWhere(QueryParameters qParams, java.lang.String condition, java.lang.Object... conditionValues)
qParams
- query qParams, may be nullcondition
- sqlite condition string in format `column_name = ? AND #?fieldName = ?`conditionValues
- parameters for condition strKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final long countWhere(java.lang.String condition, java.lang.Object... conditionValues)
condition
- sqlite condition string in format `column_name = ? AND #?fieldName = ?`conditionValues
- parameters for condition strKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final long countWhere(SQLiteCondition where)
countWhere(SQLiteCondition, QueryParameters)
(countWhere(condition, null)where
- SQLite condition, may be nullKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final long countAll(QueryParameters qParams)
countWhere(SQLiteCondition, QueryParameters)
(countWhere(null, qParams)qParams
- query parameters such as OFFSET, LIMIT etcKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final long countAll()
countWhere(SQLiteCondition, QueryParameters)
(countWhere(null, null)KittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final long sum(java.lang.String sumColumn, QueryParameters qParams, java.lang.String condition, java.lang.Object... conditionValues)
sumColumn
- qParams
- condition
- conditionValues
- public final long sum(java.lang.String sumColumn, java.lang.String condition, java.lang.Object... conditionValues)
sumColumn
- condition
- conditionValues
- public final long sum(java.lang.String sumColumn, SQLiteCondition where, QueryParameters qParams)
sumColumn
- column name from where should be values summedwhere
- SQLite condition for SUMqParams
- additional query qParamsKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final long sum(java.lang.String sumColumn, SQLiteCondition where)
sum(String, SQLiteCondition, QueryParameters)
(sum(colName, condition, null).sumColumn
- column name from where should be values summedwhere
- SQLite condition for SUMKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final long sumAll(java.lang.String sumColumn, QueryParameters qParams)
sum(String, SQLiteCondition, QueryParameters)
(sum(colName, null, qParams).sumColumn
- column name from where should be values summedqParams
- additional query qParamsKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final long sumAll(java.lang.String sumColumn)
sum(String, SQLiteCondition, QueryParameters)
(sum(colName, null, null).sumColumn
- column name from where should be values summedKittyRuntimeException
- if there some errors, if KittyRuntimeException was caused by another exception than
first exception can be fetched by KittyRuntimeException.getNestedException()
public final <M extends KittyModel> long insert(M model)
KittyRuntimeException
.M
- instance of non abstract child of KittyModelmodel
- model to insertspublic final <M extends KittyModel> void insert(java.util.List<M> models)
KittyRuntimeException
.M
- instance of non abstract child of KittyModelmodels
- list of models to insertpublic final <M extends KittyModel> void insertInTransaction(java.util.List<M> models)
KittyMapper.TRANSACTION_MODES.EXCLUSIVE_MODE
.
insert(TRANSACTION_MODES, List)
insert(TRANSACTION_MODES.EXCLUSIVE_MODE, models)
KittyRuntimeException
.M
- instance of non abstract child of KittyModelmodels
- list of models to insertpublic final <M extends KittyModel> void insert(KittyMapper.TRANSACTION_MODES txMode, java.util.List<M> models)
M
- instance of non abstract child of KittyModeltxMode
- transaction mode, see startTransaction(TRANSACTION_MODES)
for modes infomodels
- list of models to insertpublic final <M extends KittyModel> long update(M model, SQLiteCondition condition, java.lang.String[] names, int IEFlag)
KITTY_COLUMN
.
CVUtils.INCLUDE_ONLY_SELECTED_COLUMN_NAMES
CVUtils.INCLUDE_ONLY_SELECTED_FIELDS
M
- instance of non abstract child of KittyModelmodel
- model to updatecondition
- condition for that modelnames
- array of fields names or column names to include\excludeIEFlag
- flag that determines what to do with provided KittyColumnConfiguration
instance, may be CVUtils.IGNORE_INCLUSIONS_AND_EXCLUSIONS
,
CVUtils.INCLUDE_ALL_EXCEPT_SELECTED_COLUMN_NAMES
, CVUtils.INCLUDE_ONLY_SELECTED_COLUMN_NAMES
, CVUtils.INCLUDE_ALL_EXCEPT_SELECTED_FIELDS
or CVUtils.INCLUDE_ONLY_SELECTED_FIELDS
. If flag's value differs from any of inclusion predefined flags than would be used default flag
(CVUtils.IGNORE_INCLUSIONS_AND_EXCLUSIONS
)public final <M extends KittyModel> long update(M model, java.lang.String[] names, int IEFlag, java.lang.String condition, java.lang.Object... conditionValues)
update(KittyModel, SQLiteCondition, String[], int)
for more infoM
- model
- names
- IEFlag
- condition
- conditionValues
- public final <M extends KittyModel> long update(M model, SQLiteCondition condition)
KittyRuntimeException
would be thrown.M
- model
- condition
- public final <M extends KittyModel> long update(M model, java.lang.String condition, java.lang.Object... conditionValues)
public final <M extends KittyModel> long update(M model)
KittyRuntimeException
would be thrown.
update(KittyModel, SQLiteCondition)
update(model, null)M
- instance of non abstract child of KittyModelmodel
- model to updatepublic final <M extends KittyModel> long update(java.util.List<M> models)
KittyRuntimeException
would be thrown.M
- instance of non abstract child of KittyModelmodels
- list of models to updatepublic final <M extends KittyModel> void update(KittyMapper.TRANSACTION_MODES txMode, java.util.List<M> models)
KittyRuntimeException
would be thrown.
M
- instance of non abstract child of KittyModeltxMode
- transaction mode, see startTransaction(TRANSACTION_MODES)
for modes infomodels
- list of models to updatepublic final <M extends KittyModel> void updateInTransaction(java.util.List<M> models)
KittyMapper.TRANSACTION_MODES.EXCLUSIVE_MODE
.
update(TRANSACTION_MODES, List)
(update(TRANSACTION_MODES.EXCLUSIVE_MODE, models)
KittyRuntimeException
.M
- instance of non abstract child of KittyModelmodels
- list of models to updatepublic final <M extends KittyModel> void save(M model)
update(KittyModel)
would
be called.
insert(KittyModel)
would be called.M
- instance of non abstract child of KittyModelmodel
- model to savepublic final <M extends KittyModel> void save(java.util.List<M> models)
save(KittyModel)
method would be called.M
- instance of non abstract child of KittyModelmodels
- list of models to savepublic final <M extends KittyModel> void save(KittyMapper.TRANSACTION_MODES txMode, java.util.List<M> models)
save(KittyModel)
method would be called. Insert\\update operations would be run in internal method transaction.
M
- instance of non abstract child of KittyModeltxMode
- transaction mode, see startTransaction(TRANSACTION_MODES)
for modes infomodels
- list of models to savepublic final <M extends KittyModel> void saveInTransaction(java.util.List<M> models)
save(KittyModel)
method would be called. Insert\\update operations would be run in internal method transaction
started with transaction mode KittyMapper.TRANSACTION_MODES.EXCLUSIVE_MODE
.
save(TRANSACTION_MODES, List)
(save(TRANSACTION_MODES.EXCLUSIVE_MODE, models)
KittyRuntimeException
.M
- instance of non abstract child of KittyModelmodels
- list of models to savepublic final long deleteAll()
public final long deleteWhere(java.lang.String condition, java.lang.Object... conditionValues)
condition
- not nullconditionValues
- public final long deleteWhere(SQLiteCondition condition)
condition
- SQLite condition, not nullpublic final <M extends KittyModel> long delete(M model)
KittyRuntimeException
would be thrown.M
- instance of non abstract child of KittyModelmodel
- model to deletepublic final <M extends KittyModel> void delete(java.util.List<M> models)
KittyRuntimeException
would be thrown.M
- instance of non abstract child of KittyModelmodels
- list of models to deletepublic final <M extends KittyModel> void delete(KittyMapper.TRANSACTION_MODES txMode, java.util.List<M> models)
KittyRuntimeException
would be thrown.
Delete operations would be run in internal method transaction.
M
- instance of non abstract child of KittyModeltxMode
- transaction mode, see startTransaction(TRANSACTION_MODES)
for modes infomodels
- list of models to deletepublic final <M extends KittyModel> void deleteInTransaction(java.util.List<M> models)
KittyRuntimeException
would be thrown.
Delete operations would be run in internal method transaction
started with transaction mode KittyMapper.TRANSACTION_MODES.EXCLUSIVE_MODE
.
delete(TRANSACTION_MODES, List)
(delete(TRANSACTION_MODES.EXCLUSIVE_MODE, models)
KittyRuntimeException
.M
- instance of non abstract child of KittyModelmodels
- list of models to deletepublic long deleteByPK(KittyPrimaryKey pk)
getSQLiteConditionForPK(KittyPrimaryKey)
null than KittyRuntimeException
would be thrown.pk
- primary key for generating delete condition.public long deleteByRowID(java.lang.Long rowid)
getRowIDCondition(Long)
null than KittyRuntimeException
would be thrown.rowid
- row idpublic long deleteByIPK(java.lang.Long id)
getIPKCondition(Long)
null than KittyRuntimeException
would be thrown.id
- INTEGER PRIMARY KEY VALUEpublic final <M extends KittyModel> java.util.List<M> findWithRawQuery(boolean rowIdSupport, KittySQLiteQuery query)
M
- instance of non abstract child of KittyModelrowIdSupport
- RowID flagquery
- sql querypublic final void executeRawQuery(java.lang.String querySQL, java.lang.String... parameters)
querySQL
- the SQL statement to be executed. Multiple statements separated by semicolons are
not supported.parameters
- only byte[], String, Long and Double are supported in bindArgs.android.database.SQLException
- if the SQL string is invalidprotected final <M extends KittyModel> java.lang.Class<M> getModelClass()
protected <M extends KittyModel> M getBlankModelInstance()
Context
for serializing
objects to be stored in databaseClass (you're sick!)protected <M extends KittyModel> M cloneModel(java.lang.Class<M> modelClass)
M
- modelClass
- public <D extends KittyMapper> D clone(java.lang.Class<D> recordClass)
D
- recordClass
- public KittyMapper clone()
clone
in class java.lang.Object
protected final <M extends KittyModel> SQLiteCondition getPKCondition(M model, SQLiteCondition defaultCondition)
KittyPrimaryKey
instance set in KittyTableConfiguration
for provided
model.
M
- not abstract child of KittyModel
model
- KittyModel child instancedefaultCondition
- default condition, may be null, if not null than it would be returnedKittyRuntimeException
- throws exceptions wrapped into KittyRuntimeException
protected final SQLiteCondition getSQLiteConditionForPK(KittyPrimaryKey primaryKey)
primaryKey
- PK with bounded values to useprotected final SQLiteCondition getSQLiteConditionForPKKeyValues(java.util.Map<java.lang.String,java.lang.String> pkKeyValues)
pkKeyValues
- map of column names and values to create SQLiteConditionprotected final <M extends KittyModel> java.util.Map<java.lang.String,java.lang.String> getPrimaryKeyValuesForModel(M model)
M
- not abstract child of KittyModel
model
- model from what should be PK condition be generatedprotected final SQLiteCondition getIPKCondition(java.lang.Long id)
id
- protected final <M extends KittyModel> SQLiteCondition getRowIDCondition(M model)
M
- instance of not abstract child of KittyModel
model
- modelprotected final SQLiteCondition getRowIDCondition(java.lang.Long id)
id
- RowID valueprotected final void logQuery(java.lang.String executor, KittySQLiteQuery query)
executor
- query
- protected final <M extends KittyModel> void logModel(java.lang.String executor, M model)
M
- executor
- model
- public static final void logQuery(java.lang.String executor, KittySQLiteQuery query, java.lang.String logTag, boolean logOn, boolean productionMode, java.lang.Object helper, java.lang.String schemaName, int schemaVersion)
executor
- query
- logTag
- logOn
- productionMode
- helper
- schemaName
- schemaVersion
- public static final <M extends KittyModel> void logModel(java.lang.String executor, M model, java.lang.String logTag, boolean logOn, boolean productionOn, java.lang.Object helper, java.lang.String schemaName, int schemaVersion)
M
- executor
- model
- logTag
- logOn
- productionOn
- helper
- schemaName
- schemaVersion
- protected final java.lang.String pkvMapToString(java.util.Map<java.lang.String,java.lang.String> pkv)
pkv
- map for PKprotected final SQLiteCondition conditionFromSQLString(java.lang.String condition, java.lang.Object... params)
SQLiteCondition
from SQLite string and set of parameters.
SQLiteConditionBuilder.fromSQL(String, Class, Object...)
but there is no
need to pass model class cause mapper already knows it
condition
- params
- public KittyColumnConfiguration getColumnByFieldName(java.lang.String fieldName)
fieldName
-