public class SQLiteStore extends java.lang.Object implements Store, EncryptableStore
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
kDBFilename |
static java.lang.String |
SCHEMA |
java.lang.String |
TAG |
| Constructor and Description |
|---|
SQLiteStore(java.lang.String directory,
Manager manager,
StoreDelegate delegate) |
| Modifier and Type | Method and Description |
|---|---|
Action |
actionToChangeEncryptionKey(SymmetricKey newKey)
Action for changing the encryption key of the storage.
|
RevisionInternal |
add(java.lang.String docID,
java.lang.String prevRevID,
java.util.Map<java.lang.String,java.lang.Object> properties,
boolean deleting,
boolean allowConflict,
StorageValidation validationBlock,
Status outStatus)
Creates a new revision of a document.
|
protected boolean |
beginTransaction()
Begins a storageEngine transaction.
|
RevisionList |
changesSince(long lastSequence,
ChangesOptions options,
ReplicationFilter filter,
java.util.Map<java.lang.String,java.lang.Object> filterParams)
Returns all database changes with sequences greater than `lastSequence`.
|
void |
close()
Closes storage before it's deallocated.
|
void |
compact()
Explicitly compacts document storage.
|
boolean |
databaseExists(java.lang.String directory)
Preflight to see if a database file exists in this directory.
|
byte[] |
derivePBKDF2SHA256Key(java.lang.String password,
byte[] salt,
int rounds)
A utility method for deriving PBKDF2-SHA256 based key from the password.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
documentPropertiesFromJSON(byte[] json,
java.lang.String docID,
java.lang.String revID,
boolean deleted,
long sequence) |
protected boolean |
endTransaction(boolean commit)
Commits or aborts (rolls back) a transaction.
|
long |
expirationOfDocument(java.lang.String docID)
Returns a document's expiration date as a Unix timestamp, or 0 for no expiration.
|
java.util.Set<BlobKey> |
findAllAttachmentKeys()
- (NSSet*) findAllAttachmentKeys: (NSError**)outError
|
java.lang.String |
findCommonAncestorOf(RevisionInternal rev,
java.util.List<java.lang.String> revIDs)
Returns the most recent member of revIDs that appears in rev's ancestry.
|
int |
findMissingRevisions(RevisionList touchRevs)
Looks for each given revision in the local database, and removes each one found
from the list.
|
void |
forceInsert(RevisionInternal inRev,
java.util.List<java.lang.String> history,
StorageValidation validationBlock,
java.net.URL source)
Inserts an already-existing revision replicated from a remote sqliteDb.
|
java.util.Map<java.lang.String,java.lang.Object> |
getAllDocs(QueryOptions options)
- (CBLQueryIteratorBlock) getAllDocs: (CBLQueryOptions*)options
status: (CBLStatus*)outStatus
|
RevisionList |
getAllRevisions(java.lang.String docID,
boolean onlyCurrent)
Returns all the known revisions (or all current/conflicting revisions) of a document.
|
java.util.List<java.lang.String> |
getAllViewNames()
Returns the names of all existing views in the database.
|
boolean |
getAutoCompact() |
StoreDelegate |
getDelegate() |
protected long |
getDocNumericID(java.lang.String docID) |
protected RevisionInternal |
getDocument(java.lang.String docID,
long sequence)
Loads revision given its sequence.
|
RevisionInternal |
getDocument(java.lang.String docID,
java.lang.String revID,
boolean withBody,
Status outStatus)
Retrieves a document revision by ID.
|
int |
getDocumentCount()
The number of (undeleted) documents in the database.
|
SymmetricKey |
getEncryptionKey()
Return current encryption key
|
java.lang.String |
getInfo(java.lang.String key)
Returns the value assigned to the given key by -setInfo:forKey:.
|
long |
getLastSequence()
The latest sequence number used.
|
RevisionInternal |
getLocalDocument(java.lang.String docID,
java.lang.String revID)
Returns the contents of a local document.
|
int |
getMaxRevTreeDepth()
Get the maximum depth of a document's revision tree (or, max length of its revision history.)
Revisions older than this limit will be deleted during a -compact: operation.
|
RevisionInternal |
getParentRevision(RevisionInternal rev)
Retrieves the parent revision of a revision, or returns nil if there is no parent.
|
java.util.List<java.lang.String> |
getPossibleAncestorRevisionIDs(RevisionInternal rev,
int limit,
java.util.concurrent.atomic.AtomicBoolean outHaveBodies,
boolean withBodiesOnly)
Returns IDs of local revisions of the same document, that have a lower generation number.
|
java.util.List<RevisionInternal> |
getRevisionHistory(RevisionInternal rev)
Returns an array of TDRevs in reverse chronological order, starting with the given revision.
|
protected SQLiteStorageEngine |
getStorageEngine() |
ViewStore |
getViewStorage(java.lang.String name,
boolean create)
Instantiates storage for a view.
|
boolean |
inTransaction()
Is a transaction active?
|
RevisionInternal |
loadRevisionBody(RevisionInternal rev)
Loads the body of a revision.
|
long |
nextDocumentExpiry()
Returns the next time at which a document will expire.
|
void |
open()
Opens storage.
|
protected void |
optimizeSQLIndexes()
https://github.com/couchbase/couchbase-lite-ios/issues/615
|
protected int |
pruneDocument(java.lang.String docID,
long docNumericID,
int minGenToKeep) |
protected int |
pruneRevsToMaxDepth(int maxDepth)
Prune revisions to the given max depth.
|
int |
purgeExpiredDocuments()
Triggers purging of documents whose expiration time has passed.
|
java.util.Map<java.lang.String,java.lang.Object> |
purgeRevisions(java.util.Map<java.lang.String,java.util.List<java.lang.String>> docsToRevs)
Purges specific revisions, which deletes them completely from the local storageEngine _without_ adding a "tombstone" revision.
|
RevisionInternal |
putLocalRevision(RevisionInternal revision,
java.lang.String prevRevID,
boolean obeyMVCC)
Creates / updates / deletes a local document.
|
protected RevisionInternal |
putLocalRevisionNoMVCC(RevisionInternal revision)
- (CBL_Revision*) putLocalRevisionNoMVCC: (CBL_Revision*)revision
status: (CBLStatus*)outStatus
|
protected static RevisionInternal |
revision(java.lang.String docID,
java.lang.String revID,
boolean deleted,
long sequence,
byte[] json) |
protected static RevisionInternal |
revision(java.lang.String docID,
java.lang.String revID,
boolean deleted,
long sequence,
java.util.Map<java.lang.String,java.lang.Object> properties) |
boolean |
runInTransaction(TransactionalTask transactionalTask)
Executes the block within a database transaction.
|
protected void |
runStatements(java.lang.String statements) |
void |
setAutoCompact(boolean value)
Whether the database storage should automatically (periodically) be compacted.
|
void |
setDelegate(StoreDelegate delegate)
The delegate object, which in practice is the CBLDatabase.
|
void |
setEncryptionKey(SymmetricKey key)
Set encryption key for opening the storage.
|
boolean |
setExpirationOfDocument(long unixTime,
java.lang.String docID)
Sets a document's expiration to a Unix timestamp, or 0 for no expiration.
|
long |
setInfo(java.lang.String key,
java.lang.String info)
Stores an arbitrary string under an arbitrary key, persistently.
|
void |
setMaxRevTreeDepth(int maxRevTreeDepth)
Set the maximum depth of a document's revision tree (or, max length of its revision history.)
Revisions older than this limit will be deleted during a -compact: operation.
|
protected java.lang.String |
winningRevIDOfDocNumericID(long docNumericId,
java.util.concurrent.atomic.AtomicBoolean outIsDeleted,
java.util.concurrent.atomic.AtomicBoolean outIsConflict)
Returns the rev ID of the 'winning' revision of this document, and whether it's deleted.
|
public java.lang.String TAG
public static java.lang.String kDBFilename
public static final java.lang.String SCHEMA
public SQLiteStore(java.lang.String directory,
Manager manager,
StoreDelegate delegate)
throws CouchbaseLiteException
CouchbaseLiteExceptionpublic boolean databaseExists(java.lang.String directory)
StoredatabaseExists in interface Storepublic void open()
throws CouchbaseLiteException
Storeopen in interface StoreCouchbaseLiteExceptionpublic void close()
Storepublic void setDelegate(StoreDelegate delegate)
StoresetDelegate in interface Storepublic StoreDelegate getDelegate()
getDelegate in interface Storepublic void setMaxRevTreeDepth(int maxRevTreeDepth)
setMaxRevTreeDepth in interface Storepublic int getMaxRevTreeDepth()
getMaxRevTreeDepth in interface Storepublic void setAutoCompact(boolean value)
StoresetAutoCompact in interface Storepublic boolean getAutoCompact()
getAutoCompact in interface Storepublic void setEncryptionKey(SymmetricKey key)
EncryptableStoresetEncryptionKey in interface EncryptableStorekey - a SymmetricKey objectpublic SymmetricKey getEncryptionKey()
EncryptableStoregetEncryptionKey in interface EncryptableStorepublic Action actionToChangeEncryptionKey(SymmetricKey newKey)
EncryptableStoreactionToChangeEncryptionKey in interface EncryptableStorenewKey - a new SymmetricKey objectpublic byte[] derivePBKDF2SHA256Key(java.lang.String password,
byte[] salt,
int rounds)
throws CouchbaseLiteException
EncryptableStorederivePBKDF2SHA256Key in interface EncryptableStorepassword - passwordsalt - saltrounds - number of roundsCouchbaseLiteExceptionpublic long setInfo(java.lang.String key,
java.lang.String info)
Storepublic java.lang.String getInfo(java.lang.String key)
Storepublic int getDocumentCount()
StoregetDocumentCount in interface Storepublic long getLastSequence()
getLastSequence in interface Storepublic boolean inTransaction()
inTransaction in interface Storepublic void compact()
throws CouchbaseLiteException
Storecompact in interface StoreCouchbaseLiteExceptionpublic boolean runInTransaction(TransactionalTask transactionalTask)
StorerunInTransaction in interface Storepublic RevisionInternal getDocument(java.lang.String docID, java.lang.String revID, boolean withBody, Status outStatus)
StoregetDocument in interface StoredocID - The document IDrevID - The revision ID; may be nil, meaning "the current revision".withBody - If false, revision's body won't be loadedpublic RevisionInternal loadRevisionBody(RevisionInternal rev) throws CouchbaseLiteException
StoreloadRevisionBody in interface StoreCouchbaseLiteExceptionpublic RevisionInternal getParentRevision(RevisionInternal rev)
StoregetParentRevision in interface Storepublic java.util.List<RevisionInternal> getRevisionHistory(RevisionInternal rev)
getRevisionHistory in interface Storepublic java.util.List<java.lang.String> getPossibleAncestorRevisionIDs(RevisionInternal rev, int limit, java.util.concurrent.atomic.AtomicBoolean outHaveBodies, boolean withBodiesOnly)
StoregetPossibleAncestorRevisionIDs in interface Storerev - The revision to look for ancestors of. Only its docID and revID are used.limit - The maximum number of results to return, or if 0, unlimited.outHaveBodies - On return, if not NULL, then *outHaveBodies will be YES if all the
revisions returned have their JSON bodies available, otherwise NO.withBodiesOnly - Specifies whether or not to search for non-empty and non-removed revisions.public java.lang.String findCommonAncestorOf(RevisionInternal rev, java.util.List<java.lang.String> revIDs)
findCommonAncestorOf in interface Storepublic int findMissingRevisions(RevisionList touchRevs) throws SQLException
StorefindMissingRevisions in interface StoreSQLExceptionpublic java.util.Set<BlobKey> findAllAttachmentKeys() throws CouchbaseLiteException
findAllAttachmentKeys in interface StoreCouchbaseLiteExceptionpublic java.util.Map<java.lang.String,java.lang.Object> getAllDocs(QueryOptions options) throws CouchbaseLiteException
getAllDocs in interface StoreCouchbaseLiteExceptionpublic RevisionList changesSince(long lastSequence, ChangesOptions options, ReplicationFilter filter, java.util.Map<java.lang.String,java.lang.Object> filterParams)
StorechangesSince in interface StorelastSequence - The sequence number to start _after_options - Options for ordering, document content, etc.filter - If non-nil, will be called on every revision,
and those for which it returns NO will be skipped.public RevisionInternal add(java.lang.String docID, java.lang.String prevRevID, java.util.Map<java.lang.String,java.lang.Object> properties, boolean deleting, boolean allowConflict, StorageValidation validationBlock, Status outStatus) throws CouchbaseLiteException
add in interface StoredocID - The document ID, or nil if an ID should be generated at random.prevRevID - The parent revision ID, or nil if creating a new document.properties - The new revision's properties. (Metadata other than "_attachments" ignored.)deleting - YES if this revision is a deletion.allowConflict - YES if this operation is allowed to create a conflict; otherwise a 409,
status will be returned if the parent revision is not a leaf.validationBlock - If non-nil, this block will be called before the revision is added.
It's given the parent revision, with its properties if available, and can reject
the operation by returning an error status.outStatus - On return a status will be stored here. Note that on success, the
status should be 201 for a created revision but 200 for a deletion.CouchbaseLiteExceptionpublic void forceInsert(RevisionInternal inRev, java.util.List<java.lang.String> history, StorageValidation validationBlock, java.net.URL source) throws CouchbaseLiteException
forceInsert in interface StoreinRev - The revision to insert. Its revID will be non-nil.history - The revIDs of the revision and its ancestors, in reverse chronological order.
The first item will be equal to inRev.revID.validationBlock - If non-nil, this block will be called before the revision is added.
It's given the parent revision, with its properties if available,
and can reject the operation by returning an error status.source - The URL of the remote database this was pulled from, or nil if it's local.
(This will be used to create the CBLDatabaseChange object sent to the delegate.)CouchbaseLiteExceptionpublic java.util.Map<java.lang.String,java.lang.Object> purgeRevisions(java.util.Map<java.lang.String,java.util.List<java.lang.String>> docsToRevs)
purgeRevisions in interface StoredocsToRevs - A dictionary mapping document IDs to arrays of revision IDs.public long expirationOfDocument(java.lang.String docID)
StoreexpirationOfDocument in interface Storepublic boolean setExpirationOfDocument(long unixTime,
java.lang.String docID)
StoresetExpirationOfDocument in interface Storepublic long nextDocumentExpiry()
StorenextDocumentExpiry in interface Storepublic int purgeExpiredDocuments()
StorepurgeExpiredDocuments in interface Storepublic ViewStore getViewStorage(java.lang.String name, boolean create) throws CouchbaseLiteException
getViewStorage in interface Storename - The name of the viewcreate - If YES, the view should be created; otherwise it must already existCouchbaseLiteExceptionpublic java.util.List<java.lang.String> getAllViewNames()
StoregetAllViewNames in interface Storepublic RevisionInternal getLocalDocument(java.lang.String docID, java.lang.String revID)
StoregetLocalDocument in interface StoredocID - The document ID, which will begin with "_local/"revID - revID The revision ID, or nil to return the current revision.public RevisionInternal putLocalRevision(RevisionInternal revision, java.lang.String prevRevID, boolean obeyMVCC) throws CouchbaseLiteException
StoreputLocalRevision in interface Storerevision - The new revision to save. Its docID must be set but the revID is ignored.
If its .deleted property is YES, it's a deletion.prevRevID - The revision ID to replaceobeyMVCC - If YES, the prevRevID must match the document's current revID (or nil if the
document doesn't exist) or a 409 error is returned. If NO, the prevRevID is
ignored and the operation always succeeds.CouchbaseLiteExceptionprotected RevisionInternal putLocalRevisionNoMVCC(RevisionInternal revision) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic RevisionList getAllRevisions(java.lang.String docID, boolean onlyCurrent)
StoregetAllRevisions in interface StoredocID - The document IDonlyCurrent - If true, only leaf revisions (whether or not deleted) should be returned.protected SQLiteStorageEngine getStorageEngine()
protected java.lang.String winningRevIDOfDocNumericID(long docNumericId,
java.util.concurrent.atomic.AtomicBoolean outIsDeleted,
java.util.concurrent.atomic.AtomicBoolean outIsConflict)
throws CouchbaseLiteException
CouchbaseLiteExceptionprotected void optimizeSQLIndexes()
protected boolean beginTransaction()
protected boolean endTransaction(boolean commit)
commit - If true, commits; if false, aborts and rolls back, undoing all changes made
since the matching -beginTransaction call, *including* any committed nested
transactions.protected java.util.Map<java.lang.String,java.lang.Object> documentPropertiesFromJSON(byte[] json,
java.lang.String docID,
java.lang.String revID,
boolean deleted,
long sequence)
protected int pruneRevsToMaxDepth(int maxDepth)
throws CouchbaseLiteException
CouchbaseLiteExceptionprotected int pruneDocument(java.lang.String docID,
long docNumericID,
int minGenToKeep)
protected void runStatements(java.lang.String statements)
throws SQLException
SQLExceptionprotected long getDocNumericID(java.lang.String docID)
protected RevisionInternal getDocument(java.lang.String docID, long sequence)
protected static RevisionInternal revision(java.lang.String docID, java.lang.String revID, boolean deleted, long sequence, byte[] json)
protected static RevisionInternal revision(java.lang.String docID, java.lang.String revID, boolean deleted, long sequence, java.util.Map<java.lang.String,java.lang.Object> properties)