com.octo.android.robospice.persistence.ormlite
Class InDatabaseObjectPersister<T,ID>

java.lang.Object
  extended by com.octo.android.robospice.persistence.ObjectPersister<T>
      extended by com.octo.android.robospice.persistence.ormlite.InDatabaseObjectPersister<T,ID>
All Implemented Interfaces:
CacheCleaner, Persister

public class InDatabaseObjectPersister<T,ID>
extends ObjectPersister<T>


Constructor Summary
InDatabaseObjectPersister(android.app.Application application, RoboSpiceDatabaseHelper databaseHelper, Class<T> modelObjectType)
           
InDatabaseObjectPersister(android.app.Application application, RoboSpiceDatabaseHelper databaseHelper, Class<T> modelObjectType, Map<Class<?>,android.net.Uri> mapHandledClassesToNotificationUri)
           
 
Method Summary
 List<Object> getAllCacheKeys()
           
 long getCreationDateInCache(Object cacheKey)
          Return the creation date of creation of cache. entry for a given cacheKey.
protected  com.j256.ormlite.table.DatabaseTableConfig getDatabaseTableConfig(Class clazz)
           
protected  com.j256.ormlite.field.FieldType getIdField(Class clazz)
           
 boolean isDataInCache(Object cacheKey, long maxTimeInCache)
           
 List<T> loadAllDataFromCache()
           
 T loadDataFromCache(Object cacheKey, long maxTimeInCache)
          Load data from cache if not expired.
 void removeAllDataFromCache()
           
 boolean removeDataFromCache(Object cacheKey)
           
protected
<E> void
saveAllForeignObjectsToCache(E data)
          During this operation, we must save a new POJO (parent) into the database.
 T saveDataToCacheAndReturnData(T data, Object cacheKey)
           
 
Methods inherited from class com.octo.android.robospice.persistence.ObjectPersister
canHandleClass, getApplication, getHandledClass, isAsyncSaveEnabled, setAsyncSaveEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InDatabaseObjectPersister

public InDatabaseObjectPersister(android.app.Application application,
                                 RoboSpiceDatabaseHelper databaseHelper,
                                 Class<T> modelObjectType)
Parameters:
application - the android context needed to access android file system or databases to store.

InDatabaseObjectPersister

public InDatabaseObjectPersister(android.app.Application application,
                                 RoboSpiceDatabaseHelper databaseHelper,
                                 Class<T> modelObjectType,
                                 Map<Class<?>,android.net.Uri> mapHandledClassesToNotificationUri)
Parameters:
application - the android context needed to access android file system or databases to store.
Method Detail

loadDataFromCache

public T loadDataFromCache(Object cacheKey,
                           long maxTimeInCache)
                    throws CacheLoadingException
Description copied from class: ObjectPersister
Load data from cache if not expired.

Specified by:
loadDataFromCache in class ObjectPersister<T>
Parameters:
cacheKey - the cacheKey of the data to load.
maxTimeInCache - the maximum time the data can have been stored in cached before being considered expired. 0 means infinite.
Returns:
the data if it could be loaded.
Throws:
CacheLoadingException - if the data in cache is expired.

saveDataToCacheAndReturnData

public T saveDataToCacheAndReturnData(T data,
                                      Object cacheKey)
                               throws CacheSavingException
Specified by:
saveDataToCacheAndReturnData in class ObjectPersister<T>
Throws:
CacheSavingException

isDataInCache

public boolean isDataInCache(Object cacheKey,
                             long maxTimeInCache)
Specified by:
isDataInCache in class ObjectPersister<T>

getCreationDateInCache

public long getCreationDateInCache(Object cacheKey)
                            throws CacheLoadingException
Description copied from class: ObjectPersister
Return the creation date of creation of cache. entry for a given cacheKey.

Specified by:
getCreationDateInCache in class ObjectPersister<T>
Parameters:
cacheKey - the cachekey identifying the object to look for.
Returns:
a long corresponding to the creation date of creation of cache.
Throws:
CacheLoadingException - if there is no such element in cache.

saveAllForeignObjectsToCache

protected <E> void saveAllForeignObjectsToCache(E data)
                                     throws SQLException,
                                            IllegalAccessException,
                                            InvocationTargetException
During this operation, we must save a new POJO (parent) into the database. The problem is that is the POJO contains children POJOs, then saving the parent would not work as the parent must exist in the database prior to saving the children. SO :

Parameters:
data - the parent POJO to save in the database.
Throws:
SQLException
IllegalArgumentException
IllegalAccessException
InvocationTargetException

removeDataFromCache

public boolean removeDataFromCache(Object cacheKey)
Specified by:
removeDataFromCache in class ObjectPersister<T>

removeAllDataFromCache

public void removeAllDataFromCache()
Specified by:
removeAllDataFromCache in interface CacheCleaner
Specified by:
removeAllDataFromCache in class ObjectPersister<T>

loadAllDataFromCache

public List<T> loadAllDataFromCache()
                             throws CacheLoadingException
Specified by:
loadAllDataFromCache in class ObjectPersister<T>
Throws:
CacheLoadingException

getAllCacheKeys

public List<Object> getAllCacheKeys()
Specified by:
getAllCacheKeys in class ObjectPersister<T>

getIdField

protected com.j256.ormlite.field.FieldType getIdField(Class clazz)
                                               throws SQLException
Throws:
SQLException

getDatabaseTableConfig

protected com.j256.ormlite.table.DatabaseTableConfig getDatabaseTableConfig(Class clazz)
                                                                     throws SQLException
Throws:
SQLException


Copyright © 2012-2014. All Rights Reserved.