T
- Entity typeK
- Primary key (PK) type; use Void if entity does not have exactly one PKpublic abstract class AbstractDao<T,K>
extends java.lang.Object
This class is thread-safe.
Modifier and Type | Field and Description |
---|---|
protected de.greenrobot.dao.internal.DaoConfig |
config |
protected android.database.sqlite.SQLiteDatabase |
db |
protected IdentityScope<K,T> |
identityScope |
protected IdentityScopeLong<T> |
identityScopeLong |
protected int |
pkOrdinal |
protected AbstractDaoSession |
session |
protected de.greenrobot.dao.internal.TableStatements |
statements |
Constructor and Description |
---|
AbstractDao(de.greenrobot.dao.internal.DaoConfig config) |
AbstractDao(de.greenrobot.dao.internal.DaoConfig config,
AbstractDaoSession daoSession) |
Modifier and Type | Method and Description |
---|---|
protected void |
assertSinglePk() |
protected void |
attachEntity(K key,
T entity,
boolean lock)
Attaches the entity to the identity scope.
|
protected void |
attachEntity(T entity)
Sub classes with relations additionally set the DaoMaster here.
|
protected abstract void |
bindValues(android.database.sqlite.SQLiteStatement stmt,
T entity)
Binds the entity's values to the statement.
|
long |
count() |
void |
delete(T entity)
Deletes the given entity from the database.
|
void |
deleteAll() |
void |
deleteByKey(K key)
Deletes an entity with the given PK from the database.
|
void |
deleteByKeyInTx(java.lang.Iterable<K> keys)
Deletes all entities with the given keys in the database using a transaction.
|
void |
deleteByKeyInTx(K... keys)
Deletes all entities with the given keys in the database using a transaction.
|
void |
deleteInTx(java.lang.Iterable<T> entities)
Deletes the given entities in the database using a transaction.
|
void |
deleteInTx(T... entities)
Deletes the given entities in the database using a transaction.
|
boolean |
detach(T entity)
Detaches an entity from the identity scope (session).
|
java.lang.String[] |
getAllColumns() |
android.database.sqlite.SQLiteDatabase |
getDatabase()
Gets the SQLiteDatabase for custom database access.
|
protected abstract K |
getKey(T entity)
Returns the value of the primary key, if the entity has a single primary key, or, if not, null.
|
protected K |
getKeyVerified(T entity)
See
getKey(Object) , but guarantees that the returned key is never null (throws if null). |
java.lang.String[] |
getNonPkColumns() |
java.lang.String[] |
getPkColumns() |
Property |
getPkProperty() |
Property[] |
getProperties() |
AbstractDaoSession |
getSession() |
java.lang.String |
getTablename() |
long |
insert(T entity)
Insert an entity into the table associated with a concrete DAO.
|
void |
insertInTx(java.lang.Iterable<T> entities)
Inserts the given entities in the database using a transaction.
|
void |
insertInTx(java.lang.Iterable<T> entities,
boolean setPrimaryKey)
Inserts the given entities in the database using a transaction.
|
void |
insertInTx(T... entities)
Inserts the given entities in the database using a transaction.
|
long |
insertOrReplace(T entity)
Insert an entity into the table associated with a concrete DAO.
|
void |
insertOrReplaceInTx(java.lang.Iterable<T> entities)
Inserts or replaces the given entities in the database using a transaction.
|
void |
insertOrReplaceInTx(java.lang.Iterable<T> entities,
boolean setPrimaryKey)
Inserts or replaces the given entities in the database using a transaction.
|
void |
insertOrReplaceInTx(T... entities)
Inserts or replaces the given entities in the database using a transaction.
|
long |
insertWithoutSettingPk(T entity)
Insert an entity into the table associated with a concrete DAO without setting key property.
|
protected abstract boolean |
isEntityUpdateable()
Returns true if the Entity class can be updated, e.g. for setting the PK after insert.
|
T |
load(K key)
Loads and entity for the given PK.
|
java.util.List<T> |
loadAll()
Loads all available entities from the database.
|
protected java.util.List<T> |
loadAllAndCloseCursor(android.database.Cursor cursor) |
protected java.util.List<T> |
loadAllFromCursor(android.database.Cursor cursor)
Reads all available rows from the given cursor and returns a list of entities.
|
T |
loadByRowId(long rowId) |
protected T |
loadCurrent(android.database.Cursor cursor,
int offset,
boolean lock)
Internal use only.
|
protected <O> O |
loadCurrentOther(AbstractDao<O,?> dao,
android.database.Cursor cursor,
int offset)
Internal use only.
|
protected T |
loadUnique(android.database.Cursor cursor) |
protected T |
loadUniqueAndCloseCursor(android.database.Cursor cursor) |
QueryBuilder<T> |
queryBuilder() |
java.util.List<T> |
queryRaw(java.lang.String where,
java.lang.String... selectionArg)
A raw-style query where you can pass any WHERE clause and arguments.
|
Query<T> |
queryRawCreate(java.lang.String where,
java.lang.Object... selectionArg)
Creates a repeatable
Query object based on the given raw SQL where you can pass any WHERE clause and
arguments. |
Query<T> |
queryRawCreateListArgs(java.lang.String where,
java.util.Collection<java.lang.Object> selectionArg)
Creates a repeatable
Query object based on the given raw SQL where you can pass any WHERE clause and
arguments. |
protected abstract T |
readEntity(android.database.Cursor cursor,
int offset)
Reads the values from the current position of the given cursor and returns a new entity.
|
protected abstract void |
readEntity(android.database.Cursor cursor,
T entity,
int offset)
Reads the values from the current position of the given cursor into an existing entity.
|
protected abstract K |
readKey(android.database.Cursor cursor,
int offset)
Reads the key from the current position of the given cursor, or returns null if there's no single-value key.
|
void |
refresh(T entity)
Resets all locally changed properties of the entity by reloading the values from the database.
|
void |
update(T entity) |
protected void |
updateInsideSynchronized(T entity,
android.database.sqlite.SQLiteStatement stmt,
boolean lock) |
void |
updateInTx(java.lang.Iterable<T> entities)
Updates the given entities in the database using a transaction.
|
void |
updateInTx(T... entities)
Updates the given entities in the database using a transaction.
|
protected abstract K |
updateKeyAfterInsert(T entity,
long rowId)
Updates the entity's key if possible (only for Long PKs currently).
|
protected void |
updateKeyAfterInsertAndAttach(T entity,
long rowId,
boolean lock) |
protected final android.database.sqlite.SQLiteDatabase db
protected final de.greenrobot.dao.internal.DaoConfig config
protected IdentityScope<K,T> identityScope
protected IdentityScopeLong<T> identityScopeLong
protected de.greenrobot.dao.internal.TableStatements statements
protected final AbstractDaoSession session
protected final int pkOrdinal
public AbstractDao(de.greenrobot.dao.internal.DaoConfig config)
public AbstractDao(de.greenrobot.dao.internal.DaoConfig config, AbstractDaoSession daoSession)
public AbstractDaoSession getSession()
public java.lang.String getTablename()
public Property[] getProperties()
public Property getPkProperty()
public java.lang.String[] getAllColumns()
public java.lang.String[] getPkColumns()
public java.lang.String[] getNonPkColumns()
public T load(K key)
key
- a PK value or nullpublic T loadByRowId(long rowId)
protected T loadUniqueAndCloseCursor(android.database.Cursor cursor)
protected T loadUnique(android.database.Cursor cursor)
public java.util.List<T> loadAll()
public boolean detach(T entity)
protected java.util.List<T> loadAllAndCloseCursor(android.database.Cursor cursor)
public void insertInTx(java.lang.Iterable<T> entities)
entities
- The entities to insert.public void insertInTx(T... entities)
entities
- The entities to insert.public void insertInTx(java.lang.Iterable<T> entities, boolean setPrimaryKey)
entities
- The entities to insert.setPrimaryKey
- if true, the PKs of the given will be set after the insert; pass false to improve performance.public void insertOrReplaceInTx(java.lang.Iterable<T> entities, boolean setPrimaryKey)
entities
- The entities to insert.setPrimaryKey
- if true, the PKs of the given will be set after the insert; pass false to improve performance.public void insertOrReplaceInTx(java.lang.Iterable<T> entities)
entities
- The entities to insert.public void insertOrReplaceInTx(T... entities)
entities
- The entities to insert.public long insert(T entity)
public long insertWithoutSettingPk(T entity)
public long insertOrReplace(T entity)
protected void updateKeyAfterInsertAndAttach(T entity, long rowId, boolean lock)
protected java.util.List<T> loadAllFromCursor(android.database.Cursor cursor)
protected final T loadCurrent(android.database.Cursor cursor, int offset, boolean lock)
protected final <O> O loadCurrentOther(AbstractDao<O,?> dao, android.database.Cursor cursor, int offset)
public java.util.List<T> queryRaw(java.lang.String where, java.lang.String... selectionArg)
public Query<T> queryRawCreate(java.lang.String where, java.lang.Object... selectionArg)
Query
object based on the given raw SQL where you can pass any WHERE clause and
arguments.public Query<T> queryRawCreateListArgs(java.lang.String where, java.util.Collection<java.lang.Object> selectionArg)
Query
object based on the given raw SQL where you can pass any WHERE clause and
arguments.public void deleteAll()
public void delete(T entity)
public void deleteByKey(K key)
public void deleteInTx(java.lang.Iterable<T> entities)
entities
- The entities to delete.public void deleteInTx(T... entities)
entities
- The entities to delete.public void deleteByKeyInTx(java.lang.Iterable<K> keys)
keys
- Keys of the entities to delete.public void deleteByKeyInTx(K... keys)
keys
- Keys of the entities to delete.public void refresh(T entity)
public void update(T entity)
public QueryBuilder<T> queryBuilder()
protected void updateInsideSynchronized(T entity, android.database.sqlite.SQLiteStatement stmt, boolean lock)
protected final void attachEntity(K key, T entity, boolean lock)
key
- Needed only for identity scope, pass null if there's none.entity
- The entitiy to attachprotected void attachEntity(T entity)
entity
- The entitiy to attachpublic void updateInTx(java.lang.Iterable<T> entities)
entities
- The entities to insert.public void updateInTx(T... entities)
entities
- The entities to update.protected void assertSinglePk()
public long count()
protected K getKeyVerified(T entity)
getKey(Object)
, but guarantees that the returned key is never null (throws if null).public android.database.sqlite.SQLiteDatabase getDatabase()
protected abstract T readEntity(android.database.Cursor cursor, int offset)
protected abstract K readKey(android.database.Cursor cursor, int offset)
protected abstract void readEntity(android.database.Cursor cursor, T entity, int offset)
protected abstract void bindValues(android.database.sqlite.SQLiteStatement stmt, T entity)
protected abstract K updateKeyAfterInsert(T entity, long rowId)
protected abstract K getKey(T entity)
protected abstract boolean isEntityUpdateable()
Available under the Apache License, Version 2.0 - Copyright © 2011-2015 greenrobot.de. All Rights Reserved.