com.octo.android.robospice.persistence
Class ObjectPersister<T>

java.lang.Object
  extended by com.octo.android.robospice.persistence.ObjectPersister<T>
Type Parameters:
T - the class of the objects this ObjectPersister can persist/unpersist.
All Implemented Interfaces:
CacheCleaner, Persister
Direct Known Subclasses:
InDatabaseObjectPersister, InFileObjectPersister, LruCacheObjectPersister

public abstract class ObjectPersister<T>
extends Object
implements Persister, CacheCleaner

Super class of all entities responsible for loading/saving objects of a given class in the cache.

Author:
sni

Constructor Summary
ObjectPersister(android.app.Application application, Class<T> clazz)
           
 
Method Summary
 boolean canHandleClass(Class<?> clazz)
          Whether or not this bus element can persist/unpersist objects of the given class clazz.
abstract  List<Object> getAllCacheKeys()
           
 android.app.Application getApplication()
           
abstract  long getCreationDateInCache(Object cacheKey)
          Return the creation date of creation of cache. entry for a given cacheKey.
 Class<T> getHandledClass()
           
 boolean isAsyncSaveEnabled()
           
abstract  boolean isDataInCache(Object cacheKey, long maxTimeInCacheBeforeExpiry)
           
abstract  List<T> loadAllDataFromCache()
           
abstract  T loadDataFromCache(Object cacheKey, long maxTimeInCache)
          Load data from cache if not expired.
abstract  void removeAllDataFromCache()
           
abstract  boolean removeDataFromCache(Object cacheKey)
           
abstract  T saveDataToCacheAndReturnData(T data, Object cacheKey)
           
 void setAsyncSaveEnabled(boolean isAsyncSaveEnabled)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectPersister

public ObjectPersister(android.app.Application application,
                       Class<T> clazz)
Method Detail

getApplication

public android.app.Application getApplication()

getHandledClass

public Class<T> getHandledClass()

canHandleClass

public boolean canHandleClass(Class<?> clazz)
Description copied from interface: Persister
Whether or not this bus element can persist/unpersist objects of the given class clazz.

Specified by:
canHandleClass in interface Persister
Parameters:
clazz - the class of objets we are looking forward to persist.
Returns:
true if this bus element can persist/unpersist objects of the given class clazz. False otherwise.

loadDataFromCache

public abstract T loadDataFromCache(Object cacheKey,
                                    long maxTimeInCache)
                             throws CacheLoadingException
Load data from cache if not expired.

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.

loadAllDataFromCache

public abstract List<T> loadAllDataFromCache()
                                      throws CacheLoadingException
Throws:
CacheLoadingException

getAllCacheKeys

public abstract List<Object> getAllCacheKeys()

saveDataToCacheAndReturnData

public abstract T saveDataToCacheAndReturnData(T data,
                                               Object cacheKey)
                                        throws CacheSavingException
Throws:
CacheSavingException

removeDataFromCache

public abstract boolean removeDataFromCache(Object cacheKey)

removeAllDataFromCache

public abstract void removeAllDataFromCache()
Specified by:
removeAllDataFromCache in interface CacheCleaner

getCreationDateInCache

public abstract long getCreationDateInCache(Object cacheKey)
                                     throws CacheLoadingException
Return the creation date of creation of cache. entry for a given cacheKey.

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.

isAsyncSaveEnabled

public boolean isAsyncSaveEnabled()

setAsyncSaveEnabled

public void setAsyncSaveEnabled(boolean isAsyncSaveEnabled)

isDataInCache

public abstract boolean isDataInCache(Object cacheKey,
                                      long maxTimeInCacheBeforeExpiry)


Copyright © 2012-2014. All Rights Reserved.