Package org.greenrobot.greendao
Class AbstractDaoSession
- java.lang.Object
-
- org.greenrobot.greendao.AbstractDaoSession
-
public class AbstractDaoSession extends java.lang.ObjectDaoSession gives you access to your DAOs, offers convenient persistence methods, and also serves as a session cache.
To access the DAOs, call the get{entity}Dao methods by the generated DaoSession sub class.
DaoSession offers many of the available persistence operations on entities as a convenience. Consider using DAOs directly to access all available operations, especially if you call a lot of operations on a single entity type to avoid the overhead imposed by DaoSession (the overhead is small, but it may add up).
By default, the DaoSession has a session cache (IdentityScopeType.Session). The session cache is not just a plain data cache to improve performance, but also manages object identities. For example, if you load the same entity twice in a query, you will get a single Java object instead of two when using a session cache. This is particular useful for relations pointing to a common set of entities. This class is thread-safe.
-
-
Constructor Summary
Constructors Constructor Description AbstractDaoSession(Database db)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <V> VcallInTx(java.util.concurrent.Callable<V> callable)Calls the given Callable inside a database transaction and returns the result of the Callable.<V> VcallInTxNoException(java.util.concurrent.Callable<V> callable)LikecallInTx(Callable)but does not require Exception handling (rethrows an Exception as a runtime DaoException).<T> voiddelete(T entity)Convenient call forAbstractDao.delete(Object).<T> voiddeleteAll(java.lang.Class<T> entityClass)Convenient call forAbstractDao.deleteAll().java.util.Collection<AbstractDao<?,?>>getAllDaos()Allows to inspect the meta model using DAOs (e.g.AbstractDao<?,?>getDao(java.lang.Class<? extends java.lang.Object> entityClass)DatabasegetDatabase()Gets the Database for custom database access.<T> longinsert(T entity)Convenient call forAbstractDao.insert(Object).<T> longinsertOrReplace(T entity)Convenient call forAbstractDao.insertOrReplace(Object).<T,K>
Tload(java.lang.Class<T> entityClass, K key)Convenient call forAbstractDao.load(Object).<T,K>
java.util.List<T>loadAll(java.lang.Class<T> entityClass)Convenient call forAbstractDao.loadAll().<T> QueryBuilder<T>queryBuilder(java.lang.Class<T> entityClass)Convenient call forAbstractDao.queryBuilder().<T,K>
java.util.List<T>queryRaw(java.lang.Class<T> entityClass, java.lang.String where, java.lang.String... selectionArgs)Convenient call forAbstractDao.queryRaw(String, String...).<T> voidrefresh(T entity)Convenient call forAbstractDao.refresh(Object).protected <T> voidregisterDao(java.lang.Class<T> entityClass, AbstractDao<T,?> dao)voidrunInTx(java.lang.Runnable runnable)Run the given Runnable inside a database transaction.RxTransactionrxTx()The returnedRxTransactionallows DB transactions using Rx Observables using RX's IO scheduler for subscribeOn.RxTransactionrxTxPlain()The returnedRxTransactionallows DB transactions using Rx Observables without any Scheduler set for subscribeOn.AsyncSessionstartAsyncSession()Creates a newAsyncSessionto issue asynchronous entity operations.<T> voidupdate(T entity)Convenient call forAbstractDao.update(Object).
-
-
-
Constructor Detail
-
AbstractDaoSession
public AbstractDaoSession(Database db)
-
-
Method Detail
-
registerDao
protected <T> void registerDao(java.lang.Class<T> entityClass, AbstractDao<T,?> dao)
-
insert
public <T> long insert(T entity)
Convenient call forAbstractDao.insert(Object).
-
insertOrReplace
public <T> long insertOrReplace(T entity)
Convenient call forAbstractDao.insertOrReplace(Object).
-
refresh
public <T> void refresh(T entity)
Convenient call forAbstractDao.refresh(Object).
-
update
public <T> void update(T entity)
Convenient call forAbstractDao.update(Object).
-
delete
public <T> void delete(T entity)
Convenient call forAbstractDao.delete(Object).
-
deleteAll
public <T> void deleteAll(java.lang.Class<T> entityClass)
Convenient call forAbstractDao.deleteAll().
-
load
public <T,K> T load(java.lang.Class<T> entityClass, K key)Convenient call forAbstractDao.load(Object).
-
loadAll
public <T,K> java.util.List<T> loadAll(java.lang.Class<T> entityClass)
Convenient call forAbstractDao.loadAll().
-
queryRaw
public <T,K> java.util.List<T> queryRaw(java.lang.Class<T> entityClass, java.lang.String where, java.lang.String... selectionArgs)Convenient call forAbstractDao.queryRaw(String, String...).
-
queryBuilder
public <T> QueryBuilder<T> queryBuilder(java.lang.Class<T> entityClass)
Convenient call forAbstractDao.queryBuilder().
-
getDao
public AbstractDao<?,?> getDao(java.lang.Class<? extends java.lang.Object> entityClass)
-
runInTx
public void runInTx(java.lang.Runnable runnable)
Run the given Runnable inside a database transaction. If you except a result, consider callInTx.
-
callInTx
public <V> V callInTx(java.util.concurrent.Callable<V> callable) throws java.lang.ExceptionCalls the given Callable inside a database transaction and returns the result of the Callable. If you don't except a result, consider runInTx.- Throws:
java.lang.Exception
-
callInTxNoException
public <V> V callInTxNoException(java.util.concurrent.Callable<V> callable)
LikecallInTx(Callable)but does not require Exception handling (rethrows an Exception as a runtime DaoException).
-
getDatabase
public Database getDatabase()
Gets the Database for custom database access. Not needed for greenDAO entities.
-
getAllDaos
public java.util.Collection<AbstractDao<?,?>> getAllDaos()
Allows to inspect the meta model using DAOs (e.g. querying table names or properties).
-
startAsyncSession
public AsyncSession startAsyncSession()
Creates a newAsyncSessionto issue asynchronous entity operations. SeeAsyncSessionfor details.
-
rxTxPlain
@Experimental public RxTransaction rxTxPlain()
The returnedRxTransactionallows DB transactions using Rx Observables without any Scheduler set for subscribeOn.- See Also:
rxTx()
-
rxTx
@Experimental public RxTransaction rxTx()
The returnedRxTransactionallows DB transactions using Rx Observables using RX's IO scheduler for subscribeOn.- See Also:
rxTxPlain()
-
-