de.unikassel.android.sdcframework.persistence
Class PersistentStorageManagerImpl

Package class diagram package PersistentStorageManagerImpl
java.lang.Object
  extended by java.lang.Thread
      extended by de.unikassel.android.sdcframework.util.AbstractWorkerThread
          extended by de.unikassel.android.sdcframework.util.AbstractAsynchrounousSampleObserver
              extended by de.unikassel.android.sdcframework.persistence.PersistentStorageManagerImpl
All Implemented Interfaces:
DatabaseManager, PersistentStorageManager, AsynchrounousSampleObserver, DelegatingSampleObserver, LifeCycleObject, WorkerThread, Runnable

public final class PersistentStorageManagerImpl
extends AbstractAsynchrounousSampleObserver
implements PersistentStorageManager

The persistent storage manager does provide the persistent storage feature for the framework.

It does extend the AbstractAsynchrounousSampleObserver to cache observed samples for further asynchronous processing.

See Also:
ServiceManagerImpl

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  InsertSamplesCommand currentCommand
          The last not finished database command
private  DatabaseFullStrategy dbFullStrategy
          The strategy to use in case of SQLiteFullException
private  DatabaseManager dbManager
          The database manager used for database access
private  AtomicLong savedRecordCount
          The actual count of records stored to database in the actual work period
private  Class<? extends SDCService> serviceClass
          The service class
 
Fields inherited from class de.unikassel.android.sdcframework.util.AbstractAsynchrounousSampleObserver
collector
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
PersistentStorageManagerImpl(Context applicationContext, ServiceConfiguration config, DatabaseManager dbManager, Class<? extends SDCService> serviceClass, Class<? extends Activity> controlActivityClass)
          Constructor
 
Method Summary
private  Collection<DatabaseSample> convertSamplesToDBSamples(SampleCollection samples)
          Conversion of samples to database samples
 long doDeleteOldestSamplesInDatabase(long count, boolean lowestPriorityFirst)
          Method to delete the oldest "count" samples in the database
This method is used to delete samples for deletion in case of database size maximum reached.
<T> T
doExecuteCommand(DatabaseCommand<T> command)
          Does execute a database command
 boolean doExecuteCurrentCommand()
          Does execute the current outstanding database command
private  void doHandleDatabaseSizeLimitExceeded()
          Handler for the SQL database full exception
protected  void doWork()
          The working method executed in the running loop if started
 long getMaximumDatabaseSize()
          Getter for the maximum database size in kilobytes
 long getRecordCountInDatabase()
          Getter for the current sample record count stored in database
 long getSavedRecordCount()
          Getter for the savedRecordCount
 void onPause(Context applicationContext)
          Pause method
 void onResume(Context applicationContext)
          Resume method
 long setMaximumDatabaseSize(long size)
          Setter for the maximum database size in kilobytes
 void updateDatabaseFullStrategy(Context context, ServiceConfiguration config, Class<? extends Activity> controlActivityClass)
          Method to update internal database full strategy chain by configuration of the service
 
Methods inherited from class de.unikassel.android.sdcframework.util.AbstractAsynchrounousSampleObserver
doCleanUp, getObserver, onCreate, onDestroy
 
Methods inherited from class de.unikassel.android.sdcframework.util.AbstractWorkerThread
doTerminate, hasTerminated, isLogging, isWorking, logMessage, run, setLogging, start, startWork, stopWork
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.unikassel.android.sdcframework.util.facade.WorkerThread
doTerminate, hasTerminated, isLogging, isWorking, setLogging, startWork, stopWork
 
Methods inherited from interface de.unikassel.android.sdcframework.util.facade.LifeCycleObject
onCreate, onDestroy
 
Methods inherited from interface de.unikassel.android.sdcframework.util.facade.DelegatingSampleObserver
getObserver
 

Field Detail

savedRecordCount

private final AtomicLong savedRecordCount
The actual count of records stored to database in the actual work period


dbManager

private final DatabaseManager dbManager
The database manager used for database access


dbFullStrategy

private DatabaseFullStrategy dbFullStrategy
The strategy to use in case of SQLiteFullException


currentCommand

private InsertSamplesCommand currentCommand
The last not finished database command


serviceClass

private final Class<? extends SDCService> serviceClass
The service class

Constructor Detail

PersistentStorageManagerImpl

