de.greenrobot.dao
Class AbstractDao

java.lang.Object
  extended by de.greenrobot.dao.AbstractDao
Type Parameters:
T - Entity type
K - Primary key (PK) type; use Void if entity does not have exactly one PK

public abstract class AbstractDao
extends java.lang.Object

    

Base class for all DAOs: Implements entity operations like insert, load, delete, and query.


Constructor Summary
AbstractDao(DaoConfig config)
           
AbstractDao(DaoConfig config, AbstractDaoSession daoSession)
           
 
Method Summary
 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.
 boolean detach(T entity)
          Detaches an entity from the identity scope (session).
 java.lang.String[] getAllColumns()
           
 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 insertWithoutSettingPk(T entity)
          Insert an entity into the table associated with a concrete DAO.
 T load(K key)
          Loads and entity for the given PK.
 java.util.List<T> loadAll()
          Loads all available entities from the database.
 T loadByRowId(long rowId)
           
 java.util.List<T> query(java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String groupBy, java.lang.String having, java.lang.String orderby)
          Performs a standard Android-style query for entities.
 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.
 void refresh(T entity)
          Resets all locally changed properties of the entity by reloading the values from the database.
 void update(T entity)
           
 void updateInTx(java.lang.Iterable<T> entities)
          Inserts the given entities in the database using a transaction.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDao

public AbstractDao(DaoConfig config)

AbstractDao

public AbstractDao(DaoConfig config,
                   AbstractDaoSession daoSession)
Method Detail

getSession

public AbstractDaoSession getSession()

getTablename

public java.lang.String getTablename()

getProperties

public Property[] getProperties()

getPkProperty

public Property getPkProperty()

getAllColumns

public java.lang.String[] getAllColumns()

getPkColumns

public java.lang.String[] getPkColumns()

getNonPkColumns

public java.lang.String[] getNonPkColumns()

load

public T load(K key)
Loads and entity for the given PK.

Parameters:
key - a PK value or null
Returns:
The entity or null, if no entity matched the PK value

loadByRowId

public T loadByRowId(long rowId)

loadAll

public java.util.List<T> loadAll()
Loads all available entities from the database.


detach

public boolean detach(T entity)
Detaches an entity from the identity scope (session). Subsequent query results won't return this object.


insertInTx

public void insertInTx(java.lang.Iterable<T> entities)
Inserts the given entities in the database using a transaction.

Parameters:
entities - The entities to insert.

insertInTx

public void insertInTx(T... entities)
Inserts the given entities in the database using a transaction.

Parameters:
entities - The entities to insert.

insertInTx

public void insertInTx(java.lang.Iterable<T> entities,
                       boolean setPrimaryKey)
Inserts the given entities in the database using a transaction. The given entities will become tracked if the PK is set.

Parameters:
entities - The entities to insert.
setPrimaryKey - if true, the PKs of the given will be set after the insert; pass false to improve performance.

insert

public long insert(T entity)
Insert an entity into the table associated with a concrete DAO.


insertWithoutSettingPk

public void insertWithoutSettingPk(T entity)
Insert an entity into the table associated with a concrete DAO.


insertOrReplace

public long insertOrReplace(T entity)
Insert an entity into the table associated with a concrete DAO.


queryRaw

public 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

public java.util.List<T> query(java.lang.String selection,
                               java.lang.String[] selectionArgs,
                               java.lang.String groupBy,
                               java.lang.String having,
                               java.lang.String orderby)
Performs a standard Android-style query for entities.


deleteAll

public void deleteAll()

delete

public void delete(T entity)
Deletes the given entity from the database. Currently, only single value PK entities are supported.


deleteByKey

public void deleteByKey(K key)
Deletes an entity with the given PK from the database. Currently, only single value PK entities are supported.


refresh

public void refresh(T entity)
Resets all locally changed properties of the entity by reloading the values from the database.


update

public void update(T entity)

queryBuilder

public QueryBuilder<T> queryBuilder()

updateInTx

public void updateInTx(java.lang.Iterable<T> entities)
Inserts the given entities in the database using a transaction.

Parameters:
entities - The entities to insert.
setPrimaryKey - if true, the PKs of the given will be set after the insert; pass false to improve performance.

count

public long count()


Copyright © 2011-2012 greenrobot.de. All Rights Reserved.