public class SmartStore
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
SmartStore.FtsExtension
Enum for fts extensions
|
static class |
SmartStore.SmartStoreException
Exception thrown by smart store
|
static class |
SmartStore.Type
Enum for column type
|
static class |
SmartStore.TypeGroup
Enum for type groups
|
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
COLUMN_NAME_COL |
static java.lang.String |
COLUMN_TYPE_COL |
protected static java.lang.String |
CREATED_COL |
protected SQLiteOpenHelper |
dbOpenHelper |
protected static java.lang.String |
DETAILS_COL |
static java.lang.String |
FTS_SUFFIX |
protected SmartStore.FtsExtension |
ftsExtension |
protected static java.lang.String |
ID_COL |
protected static java.lang.String |
ID_PREDICATE |
protected static java.lang.String |
LAST_MODIFIED_COL |
protected static java.lang.String |
LONG_OPERATIONS_STATUS_TABLE |
static java.lang.String |
PATH_COL |
protected static java.lang.String |
ROWID_COL |
protected static java.lang.String |
ROWID_PREDICATE |
static java.lang.String |
SOUP_ATTRS_TABLE |
protected static java.lang.String |
SOUP_COL |
static java.lang.String |
SOUP_CREATED_DATE |
static java.lang.String |
SOUP_ENTRY_ID |
static java.lang.String |
SOUP_INDEX_MAP_TABLE |
static java.lang.String |
SOUP_LAST_MODIFIED_DATE |
static java.lang.String |
SOUP_NAME_COL |
protected static java.lang.String |
SOUP_NAME_PREDICATE |
protected static java.lang.String |
STATUS_COL |
protected static java.lang.String |
TYPE_COL |
Constructor and Description |
---|
SmartStore(SQLiteOpenHelper dbOpenHelper)
Relies on SQLiteOpenHelper for database handling.
|
Modifier and Type | Method and Description |
---|---|
void |
alterSoup(java.lang.String soupName,
IndexSpec[] indexSpecs,
boolean reIndexData)
Alter soup using only soup name without extra soup features.
|
void |
beginTransaction()
Start transaction
NB: to avoid deadlock, caller should have synchronized(store.getDatabase()) around the whole transaction
|
static void |
changeKey(SQLiteDatabase db,
java.lang.String oldKey,
java.lang.String newKey)
Changes the encryption key on the smartstore.
|
void |
clearSoup(java.lang.String soupName)
Clear all rows from a soup
|
java.lang.String |
convertSmartSql(java.lang.String smartSql) |
int |
countQuery(QuerySpec querySpec) |
JSONObject |
create(java.lang.String soupName,
JSONObject soupElt)
Create (and commits)
Note: Passed soupElt is modified (last modified date and soup entry id fields)
|
JSONObject |
create(java.lang.String soupName,
JSONObject soupElt,
boolean handleTx)
Create
Note: Passed soupElt is modified (last modified date and soup entry id fields)
|
static void |
createLongOperationsStatusTable(SQLiteDatabase db)
Create long_operations_status table
|
static void |
createMetaTables(SQLiteDatabase db)
Create soup index map table to keep track of soups' index specs
Create soup name map table to keep track of soup name to table name mappings
Called when the database is first created
|
void |
delete(java.lang.String soupName,
java.lang.Long... soupEntryIds)
Delete soup elements given by their ids (and commits)
|
void |
delete(java.lang.String soupName,
java.lang.Long[] soupEntryIds,
boolean handleTx)
Delete soup elements given by their ids
|
void |
deleteByQuery(java.lang.String soupName,
QuerySpec querySpec)
Delete soup elements selected by querySpec (and commits)
|
void |
deleteByQuery(java.lang.String soupName,
QuerySpec querySpec,
boolean handleTx)
Delete soup elements selected by querySpec
|
void |
dropAllSoups()
Destroy all the soups in the smartstore
|
void |
dropSoup(java.lang.String soupName)
Destroy a soup
Drop table for soupName
Cleanup entries in soup index map table
|
void |
endTransaction()
End transaction (commit or rollback)
|
java.util.List<java.lang.String> |
getAllSoupNames() |
java.util.List<java.lang.String> |
getCompileOptions()
Get SQLCipher compile options
|
SQLiteDatabase |
getDatabase()
Return db
|
int |
getDatabaseSize()
Get database size
|
SmartStore.FtsExtension |
getFtsExtension() |
JSONObject |
getLastExplainQueryPlan() |
LongOperation[] |
getLongOperations() |
java.util.List<java.lang.String> |
getRuntimeSettings()
Get SQLCipher runtime settings
|
IndexSpec[] |
getSoupIndexSpecs(java.lang.String soupName)
Return indexSpecs of soup
|
static java.lang.String |
getSoupTableName(long soupId) |
java.lang.String |
getSQLCipherVersion()
Get SQLCipher version
|
boolean |
hasIndexForPath(java.lang.String soupName,
java.lang.String path)
Return true if the given path is indexed on the given soup
|
boolean |
hasSoup(java.lang.String soupName)
Check if soup exists
|
long |
lookupSoupEntryId(java.lang.String soupName,
java.lang.String fieldPath,
java.lang.String fieldValue)
Look for a soup element where fieldPath's value is fieldValue
Return its soupEntryId
Return -1 if not found
Throw an exception if fieldName is not indexed
Throw an exception if more than one soup element are found
|
static java.lang.Object |
project(JSONObject soup,
java.lang.String path) |
static java.lang.Object |
projectReturningNULLObject(JSONObject soup,
java.lang.String path)
Same as project but returns JSONObject.NULL if node found but without value and null if node not found
|
JSONArray |
query(QuerySpec querySpec,
int pageIndex)
Run a query given by its query spec
Returns results from selected page
|
void |
queryAsString(java.lang.StringBuilder resultBuilder,
QuerySpec querySpec,
int pageIndex)
Run a query given by its query Spec
Returns results from selected page without deserializing any JSON
|
JSONArray |
queryWithArgs(QuerySpec querySpec,
int pageIndex,
java.lang.String... whereArgs)
Run a query given by its query spec with optional "where args" (i.e.
|
void |
registerSoup(java.lang.String soupName,
IndexSpec[] indexSpecs)
Register a soup.
|
protected void |
registerSoupUsingTableName(java.lang.String soupName,
IndexSpec[] indexSpecs,
java.lang.String soupTableName)
Helper method for registerSoup
|
void |
reIndexSoup(java.lang.String soupName,
java.lang.String[] indexPaths,
boolean handleTx)
Re-index all soup elements for passed indexPaths
NB: only indexPath that have IndexSpec on them will be indexed
|
void |
resumeLongOperations()
Finish long operations that were interrupted
|
JSONArray |
retrieve(java.lang.String soupName,
java.lang.Long... soupEntryIds)
Retrieve
|
void |
setCaptureExplainQueryPlan(boolean captureExplainQueryPlan)
If turned on, explain query plan is run before executing a query and stored in lastExplainQueryPlan
and also get logged
|
void |
setFtsExtension(SmartStore.FtsExtension ftsExtension)
Sets the ftsX to be used when creating the virtual table to support full_text queries
NB: only used in tests
|
void |
setTransactionSuccessful()
Mark transaction as successful (next call to endTransaction will be a commit)
|
JSONObject |
update(java.lang.String soupName,
JSONObject soupElt,
long soupEntryId)
Update (and commits)
Note: Passed soupElt is modified (last modified date and soup entry id fields)
|
JSONObject |
update(java.lang.String soupName,
JSONObject soupElt,
long soupEntryId,
boolean handleTx)
Update
Note: Passed soupElt is modified (last modified date and soup entry id fields)
|
static void |
updateTableNameAndAddColumns(SQLiteDatabase db,
java.lang.String oldName,
java.lang.String newName,
java.lang.String[] columns)
Updates the given table with a new name and adds columns if any.
|
JSONObject |
upsert(java.lang.String soupName,
JSONObject soupElt)
Upsert (and commits) expecting _soupEntryId in soupElt for updates
|
JSONObject |
upsert(java.lang.String soupName,
JSONObject soupElt,
java.lang.String externalIdPath)
Upsert (and commits)
|
JSONObject |
upsert(java.lang.String soupName,
JSONObject soupElt,
java.lang.String externalIdPath,
boolean handleTx)
Upsert
|
public static final java.lang.String SOUP_ATTRS_TABLE
public static final java.lang.String FTS_SUFFIX
public static final java.lang.String SOUP_INDEX_MAP_TABLE
protected static final java.lang.String LONG_OPERATIONS_STATUS_TABLE
public static final java.lang.String SOUP_NAME_COL
public static final java.lang.String PATH_COL
protected static final java.lang.String COLUMN_NAME_COL
public static final java.lang.String COLUMN_TYPE_COL
protected static final java.lang.String ID_COL
protected static final java.lang.String CREATED_COL
protected static final java.lang.String LAST_MODIFIED_COL
protected static final java.lang.String SOUP_COL
protected static final java.lang.String ROWID_COL
protected static final java.lang.String TYPE_COL
protected static final java.lang.String DETAILS_COL
protected static final java.lang.String STATUS_COL
public static final java.lang.String SOUP_ENTRY_ID
public static final java.lang.String SOUP_LAST_MODIFIED_DATE
public static final java.lang.String SOUP_CREATED_DATE
protected static final java.lang.String SOUP_NAME_PREDICATE
protected static final java.lang.String ID_PREDICATE
protected static final java.lang.String ROWID_PREDICATE
protected SQLiteOpenHelper dbOpenHelper
protected SmartStore.FtsExtension ftsExtension
public SmartStore(SQLiteOpenHelper dbOpenHelper)
dbOpenHelper
- DB open helper.public static void changeKey(SQLiteDatabase db, java.lang.String oldKey, java.lang.String newKey)
db
- Database object.oldKey
- Old encryption key.newKey
- New encryption key.public static void createMetaTables(SQLiteDatabase db)
db
- public static void createLongOperationsStatusTable(SQLiteDatabase db)
db
- public SQLiteDatabase getDatabase()
public void setCaptureExplainQueryPlan(boolean captureExplainQueryPlan)
captureExplainQueryPlan
- true to turn capture on and false to turn offpublic JSONObject getLastExplainQueryPlan()
public int getDatabaseSize()
public void beginTransaction()
public void endTransaction()
public void setTransactionSuccessful()
public void registerSoup(java.lang.String soupName, IndexSpec[] indexSpecs)
soupName
- indexSpecs
- protected void registerSoupUsingTableName(java.lang.String soupName, IndexSpec[] indexSpecs, java.lang.String soupTableName)
soupName
- indexSpecs
- soupTableName
- public void resumeLongOperations()
public LongOperation[] getLongOperations()
public void alterSoup(java.lang.String soupName, IndexSpec[] indexSpecs, boolean reIndexData) throws JSONException
soupName
- indexSpecs
- array of index specsreIndexData
- JSONException
public void reIndexSoup(java.lang.String soupName, java.lang.String[] indexPaths, boolean handleTx)
soupName
- indexPaths
- handleTx
- public IndexSpec[] getSoupIndexSpecs(java.lang.String soupName)
soupName
- public boolean hasIndexForPath(java.lang.String soupName, java.lang.String path)
soupName
- path
- public void clearSoup(java.lang.String soupName)
soupName
- public boolean hasSoup(java.lang.String soupName)
soupName
- public void dropSoup(java.lang.String soupName)
soupName
- public void dropAllSoups()
public java.util.List<java.lang.String> getAllSoupNames()
public JSONArray query(QuerySpec querySpec, int pageIndex) throws JSONException
querySpec
- the query to runpageIndex
- the page to returnJSONException
public JSONArray queryWithArgs(QuerySpec querySpec, int pageIndex, java.lang.String... whereArgs) throws JSONException
querySpec
- the query to runpageIndex
- the page to returnwhereArgs
- the bind args (optional - only supported for smart queries)JSONException
public void queryAsString(java.lang.StringBuilder resultBuilder, QuerySpec querySpec, int pageIndex)
resultBuilder
- string builder to which results are appendedquerySpec
- pageIndex
- public int countQuery(QuerySpec querySpec)
querySpec
- public java.lang.String convertSmartSql(java.lang.String smartSql)
smartSql
- public JSONObject create(java.lang.String soupName, JSONObject soupElt) throws JSONException
soupName
- soupElt
- JSONException
public JSONObject create(java.lang.String soupName, JSONObject soupElt, boolean handleTx) throws JSONException
soupName
- soupElt
- JSONException
public JSONArray retrieve(java.lang.String soupName, java.lang.Long... soupEntryIds) throws JSONException
soupName
- soupEntryIds
- JSONException
public JSONObject update(java.lang.String soupName, JSONObject soupElt, long soupEntryId) throws JSONException
soupName
- soupElt
- soupEntryId
- JSONException
public JSONObject update(java.lang.String soupName, JSONObject soupElt, long soupEntryId, boolean handleTx) throws JSONException
soupName
- soupElt
- soupEntryId
- handleTx
- JSONException
public JSONObject upsert(java.lang.String soupName, JSONObject soupElt, java.lang.String externalIdPath) throws JSONException
soupName
- soupElt
- externalIdPath
- JSONException
public JSONObject upsert(java.lang.String soupName, JSONObject soupElt) throws JSONException
soupName
- soupElt
- JSONException
public JSONObject upsert(java.lang.String soupName, JSONObject soupElt, java.lang.String externalIdPath, boolean handleTx) throws JSONException
soupName
- soupElt
- externalIdPath
- handleTx
- JSONException
public long lookupSoupEntryId(java.lang.String soupName, java.lang.String fieldPath, java.lang.String fieldValue)
soupName
- fieldPath
- fieldValue
- public void delete(java.lang.String soupName, java.lang.Long... soupEntryIds)
soupName
- soupEntryIds
- public void delete(java.lang.String soupName, java.lang.Long[] soupEntryIds, boolean handleTx)
soupName
- soupEntryIds
- handleTx
- public void deleteByQuery(java.lang.String soupName, QuerySpec querySpec)
soupName
- querySpec
- Query returning entries to delete (if querySpec uses smartSQL, it must select soup entry ids)public void deleteByQuery(java.lang.String soupName, QuerySpec querySpec, boolean handleTx)
soupName
- querySpec
- handleTx
- public SmartStore.FtsExtension getFtsExtension()
public void setFtsExtension(SmartStore.FtsExtension ftsExtension)
ftsExtension
- public static java.lang.String getSoupTableName(long soupId)
soupId
- public static java.lang.Object project(JSONObject soup, java.lang.String path)
soup
- path
- public static java.lang.Object projectReturningNULLObject(JSONObject soup, java.lang.String path)
soup
- path
- public static void updateTableNameAndAddColumns(SQLiteDatabase db, java.lang.String oldName, java.lang.String newName, java.lang.String[] columns)
db
- Database to updateoldName
- Old name of the table to be renamed, null if table should not be renamed.newName
- New name of the table to be renamed, null if table should not be renamed.columns
- Columns to add. Null if no new columns should be added.public java.util.List<java.lang.String> getRuntimeSettings()
public java.util.List<java.lang.String> getCompileOptions()
public java.lang.String getSQLCipherVersion()