public class SqlCipherDatabaseHelper extends co.touchlab.squeaky.db.sqlcipher.SqueakyOpenHelper implements AppDatabase
AppDatabase
that uses SqlCipher for encryption and
only has tables for saving TaskResults and StepResults. You can extend this class and override
onCreate and onUpgrade to add your own tables to those provided by this implementation.
Uses Squeaky, a simple ORM, which uses annotation processing on the model classes to create the tables and add methods for database operations. If you create a subclass of this database class and add more models, you will need to add the annotation processor to your app's build.gradle file: (See the Sample App for details, but add `apt 'co.touchlab.squeaky:squeaky-processor:0.4.0'` to your dependencies and add android-apt: https://bitbucket.org/hvisser/android-apt)
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_NAME |
static int |
DEFAULT_VERSION |
Constructor and Description |
---|
SqlCipherDatabaseHelper(android.content.Context context,
java.lang.String name,
net.sqlcipher.database.SQLiteDatabase.CursorFactory factory,
int version,
UpdatablePassphraseProvider passphraseProvider) |
Modifier and Type | Method and Description |
---|---|
<D extends co.touchlab.squeaky.dao.Dao<T>,T> |
getDao(java.lang.Class<T> clazz) |
TaskResult |
loadLatestTaskResult(java.lang.String taskIdentifier)
Loads the latest task result for the given task identifier.
|
java.util.List<StepResult> |
loadStepResults(java.lang.String stepIdentifier)
Returns a list of all StepResults for the given step identifier.
|
java.util.List<TaskResult> |
loadTaskResults(java.lang.String taskIdentifier)
Returns a list of all TaskResults for the given task identifier.
|
void |
onCreate(net.sqlcipher.database.SQLiteDatabase sqLiteDatabase) |
void |
onUpgrade(net.sqlcipher.database.SQLiteDatabase sqLiteDatabase,
int i,
int i1) |
void |
saveTaskResult(TaskResult taskResult)
Saves the TaskResult to the database, along with its child StepResults
|
void |
setEncryptionKey(java.lang.String key)
Sets the encryption key on the database.
|
close, getGeneratedTableMapper, getSqueakyContext, getWrappedDatabase
public static final java.lang.String DEFAULT_NAME
public static final int DEFAULT_VERSION
public SqlCipherDatabaseHelper(android.content.Context context, java.lang.String name, net.sqlcipher.database.SQLiteDatabase.CursorFactory factory, int version, UpdatablePassphraseProvider passphraseProvider)
public void onCreate(net.sqlcipher.database.SQLiteDatabase sqLiteDatabase)
onCreate
in class net.sqlcipher.database.SQLiteOpenHelper
public void onUpgrade(net.sqlcipher.database.SQLiteDatabase sqLiteDatabase, int i, int i1)
onUpgrade
in class net.sqlcipher.database.SQLiteOpenHelper
public void saveTaskResult(TaskResult taskResult)
AppDatabase
saveTaskResult
in interface AppDatabase
taskResult
- the task result to savepublic TaskResult loadLatestTaskResult(java.lang.String taskIdentifier)
AppDatabase
This can be used to see when the user last answered the survey, or to get their most recent answer to a survey question.
loadLatestTaskResult
in interface AppDatabase
taskIdentifier
- the task identifierpublic java.util.List<TaskResult> loadTaskResults(java.lang.String taskIdentifier)
AppDatabase
loadTaskResults
in interface AppDatabase
taskIdentifier
- the task identifierpublic java.util.List<StepResult> loadStepResults(java.lang.String stepIdentifier)
AppDatabase
loadStepResults
in interface AppDatabase
stepIdentifier
- the step identifierpublic <D extends co.touchlab.squeaky.dao.Dao<T>,T> D getDao(java.lang.Class<T> clazz)
getDao
in class co.touchlab.squeaky.db.sqlcipher.SqueakyOpenHelper
public void setEncryptionKey(java.lang.String key)
AppDatabase
setEncryptionKey
in interface AppDatabase
key
- a string key to be used to encrypt the database