|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.unikassel.android.sdcframework.persistence.DatabaseAdapterImpl
public final class DatabaseAdapterImpl
The database adapter class does wrap the direct Android database access.
Nested Class Summary | |
---|---|
private static class |
DatabaseAdapterImpl.DatabaseHelper
The internal SQLite helper class |
Field Summary | |
---|---|
private SQLiteDatabase |
db
The database |
private static String |
DB_CREATE_INDEX1
The first index creation statements |
private static String |
DB_CREATE_INDEX2
The first index creation statements |
private static String |
DB_CREATE_TABLE
The table creation statement |
static String |
DB_INDEX1
The first index name |
static String |
DB_INDEX2
The second index name |
static String |
DB_TABLE
The table name |
private static String |
DB_UPDATE_1
The first table update statement statement |
private static String |
DB_UPDATE_2
The first table update statement statement |
private static int |
DB_VERSION
The database version |
private DatabaseAdapterImpl.DatabaseHelper |
dbHelper
The SQLite helper |
private static String |
KEY_DATA
The data column name |
private static String |
KEY_DATA_CLASS
The data type class name |
private static String |
KEY_LOCATION
The location column name |
private static String |
KEY_PRIO
The priority column name |
private static String |
KEY_ROWID
The row identifier column name |
private static String |
KEY_SENSORID
The sensor identifier column name |
private static String |
KEY_SYNCED
The time stamp sync state column |
private static String |
KEY_TIMESTAMP
The sensor identifier column name |
private static long |
MAX_NUM_PLACEHOLDERS
There's a limit in maximum number of placeholders in compiled SQL statement |
private static String |
ORDER_BY_ASC_PRIO_TS
The order by time ascending priority and stamp statement ( ascending time stamp order, highest priority first ) |
private static String |
ORDER_BY_DESC_PRIO_TS
The order by time descending priority and stamp statement ( ascending time stamp order, lowest priority first ) |
private static String |
ORDER_BY_TS
The order by time stamp statement ( oldest time stamps first ) |
Constructor Summary | |
---|---|
DatabaseAdapterImpl(String dbName,
Context applicationContext)
Constructor |
|
DatabaseAdapterImpl(String dbName,
long maxDBSize,
Context applicationContext)
Constructor |
Method Summary | |
---|---|
void |
close()
Method to close the database |
boolean |
deleteAll()
Method to delete all stored records at once |
private long |
deleteSamples(Set<Long> rowIds)
Method to delete a set of samples from the database |
long |
deleteSamplesOrdered(long count,
boolean deleteLowestPriorityFirst)
Method to delete a given count of the oldest samples. |
private long |
deleteSamplesOrdered(long count,
String orderByStatement)
Method to delete a given count of records using the given order by statement |
long |
getMaximumDatabaseSize()
Getter for the maximum database size |
long |
getPageSize()
Getter for the current database page size in bytes |
long |
getRecordCount()
Method to get the current record count |
private Cursor |
getSamplesOrdered(long limit,
String orderByStatement)
Getter for samples ordered by the given statement |
private long |
insertSample(DatabaseSample sample)
Method to insert a sample into the database |
void |
insertSamples(Collection<DatabaseSample> samples)
Method to insert a sample collection into the database |
DatabaseAdapter |
open()
Method to open the database for write access |
DatabaseAdapter |
openForRead()
Method to open the database for read access |
private boolean |
removeSamples(long count,
Collection<DatabaseSample> sampleCollection,
String orderByStatement)
Method to remove the next "count" samples selected ordered by priority and time stamp from the database and stored in a given sample collection. |
boolean |
removeSamplesHighestPrioFirst(long count,
Collection<DatabaseSample> sampleCollection)
Method to remove the next "count" samples which will be selected ordered by ascending priority and ascending time stamp from the database and stored in a given sample collection. |
boolean |
removeSamplesLowestPrioFirst(long count,
Collection<DatabaseSample> sampleCollection)
Method to remove the next "count" samples which will be selected ordered by descending priority and ascending time stamps from the database and stored in a given sample collection. |
boolean |
removeSamplesOldestTimeStampFirst(long count,
Collection<DatabaseSample> sampleCollection)
Method to remove the next "count" samples which will be selected ordered by ascending time stamps from the database and stored in a given sample collection. |
private DatabaseSample |
sampleFromCursor(Cursor cursor)
Does create a sample from cursor position |
long |
setMaximumDatabaseSize(long size)
Setter for the maximum database size |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long MAX_NUM_PLACEHOLDERS
private static final String KEY_ROWID
private static final String KEY_SENSORID
private static final String KEY_TIMESTAMP
private static final String KEY_PRIO
private static final String KEY_SYNCED
private static final String KEY_DATA
private static final String KEY_DATA_CLASS
private static final String KEY_LOCATION
private static final String ORDER_BY_TS
private static final String ORDER_BY_ASC_PRIO_TS
private static final String ORDER_BY_DESC_PRIO_TS
public static final String DB_TABLE
public static final String DB_INDEX1
public static final String DB_INDEX2
private static final int DB_VERSION
private static final String DB_CREATE_TABLE
private static final String DB_CREATE_INDEX1
private static final String DB_CREATE_INDEX2
private static final String DB_UPDATE_1
private static final String DB_UPDATE_2
private final DatabaseAdapterImpl.DatabaseHelper dbHelper
private SQLiteDatabase db
Constructor Detail |
---|
public DatabaseAdapterImpl(String dbName, Context applicationContext)
dbName
- the database nameapplicationContext
- the application contextpublic DatabaseAdapterImpl(String dbName, long maxDBSize, Context applicationContext)
dbName
- the database namemaxDBSize
- the maximum databse sizeapplicationContext
- the application contextMethod Detail |
---|
public final DatabaseAdapter open() throws SQLiteException
DatabaseAdapter
open
in interface DatabaseAdapter
SQLiteException
- if unable to open the databasepublic final DatabaseAdapter openForRead() throws SQLiteException
DatabaseAdapter
openForRead
in interface DatabaseAdapter
SQLiteException
- if unable to open the databasepublic final void close()
DatabaseAdapter
close
in interface DatabaseAdapter
private final long insertSample(DatabaseSample sample) throws SQLException
sample
- the sample to insert
SQLException
public final void insertSamples(Collection<DatabaseSample> samples) throws Exception
DatabaseAdapter
insertSamples
in interface DatabaseAdapter
samples
- the sample collection to insert
Exception
private final long deleteSamples(Set<Long> rowIds)
rowIds
- a set with unique row identifiers from database to delete
public final boolean deleteAll()
public final long getRecordCount()
DatabaseAdapter
getRecordCount
in interface DatabaseAdapter
private final Cursor getSamplesOrdered(long limit, String orderByStatement)
limit
- the count of rows to retrieveorderByStatement
- the order by statement
private final DatabaseSample sampleFromCursor(Cursor cursor)
cursor
- the database cursor
private final boolean removeSamples(long count, Collection<DatabaseSample> sampleCollection, String orderByStatement)
count
- the sample count to removesampleCollection
- the sample collection to store removed samples inorderByStatement
- the order by statement to use for the query
private final long deleteSamplesOrdered(long count, String orderByStatement)
count
- the count of records to deleteorderByStatement
- the order by statement
public final long deleteSamplesOrdered(long count, boolean deleteLowestPriorityFirst)
DatabaseAdapter
deleteSamplesOrdered
in interface DatabaseAdapter
count
- the count of records to deletedeleteLowestPriorityFirst
- if true the sample for deletion will be selected first by lowest
priority, second oldest time stamp
public final boolean removeSamplesHighestPrioFirst(long count, Collection<DatabaseSample> sampleCollection)
DatabaseAdapter
removeSamplesHighestPrioFirst
in interface DatabaseAdapter
count
- the sample count to removesampleCollection
- the sample collection to store removed samples in
public final boolean removeSamplesLowestPrioFirst(long count, Collection<DatabaseSample> sampleCollection)
DatabaseAdapter
removeSamplesLowestPrioFirst
in interface DatabaseAdapter
count
- the sample count to removesampleCollection
- the sample collection to store removed samples in
public final boolean removeSamplesOldestTimeStampFirst(long count, Collection<DatabaseSample> sampleCollection)
DatabaseAdapter
removeSamplesOldestTimeStampFirst
in interface DatabaseAdapter
count
- the sample count to removesampleCollection
- the sample collection to store removed samples in
public final long setMaximumDatabaseSize(long size)
DatabaseAdapter
setMaximumDatabaseSize
in interface DatabaseAdapter
size
- the maximum database size
public final long getMaximumDatabaseSize()
DatabaseAdapter
getMaximumDatabaseSize
in interface DatabaseAdapter
public final long getPageSize()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |