public class DatabaseCompartment
extends java.lang.Object
CupboardDatabase. A DatabaseCompartment is created from Cupboard.withDatabase(SQLiteDatabase)
or Cupboard.withDatabase(CupboardDatabase)
SQLiteDatabase db = ... // get the book with id 1 Book book = cupboard().withDatabase(db).get(Book.class, 1L);
| Modifier and Type | Class and Description |
|---|---|
static class |
DatabaseCompartment.QueryBuilder<T> |
| Constructor and Description |
|---|
DatabaseCompartment(Cupboard cupboard,
android.database.sqlite.SQLiteDatabase database) |
| Modifier and Type | Method and Description |
|---|---|
void |
createTables()
Create tables for the classes registered with
Cupboard.register(Class). |
boolean |
delete(java.lang.Class<?> entityClass,
long id)
Delete an entity by id
|
int |
delete(java.lang.Class<?> entityClass,
java.lang.String selection,
java.lang.String... selectionArgs)
Delete entities
|
<T> boolean |
delete(T entity)
Delete an entity
|
void |
dropAllIndices()
Remove all indices for the classes registered with
Cupboard.register(Class), including
any indices not added by Cupboard. |
void |
dropAllTables()
Drop all tables for the classes registered with
Cupboard.register(Class) |
<T> T |
get(java.lang.Class<T> entityClass,
long id)
Get an entity by id
|
<T> T |
get(T object)
Get an entity by the id set on an example entity
|
protected <T> EntityConverter<T> |
getConverter(java.lang.Class<T> clz) |
long |
put(java.lang.Class<?> entityClass,
android.content.ContentValues values)
Put an entity from a
ContentValues object. |
void |
put(java.util.Collection<?> entities)
Put multiple entities in a single transaction.
|
void |
put(java.lang.Object... entities)
Put multiple entities in a single transaction.
|
<T> long |
put(T entity)
Put a single entity.
|
<T> DatabaseCompartment.QueryBuilder<T> |
query(java.lang.Class<T> entityClass)
Query entities
|
int |
update(java.lang.Class<?> entityClass,
android.content.ContentValues values)
Update entities
|
int |
update(java.lang.Class<?> entityClass,
android.content.ContentValues values,
java.lang.String selection,
java.lang.String... selectionArgs)
Update entities
|
void |
upgradeTables()
Upgrade and / or create tables for the classes registered with
Cupboard.register(Class)
This is useful in SQLiteOpenHelper.onUpgrade(SQLiteDatabase, int, int) |
protected final Cupboard mCupboard
public DatabaseCompartment(Cupboard cupboard, android.database.sqlite.SQLiteDatabase database)
public void createTables()
Cupboard.register(Class).
This is useful in SQLiteOpenHelper.onCreate(SQLiteDatabase)public void upgradeTables()
Cupboard.register(Class)
This is useful in SQLiteOpenHelper.onUpgrade(SQLiteDatabase, int, int)public void dropAllTables()
Cupboard.register(Class)public void dropAllIndices()
Cupboard.register(Class), including
any indices not added by Cupboard. Typically called before upgrading tables.public <T> T get(java.lang.Class<T> entityClass,
long id)
entityClass - the entity classid - the id of the entitypublic <T> T get(T object)
throws java.lang.IllegalArgumentException
object - the entityjava.lang.IllegalArgumentException - if the entity id is not setpublic <T> DatabaseCompartment.QueryBuilder<T> query(java.lang.Class<T> entityClass)
entityClass - the entity to query forDatabaseCompartment.QueryBuilder for chainingpublic void put(java.lang.Object... entities)
entities - the entitiespublic void put(java.util.Collection<?> entities)
entities - the entitiespublic <T> long put(T entity)
entity - the entitypublic long put(java.lang.Class<?> entityClass,
android.content.ContentValues values)
ContentValues object.
If the content values contain a BaseColumns._ID then this id will be used and an existing entity will be replaced.entityClass - the entity classvalues - the content valuespublic int update(java.lang.Class<?> entityClass,
android.content.ContentValues values)
entityClass - the entity classvalues - the content values. If it contains a BaseColumns._ID then only the entity with the given id will be updated (if any)public int update(java.lang.Class<?> entityClass,
android.content.ContentValues values,
java.lang.String selection,
java.lang.String... selectionArgs)
entityClass - entity classvalues - content valuesselection - where clauseselectionArgs - selection argumentspublic <T> boolean delete(T entity)
entity - the entity to delete.public boolean delete(java.lang.Class<?> entityClass,
long id)
entityClass - the entity classid - the entity idpublic int delete(java.lang.Class<?> entityClass,
java.lang.String selection,
java.lang.String... selectionArgs)
entityClass - the entity classselection - where clauseselectionArgs - selection argumentsprotected <T> EntityConverter<T> getConverter(java.lang.Class<T> clz)