Class AbstractDaoSession


  • public class AbstractDaoSession
    extends java.lang.Object
    DaoSession 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 Detail

      • AbstractDaoSession

        public AbstractDaoSession​(Database db)
    • Method Detail

      • registerDao

        protected <T> void registerDao​(java.lang.Class<T> entityClass,
                                       AbstractDao<T,​?> dao)
      • deleteAll

        public <T> void deleteAll​(java.lang.Class<T> entityClass)
        Convenient call for AbstractDao.deleteAll().
      • load

        public <T,​K> T load​(java.lang.Class<T> entityClass,
                                  K key)
        Convenient call for AbstractDao.load(Object).
      • loadAll

        public <T,​K> java.util.List<T> loadAll​(java.lang.Class<T> entityClass)
        Convenient call for AbstractDao.loadAll().
      • queryRaw

        public <T,​K> java.util.List<T> queryRaw​(java.lang.Class<T> entityClass,
                                                      java.lang.String where,
                                                      java.lang.String... selectionArgs)
      • 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.Exception
        Calls 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)
        Like callInTx(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).