de.greenrobot.dao
Class AbstractDao<T,K>

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

public abstract class AbstractDao<T,K>
extends java.lang.Object

Base class for all DAOs: Implements entity operations like insert, load, delete, and query. This class is thread-safe.


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.
 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()
           
 SQLiteDatabase getDatabase()
          Gets the SQLiteDatabase for custom database access.
 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.
 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)
          Deprecated. groupBy & having does not make sense for entities. Method will be removed.
 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)
          Updates the given entities in the database using a transaction.
 void updateInTx(T... entities)
          Updates 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.

insertOrReplaceInTx

public void insertOrReplaceInTx(java.lang.Iterable<T> entities,
                                boolean setPrimaryKey)
Inserts or replaces 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.

insertOrReplaceInTx

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

Parameters:
entities - The entities to insert.

insertOrReplaceInTx

public void insertOrReplaceInTx(T... entities)
Inserts or replaces the given entities in the database using a transaction.

Parameters:
entities - The entities to insert.

insert

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

Returns:
row ID of newly inserted entity

insertWithoutSettingPk

public long insertWithoutSettingPk(T entity)
Insert an entity into the table associated with a concrete DAO without setting key property. Warning: This may be faster, but the entity should not be used anymore. The entity also won't be attached to identy scope.

Returns:
row ID of newly inserted entity

insertOrReplace

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

Returns:
row ID of newly inserted entity

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)
Deprecated. groupBy & having does not make sense for entities. Method will be removed.


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.


deleteInTx

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

Parameters:
entities - The entities to delete.

deleteInTx

public void deleteInTx(T... entities)
Deletes the given entities in the database using a transaction.

Parameters:
entities - The entities to delete.

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)
Updates the given entities in the database using a transaction.

Parameters:
entities - The entities to insert.

updateInTx

public void updateInTx(T... entities)
Updates the given entities in the database using a transaction.

Parameters:
entities - The entities to update.

count

public long count()

getDatabase

public SQLiteDatabase getDatabase()
Gets the SQLiteDatabase for custom database access. Not needed for greenDAO entities.



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