com.todoroo.andlib.data
Class AbstractDatabase

java.lang.Object
  extended by com.todoroo.andlib.data.AbstractDatabase

public abstract class AbstractDatabase
extends java.lang.Object

AbstractDatabase is a database abstraction which wraps a SQLite database.

Users of this class are in charge of the database's lifecycle - ensuring that the database is open when needed and closed when usage is finished. Within an activity, this is typically accomplished through the onResume and onPause methods, though if the database is not needed for the activity's entire lifecycle, it can be closed earlier.

Direct querying is not recommended for type safety reasons. Instead, use one of the service classes to issue the request and return a TodorooCursor.

Author:
Tim Su

Nested Class Summary
static interface AbstractDatabase.DatabaseUpdateListener
          Interface for responding to database changes
static class AbstractDatabase.SqlConstructorVisitor
          Visitor that returns SQL constructor for this property
 
Constructor Summary
AbstractDatabase()
           
 
Method Summary
 void addListener(AbstractDatabase.DatabaseUpdateListener listener)
           
 void clear()
          Clear all data in database.
 void close()
          Close the database if it has been opened previously
 int delete(java.lang.String table, java.lang.String whereClause, java.lang.String[] whereArgs)
           
 android.database.sqlite.SQLiteDatabase getDatabase()
           
 Table getTable(java.lang.Class<? extends AbstractModel> modelType)
          Return the name of the table containing these models
 long insert(java.lang.String table, java.lang.String nullColumnHack, android.content.ContentValues values)
           
 void openForReading()
          Open the database for reading.
 void openForWriting()
          Open the database for writing.
 android.database.Cursor rawQuery(java.lang.String sql, java.lang.String[] selectionArgs)
           
 java.lang.String toString()
           
 int update(java.lang.String table, android.content.ContentValues values, java.lang.String whereClause, java.lang.String[] whereArgs)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractDatabase

public AbstractDatabase()
Method Detail

addListener

public void addListener(AbstractDatabase.DatabaseUpdateListener listener)

getTable

public final Table getTable(java.lang.Class<? extends AbstractModel> modelType)
Return the name of the table containing these models

Parameters:
modelType -
Returns:

openForWriting

public final void openForWriting()
Open the database for writing. Must be closed afterwards. If user is out of disk space, database may be opened for reading instead


openForReading

public final void openForReading()
Open the database for reading. Must be closed afterwards


close

public final void close()
Close the database if it has been opened previously


clear

public final void clear()
Clear all data in database. Warning: this does what it says. Any open database resources will be abruptly closed.


getDatabase

public final android.database.sqlite.SQLiteDatabase getDatabase()
Returns:
sql database. opens database if not yet open

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
human-readable database name for debugging

rawQuery

public android.database.Cursor rawQuery(java.lang.String sql,
                                        java.lang.String[] selectionArgs)

insert

public long insert(java.lang.String table,
                   java.lang.String nullColumnHack,
                   android.content.ContentValues values)

delete

public int delete(java.lang.String table,
                  java.lang.String whereClause,
                  java.lang.String[] whereArgs)

update

public int update(java.lang.String table,
                  android.content.ContentValues values,
                  java.lang.String whereClause,
                  java.lang.String[] whereArgs)