de.unikassel.android.sdcframework.persistence
Class AbstractDatabaseCommand<T>

Package class diagram package AbstractDatabaseCommand
java.lang.Object
  extended by de.unikassel.android.sdcframework.persistence.AbstractDatabaseCommand<T>
Type Parameters:
T - the result type of the command
All Implemented Interfaces:
DatabaseCommand<T>
Direct Known Subclasses:
DeleteSamplesCommand, GetMaximumDatabaseSizeCommand, GetRecordCountCommand, InsertSamplesCommand, RemoveSamplesCommand, SetMaximumDatabaseSizeCommand

public abstract class AbstractDatabaseCommand<T>
extends Object
implements DatabaseCommand<T>

Abstract base class for database commands. It does allow homogeneous command execution using a database adapter, as well as a basic handling of open errors and exceptions.

Any extending concrete command class has to implement the abstract protected applyCommand(DatabaseAdapter) method, to implement the concrete command behavior on an open database.


Field Summary
private  int dbOpenRetryCount
          The count of retries if we fail to open the database
static int DEFAULT_DB_OPEN_RETRY_COUNT
          The default value for the count of repeated tries to open the database
private  boolean openReadOnly
          The database open access flag
private  T result
          The command execution result
 
Constructor Summary
AbstractDatabaseCommand(boolean openReadOnly)
          Constructor
AbstractDatabaseCommand(boolean openReadOnly, int dbOpenRetryCount)
          Constructor
 
Method Summary
protected abstract  T applyCommand(DatabaseAdapter dbAdapter)
          Method to apply the basic database command operation.
 boolean execute(DatabaseAdapter dbAdapter)
          Method to execute the command
 int getDbOpenRetryCount()
          Getter for the dbOpenRetryCount
 T getResult()
          Getter for the result
protected  void internalExecute(DatabaseAdapter dbAdapter)
          Internal method to execute the command and store the result
 boolean isOpenReadOnly()
          Getter for the openReadOnly flag
private  void onSQLException(SQLException e)
          SQLException handler
private  boolean openDatabase(DatabaseAdapter dbAdapter)
          Method to open the database
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DB_OPEN_RETRY_COUNT

public static final int DEFAULT_DB_OPEN_RETRY_COUNT
The default value for the count of repeated tries to open the database

See Also:
Constant Field Values

dbOpenRetryCount

private final int dbOpenRetryCount
The count of retries if we fail to open the database


openReadOnly

private final boolean openReadOnly
The database open access flag


result

private T result
The command execution result

Constructor Detail

AbstractDatabaseCommand

public AbstractDatabaseCommand(boolean openReadOnly,
                               int dbOpenRetryCount)
Constructor

Parameters:
openReadOnly - flag if database can be open read only to execute the command
dbOpenRetryCount - retry count for database open command

AbstractDatabaseCommand

public AbstractDatabaseCommand(boolean openReadOnly)
Constructor

Parameters:
openReadOnly - flag if database can be open read only to execute the command
Method Detail

getResult

public final T getResult()
Description copied from interface: DatabaseCommand
Getter for the result

Specified by:
getResult in interface DatabaseCommand<T>
Returns:
the result

getDbOpenRetryCount

public final int getDbOpenRetryCount()
Getter for the dbOpenRetryCount

Returns:
the dbOpenRetryCount

isOpenReadOnly

public final boolean isOpenReadOnly()
Getter for the openReadOnly flag

Returns:
the openReadOnly

internalExecute

protected final void internalExecute(DatabaseAdapter dbAdapter)
                              throws SQLiteFullException
Internal method to execute the command and store the result

Parameters:
dbAdapter - the database adapter to use for execution
Throws:
SQLiteFullException - if command execution fails due to the fact that the database is full

openDatabase

private boolean openDatabase(DatabaseAdapter dbAdapter)
Method to open the database

Parameters:
dbAdapter - the database adapter result success true if successful

execute

public boolean execute(DatabaseAdapter dbAdapter)
                throws SQLiteFullException
Description copied from interface: DatabaseCommand
Method to execute the command

Specified by:
execute in interface DatabaseCommand<T>
Parameters:
dbAdapter - the database adapter to use for execution
Returns:
true if successful, false otherwise
Throws:
SQLiteFullException - if command execution fails due to the fact that the database is full

applyCommand

protected abstract T applyCommand(DatabaseAdapter dbAdapter)
Method to apply the basic database command operation.

Parameters:
dbAdapter - the database adapter to use
Returns:
the command result

onSQLException

private void onSQLException(SQLException e)
SQLException handler

Parameters:
e - the exception