public PersistentStorageManagerImpl(Context applicationContext,
                                    ServiceConfiguration config,
                                    DatabaseManager dbManager,
                                    Class<? extends SDCService> serviceClass,
                                    Class<? extends Activity> controlActivityClass)
Constructor

Parameters:
applicationContext - the application context
config - the service configuration
dbManager - the database manager to use
serviceClass - the service class
controlActivityClass - the control activity class or null
Method Detail

updateDatabaseFullStrategy

public final void updateDatabaseFullStrategy(Context context,
                                             ServiceConfiguration config,
                                             Class<? extends Activity> controlActivityClass)
Description copied from interface: PersistentStorageManager
Method to update internal database full strategy chain by configuration of the service

Specified by:
updateDatabaseFullStrategy in interface PersistentStorageManager
Parameters:
context - the application context
config - the current service configuration to update from
controlActivityClass - the control activity class or null

doWork

protected final void doWork()
Description copied from class: AbstractWorkerThread
The working method executed in the running loop if started

Specified by:
doWork in class AbstractWorkerThread

convertSamplesToDBSamples

private final Collection<DatabaseSample> convertSamplesToDBSamples(SampleCollection samples)
Conversion of samples to database samples

Parameters:
samples - the sample collection to convert to a database sample collection
Returns:
a collection of the converted samples

doExecuteCurrentCommand

public final boolean doExecuteCurrentCommand()
Description copied from interface: PersistentStorageManager
Does execute the current outstanding database command

Specified by:
doExecuteCurrentCommand in interface PersistentStorageManager
Returns:
true if successful, false otherwise

doDeleteOldestSamplesInDatabase

public final long doDeleteOldestSamplesInDatabase(long count,
                                                  boolean lowestPriorityFirst)
Description copied from interface: DatabaseManager
Method to delete the oldest "count" samples in the database
This method is used to delete samples for deletion in case of database size maximum reached.
Depending on the flag lowestPriorityFirst the oldest samples will be selected priority independent or not.

Specified by:
doDeleteOldestSamplesInDatabase in interface DatabaseManager
Parameters:
count - the sample count to delete in database
lowestPriorityFirst - if true the samples will be selected ordered by priority and time stamp, otherwise just by time stamp
Returns:
the count of samples deleted in database

doHandleDatabaseSizeLimitExceeded

private final void doHandleDatabaseSizeLimitExceeded()
Handler for the SQL database full exception


onResume

public final void onResume(Context applicationContext)
Description copied from interface: LifeCycleObject
Resume method

Specified by:
onResume in interface LifeCycleObject
Overrides:
onResume in class AbstractAsynchrounousSampleObserver
Parameters:
applicationContext - the application context

onPause

public final void onPause(Context applicationContext)
Description copied from interface: LifeCycleObject
Pause method

Specified by:
onPause in interface LifeCycleObject
Overrides:
onPause in class AbstractAsynchrounousSampleObserver
Parameters:
applicationContext - the application context

getSavedRecordCount

public final long getSavedRecordCount()
Description copied from interface: PersistentStorageManager
Getter for the savedRecordCount

Specified by:
getSavedRecordCount in interface PersistentStorageManager
Returns:
the savedRecordCount

getRecordCountInDatabase

public final long getRecordCountInDatabase()
Description copied from interface: DatabaseManager
Getter for the current sample record count stored in database

Specified by:
getRecordCountInDatabase in interface DatabaseManager
Returns:
the current sample record count in the database

getMaximumDatabaseSize

public final long getMaximumDatabaseSize()
Description copied from interface: DatabaseManager
Getter for the maximum database size in kilobytes

Specified by:
getMaximumDatabaseSize in interface DatabaseManager
Returns:
the new maximum database size

setMaximumDatabaseSize

public final long setMaximumDatabaseSize(long size)
Description copied from interface: DatabaseManager
Setter for the maximum database size in kilobytes

Specified by:
setMaximumDatabaseSize in interface DatabaseManager
Parameters:
size - the maximum database size
Returns:
the new maximum database size

doExecuteCommand

public <T> T doExecuteCommand(DatabaseCommand<T> command)
Description copied from interface: DatabaseManager
Does execute a database command

Specified by:
doExecuteCommand in interface DatabaseManager
Type Parameters:
T - the result type of the command
Parameters:
command - the command to execute
Returns:
true if successful, false if a database full exception occurred