com.j256.ormlite.dao
Class DaoManager

java.lang.Object
  extended by com.j256.ormlite.dao.DaoManager

public class DaoManager
extends Object

Class which caches created DAOs. Sometimes internal DAOs are used to support such features as auto-refreshing of foreign fields or collections of sub-objects. Since instantiation of the DAO is a bit expensive, this class is used in an attempt to only create a DAO once for each class.

NOTE: To use this cache, you should make sure you've added a DatabaseTable.daoClass() value to the annotation to the top of your class.

Author:
graywatson

Constructor Summary
DaoManager()
           
 
Method Summary
static void addCachedDatabaseConfigs(Collection<DatabaseTableConfig<?>> configs)
          This adds database table configurations to the internal cache which can be used to speed up DAO construction.
static void clearCache()
          Clear out all of internal caches.
static void clearDaoCache()
          Clear out our DAO caches.
static
<D extends Dao<T,?>,T>
D
createDao(ConnectionSource connectionSource, Class<T> clazz)
          Helper method to create a DAO object without having to define a class.
static
<D extends Dao<T,?>,T>
D
createDao(ConnectionSource connectionSource, DatabaseTableConfig<T> tableConfig)
          Helper method to create a DAO object without having to define a class.
static
<D extends Dao<T,?>,T>
D
lookupDao(ConnectionSource connectionSource, Class<T> clazz)
          Helper method to lookup a DAO if it has already been associated with the class.
static
<D extends Dao<T,?>,T>
D
lookupDao(ConnectionSource connectionSource, DatabaseTableConfig<T> tableConfig)
          Helper method to lookup a DAO if it has already been associated with the table-config.
static void registerDao(ConnectionSource connectionSource, Dao<?,?> dao)
          Register the DAO with the cache.
static void registerDaoWithTableConfig(ConnectionSource connectionSource, Dao<?,?> dao)
          Same as registerDao(ConnectionSource, Dao) but this allows you to register it just with its DatabaseTableConfig.
static void unregisterDao(ConnectionSource connectionSource, Dao<?,?> dao)
          Remove a DAO from the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DaoManager

public DaoManager()
Method Detail

createDao

public static <D extends Dao<T,?>,T> D createDao(ConnectionSource connectionSource,
                                                 Class<T> clazz)
                                    throws SQLException
Helper method to create a DAO object without having to define a class. This checks to see if the DAO has already been created. If not then it is a call through to BaseDaoImpl.createDao(ConnectionSource, Class).

Throws:
SQLException

lookupDao

public static <D extends Dao<T,?>,T> D lookupDao(ConnectionSource connectionSource,
                                                 Class<T> clazz)
Helper method to lookup a DAO if it has already been associated with the class. Otherwise this returns null.


createDao

public static <D extends Dao<T,?>,T> D createDao(ConnectionSource connectionSource,
                                                 DatabaseTableConfig<T> tableConfig)
                                    throws SQLException
Helper method to create a DAO object without having to define a class. This checks to see if the DAO has already been created. If not then it is a call through to BaseDaoImpl.createDao(ConnectionSource, DatabaseTableConfig).

Throws:
SQLException

lookupDao

public static <D extends Dao<T,?>,T> D lookupDao(ConnectionSource connectionSource,
                                                 DatabaseTableConfig<T> tableConfig)
Helper method to lookup a DAO if it has already been associated with the table-config. Otherwise this returns null.


registerDao

public static void registerDao(ConnectionSource connectionSource,
                               Dao<?,?> dao)
Register the DAO with the cache. This will allow folks to build a DAO externally and then register so it can be used internally as necessary.

NOTE: By default this registers the DAO to be associated with the class that it uses. If you need to register multiple dao's that use different DatabaseTableConfigs then you should use registerDaoWithTableConfig(ConnectionSource, Dao).

NOTE: You should maybe use the DatabaseTable.daoClass() and have the DaoManager construct the DAO if possible.


unregisterDao

public static void unregisterDao(ConnectionSource connectionSource,
                                 Dao<?,?> dao)
Remove a DAO from the cache. This is necessary if we've registered it already but it throws an exception during configuration.


registerDaoWithTableConfig

public static void registerDaoWithTableConfig(ConnectionSource connectionSource,
                                              Dao<?,?> dao)
Same as registerDao(ConnectionSource, Dao) but this allows you to register it just with its DatabaseTableConfig. This allows multiple versions of the DAO to be configured if necessary.


clearCache

public static void clearCache()
Clear out all of internal caches.


clearDaoCache

public static void clearDaoCache()
Clear out our DAO caches.


addCachedDatabaseConfigs

public static void addCachedDatabaseConfigs(Collection<DatabaseTableConfig<?>> configs)
This adds database table configurations to the internal cache which can be used to speed up DAO construction. This is especially true of Android and other mobile platforms.



This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.