public class Database extends java.lang.Object implements StoreDelegate
| Modifier and Type | Class and Description |
|---|---|
static class |
Database.ChangeEvent
The type of event raised when a Database changes.
|
static interface |
Database.ChangeListener
A delegate that can be used to listen for Database changes.
|
static interface |
Database.DatabaseListener |
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_REVS |
static int |
kBigAttachmentLength |
static java.lang.String |
kCBLDatabaseLocalCheckpoint_LocalUUID |
static java.lang.String |
kLocalCheckpointDocId |
static java.lang.String |
TAG |
| Constructor and Description |
|---|
Database(java.lang.String path,
java.lang.String name,
Manager manager,
boolean readOnly)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
addActiveReplication(Replication replication) |
void |
addChangeListener(Database.ChangeListener listener)
Adds a Database change delegate that will be called whenever a Document
within the Database changes.
|
void |
addDatabaseListener(Database.DatabaseListener listener) |
void |
changeEncryptionKey(java.lang.Object newKeyOrPassword)
Changes the database's encryption key, or removes encryption if the new key is null.
|
RevisionList |
changesSince(long lastSeq,
ChangesOptions options,
ReplicationFilter filter,
java.util.Map<java.lang.String,java.lang.Object> filterParams) |
protected void |
clearDocumentCache()
Empties the cache of recently used Document objects.
|
boolean |
close() |
void |
compact()
Compacts the database file by purging non-current JSON bodies, pruning revisions older than
the maxRevTreeDepth, deleting unused attachment files, and vacuuming the SQLite database.
|
Query |
createAllDocumentsQuery()
Returns a query that matches all documents in the database.
|
Document |
createDocument()
Creates a new Document object with no properties and a new (random) UUID.
|
Replication |
createPullReplication(java.net.URL remote)
Creates a new Replication that will pull from the source Database at the given url.
|
Replication |
createPushReplication(java.net.URL remote)
Creates a new Replication that will push to the target Database at the given url.
|
void |
databaseStorageChanged(DocumentChange change)
in CBLDatabase+Internal.m
- (void) databaseStorageChanged:(CBLDatabaseChange *)change
|
void |
delete()
Deletes the database.
|
boolean |
deleteLocalDocument(java.lang.String localDocID)
Deletes the local document with the given ID.
|
boolean |
exists() |
boolean |
expandAttachments(RevisionInternal rev,
int minRevPos,
boolean allowFollows,
boolean decodeAttachments,
Status outStatus)
Modifies a CBL_Revision's _attachments dictionary by adding the "data" property to all
attachments (and removing "stub" and "follows".) GZip-encoded attachments will be unzipped
unless options contains the flag kCBLLeaveAttachmentsEncoded.
|
protected long |
expirationOfDocument(java.lang.String docID) |
java.net.URL |
fileForAttachmentDict(java.util.Map<java.lang.String,java.lang.Object> attachmentDict) |
protected Replication |
findActiveReplicator(Replication replicator) |
java.lang.String |
findCommonAncestorOf(RevisionInternal rev,
java.util.List<java.lang.String> revIDs) |
int |
findMissingRevisions(RevisionList touchRevs) |
void |
forceInsert(RevisionInternal inRev,
java.util.List<java.lang.String> history,
java.net.URL source)
Inserts an already-existing revision replicated from a remote sqliteDb.
|
protected void |
forgetView(java.lang.String name)
in CBLDatabase+Internal.m
- (void) forgetViewNamed: (NSString*)name
|
java.lang.String |
generateRevID(byte[] json,
boolean deleted,
java.lang.String prevRevID)
Generates a revision ID for a new revision.
|
java.util.Map<java.lang.String,java.lang.Object> |
getAllDocs(QueryOptions options) |
java.util.List<Replication> |
getAllReplications()
Get all the replicators associated with this database.
|
RevisionList |
getAllRevisions(java.lang.String docID,
boolean onlyCurrent) |
protected java.util.List<View> |
getAllViews()
NOTE: Only used by Unit Tests
|
AttachmentInternal |
getAttachment(java.util.Map info,
java.lang.String filename) |
AttachmentInternal |
getAttachment(RevisionInternal rev,
java.lang.String filename) |
protected java.util.Map<java.lang.String,java.lang.Object> |
getAttachments(java.lang.String docID,
java.lang.String revID)
- (NSDictionary*) attachmentsForDocID: (NSString*)docID
revID: (NSString*)revID
status: (CBLStatus*)outStatus
|
BlobStore |
getAttachmentStore() |
protected java.lang.String |
getAttachmentStorePath() |
BlobStoreWriter |
getAttachmentWriter() |
protected Document |
getCachedDocument(java.lang.String documentID)
Returns the already-instantiated cached Document with the given ID,
or nil if none is yet cached.
|
Document |
getDocument(java.lang.String documentId)
Instantiates a Document object with the given ID.
|
RevisionInternal |
getDocument(java.lang.String docID,
java.lang.String revID,
boolean withBody) |
RevisionInternal |
getDocument(java.lang.String docID,
java.lang.String revID,
boolean withBody,
Status outStatus) |
int |
getDocumentCount()
The number of documents in the database.
|
Document |
getExistingDocument(java.lang.String docID)
Gets the Document with the given id, or null if it does not exist.
|
java.util.Map<java.lang.String,java.lang.Object> |
getExistingLocalDocument(java.lang.String documentId)
Returns the contents of the local document with the given ID, or nil if none exists.
|
View |
getExistingView(java.lang.String name)
Returns the existing View with the given name, or nil if none.
|
ReplicationFilter |
getFilter(java.lang.String filterName)
Returns the existing filter function (block) registered with the given name.
|
static ReplicationFilterCompiler |
getFilterCompiler()
Returns the currently registered filter compiler (nil by default).
|
protected java.lang.String |
getInfo(java.lang.String key) |
long |
getLastSequenceNumber()
The latest sequence number used.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
getLocalCheckpointDocument()
Returns local checkpoint document if it exists.
|
protected java.lang.Object |
getLocalCheckpointDocumentPropertyValueForKey(java.lang.String key)
Returns a property value specifiec by the key from the local checkpoint document.
|
RevisionInternal |
getLocalDocument(java.lang.String docID,
java.lang.String revID) |
Manager |
getManager()
The database manager that owns this database.
|
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.
|
java.lang.String |
getName()
Get the database's name.
|
protected RevisionInternal |
getParentRevision(RevisionInternal rev) |
protected java.lang.String |
getPath() |
PersistentCookieJar |
getPersistentCookieStore()
Get the PersistentCookieStore associated with this database.
|
java.util.List<java.lang.String> |
getPossibleAncestorRevisionIDs(RevisionInternal rev,
int limit,
java.util.concurrent.atomic.AtomicBoolean hasAttachment,
boolean withBodiesOnly)
NOTE: This method is internal use only (from BulkDownloader and PullerInternal)
|
java.util.List<RevisionInternal> |
getRevisionHistory(RevisionInternal rev)
Returns an array of TDRevs in reverse chronological order, starting with the given revision.
|
java.util.Map<java.lang.String,java.lang.Object> |
getRevisionHistoryDictStartingFromAnyAncestor(RevisionInternal rev,
java.util.List<java.lang.String> ancestorRevIDs)
Returns the revision history as a _revisions dictionary, as returned
by the REST API's ?revs=true option.
|
long |
getStartTime() |
protected Store |
getStore() |
Validator |
getValidation(java.lang.String name)
Returns the existing document validation function (block) registered with the given name.
|
View |
getView(java.lang.String name)
Returns a View object for the view with the given name.
|
protected java.lang.String |
getViewDocumentType(java.lang.String viewName)
Get the document type for the given view name.
|
protected ViewStore |
getViewStorage(java.lang.String name,
boolean create) |
boolean |
inlineFollowingAttachmentsIn(RevisionInternal rev) |
boolean |
isOpen()
Is the database open?
|
java.lang.String |
lastSequenceWithCheckpointId(java.lang.String checkpointId) |
RevisionInternal |
loadRevisionBody(RevisionInternal rev) |
protected View |
makeAnonymousView() |
void |
open() |
void |
open(DatabaseOptions options) |
static java.util.List<java.lang.String> |
parseCouchDBRevisionHistory(java.util.Map<java.lang.String,java.lang.Object> docProperties)
Parses the _revisions dict from a document into an array of revision ID strings
|
java.lang.String |
privateUUID() |
java.lang.String |
publicUUID() |
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 database
_without_ adding a "tombstone" revision.
|
RevisionInternal |
put(java.lang.String docID,
java.util.Map<java.lang.String,java.lang.Object> properties,
java.lang.String prevRevID,
boolean allowConflict,
java.net.URL source,
Status outStatus) |
protected boolean |
putLocalCheckpointDocumentWithKey(java.lang.String key,
java.lang.Object value)
Put a property with a given key and value into the local checkpoint document.
|
boolean |
putLocalDocument(java.lang.String localDocID,
java.util.Map<java.lang.String,java.lang.Object> properties)
Sets the contents of the local document with the given ID.
|
RevisionInternal |
putLocalRevision(RevisionInternal revision,
java.lang.String prevRevID,
boolean obeyMVCC) |
RevisionInternal |
putRevision(RevisionInternal rev,
java.lang.String prevRevId,
boolean allowConflict) |
RevisionInternal |
putRevision(RevisionInternal putRev,
java.lang.String inPrevRevID,
boolean allowConflict,
Status outStatus) |
protected java.util.List<QueryRow> |
queryViewNamed(java.lang.String viewName,
QueryOptions options,
java.util.List<java.lang.Long> outLastSequence)
Reference: In CBLQuery.m
- (CBLQueryEnumerator*) queryViewNamed: (NSString*)viewName
options: (CBLQueryOptions*)options
ifChangedSince: (SequenceNumber)ifChangedSince
status: (CBLStatus*)outStatus
|
protected void |
rememberAttachmentWriter(BlobStoreWriter writer) |
protected void |
rememberAttachmentWriter(BlobStoreWriter writer,
java.lang.String digest) |
void |
rememberAttachmentWritersForDigests(java.util.Map<java.lang.String,BlobStoreWriter> blobsByDigest) |
void |
rememberPendingKey(BlobKey key,
java.lang.String digest) |
void |
removeChangeListener(Database.ChangeListener listener)
Removes the specified delegate as a listener for the Database change event.
|
void |
removeDatabaseListener(Database.DatabaseListener listener) |
protected void |
removeDocumentFromCache(Document document) |
protected boolean |
replaceUUIDs() |
java.util.concurrent.Future |
runAsync(AsyncTask asyncTask)
Runs the delegate asynchronously.
|
boolean |
runFilter(ReplicationFilter filter,
java.util.Map<java.lang.String,java.lang.Object> filterParams,
RevisionInternal rev) |
boolean |
runInTransaction(TransactionalTask task)
Runs the block within a transaction.
|
protected boolean |
saveLocalUUIDInLocalCheckpointDocument()
Save current local uuid into the local checkpoint document.
|
static void |
setAutoCompact(boolean autoCompact) |
void |
setFilter(java.lang.String filterName,
ReplicationFilter filter)
Define or clear a named filter function.
|
static void |
setFilterCompiler(ReplicationFilterCompiler filterCompiler)
Registers an object that can compile source code into executable filter blocks.
|
protected long |
setInfo(java.lang.String key,
java.lang.String info) |
boolean |
setLastSequence(java.lang.String lastSequence,
java.lang.String checkpointId) |
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 void |
setName(java.lang.String name)
Set the database's name.
|
void |
setValidation(java.lang.String name,
Validator validator)
Defines or clears a named document validation function.
|
protected void |
setViewDocumentType(java.lang.String docType,
java.lang.String viewName)
Set the document type for the given view name.
|
protected Query |
slowQuery(Mapper map)
Creates a one-shot query with the given map function.
|
void |
storageExitedTransaction(boolean committed)
in CBLDatabase+Internal.m
- (void) storageExitedTransaction: (BOOL)committed
|
java.lang.String |
toString()
Returns a string representation of this database.
|
long |
totalDataSize() |
RevisionList |
unpushedRevisionsSince(java.lang.String sequence,
ReplicationFilter filter,
java.util.Map<java.lang.String,java.lang.Object> filterParams) |
RevisionInternal |
updateAttachment(java.lang.String filename,
BlobStoreWriter body,
java.lang.String contentType,
AttachmentInternal.AttachmentEncoding encoding,
java.lang.String docID,
java.lang.String oldRevID,
java.net.URL source)
Updates or deletes an attachment, creating a new document revision in the process.
|
public static final java.lang.String TAG
public static int kBigAttachmentLength
public static int DEFAULT_MAX_REVS
public static java.lang.String kCBLDatabaseLocalCheckpoint_LocalUUID
public static java.lang.String kLocalCheckpointDocId
public Database(java.lang.String path,
java.lang.String name,
Manager manager,
boolean readOnly)
public static ReplicationFilterCompiler getFilterCompiler()
public static void setFilterCompiler(ReplicationFilterCompiler filterCompiler)
public java.util.List<Replication> getAllReplications()
public int getDocumentCount()
public long getLastSequenceNumber()
public Manager getManager()
public java.lang.String getName()
public void addChangeListener(Database.ChangeListener listener)
public void compact()
throws CouchbaseLiteException
CouchbaseLiteExceptionpublic void changeEncryptionKey(java.lang.Object newKeyOrPassword)
throws CouchbaseLiteException
newKeyOrPassword - The encryption key in the form of an String (a password) or an
byte[] object exactly 32 bytes in length (a raw AES key.)
If a string is given, it will be internally converted to a raw key
using 64,000 rounds of PBKDF2 hashing.
A null value is legal, and clears a previously-registered key.CouchbaseLiteExceptionpublic Query createAllDocumentsQuery()
public Document createDocument()
public Replication createPullReplication(java.net.URL remote)
remote - the remote URL to pull frompublic Replication createPushReplication(java.net.URL remote)
remote - the remote URL to push topublic void delete()
throws CouchbaseLiteException
CouchbaseLiteExceptionpublic boolean deleteLocalDocument(java.lang.String localDocID)
throws CouchbaseLiteException
CouchbaseLiteExceptionpublic Document getDocument(java.lang.String documentId)
public Document getExistingDocument(java.lang.String docID)
public java.util.Map<java.lang.String,java.lang.Object> getExistingLocalDocument(java.lang.String documentId)
public View getExistingView(java.lang.String name)
public ReplicationFilter getFilter(java.lang.String filterName)
public Validator getValidation(java.lang.String name)
public View getView(java.lang.String name)
public boolean putLocalDocument(java.lang.String localDocID,
java.util.Map<java.lang.String,java.lang.Object> properties)
throws CouchbaseLiteException
CouchbaseLiteExceptionpublic void removeChangeListener(Database.ChangeListener listener)
public java.util.concurrent.Future runAsync(AsyncTask asyncTask)
public boolean runInTransaction(TransactionalTask task)
public void setFilter(java.lang.String filterName,
ReplicationFilter filter)
public void setValidation(java.lang.String name,
Validator validator)
public void setMaxRevTreeDepth(int maxRevTreeDepth)
public int getMaxRevTreeDepth()
public java.lang.String toString()
toString in class java.lang.Objectpublic void storageExitedTransaction(boolean committed)
storageExitedTransaction in interface StoreDelegatecommitted - YES on commit, NO if the transaction was aborted.public void databaseStorageChanged(DocumentChange change)
databaseStorageChanged in interface StoreDelegatepublic java.lang.String generateRevID(byte[] json,
boolean deleted,
java.lang.String prevRevID)
generateRevID in interface StoreDelegatejson - The canonical JSON of the revision (with metadata properties removed.)deleted - YES if this revision is a deletionprevRevID - The parent's revision ID, or nil if this is a new document.public BlobStore getAttachmentStore()
public boolean expandAttachments(RevisionInternal rev, int minRevPos, boolean allowFollows, boolean decodeAttachments, Status outStatus)
rev - The revision to operate on. Its _attachments property may be altered.minRevPos - Attachments with a "revpos" less than this will remain stubs.allowFollows - If YES, non-small attachments will get a "follows" key instead of data.decodeAttachments - If YES, attachments with "encoding" properties will be decoded.outStatus - On failure, will be set to the error status.public boolean runFilter(ReplicationFilter filter, java.util.Map<java.lang.String,java.lang.Object> filterParams, RevisionInternal rev)
runFilter in interface StoreDelegatepublic static void setAutoCompact(boolean autoCompact)
public void addDatabaseListener(Database.DatabaseListener listener)
public void removeDatabaseListener(Database.DatabaseListener listener)
public boolean exists()
public void open()
throws CouchbaseLiteException
CouchbaseLiteExceptionpublic void open(DatabaseOptions options) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic boolean close()
public BlobStoreWriter getAttachmentWriter()
public long totalDataSize()
public java.lang.String privateUUID()
public java.lang.String publicUUID()
public RevisionInternal getDocument(java.lang.String docID, java.lang.String revID, boolean withBody)
public RevisionInternal getDocument(java.lang.String docID, java.lang.String revID, boolean withBody, Status outStatus)
public RevisionInternal loadRevisionBody(RevisionInternal rev) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic java.util.List<java.lang.String> getPossibleAncestorRevisionIDs(RevisionInternal rev, int limit, java.util.concurrent.atomic.AtomicBoolean hasAttachment, boolean withBodiesOnly)
public java.util.Map<java.lang.String,java.lang.Object> getRevisionHistoryDictStartingFromAnyAncestor(RevisionInternal rev, java.util.List<java.lang.String> ancestorRevIDs)
public RevisionList changesSince(long lastSeq, ChangesOptions options, ReplicationFilter filter, java.util.Map<java.lang.String,java.lang.Object> filterParams)
public RevisionList unpushedRevisionsSince(java.lang.String sequence, ReplicationFilter filter, java.util.Map<java.lang.String,java.lang.Object> filterParams)
public java.util.Map<java.lang.String,java.lang.Object> getAllDocs(QueryOptions options) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic AttachmentInternal getAttachment(java.util.Map info, java.lang.String filename) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic java.net.URL fileForAttachmentDict(java.util.Map<java.lang.String,java.lang.Object> attachmentDict)
public boolean inlineFollowingAttachmentsIn(RevisionInternal rev)
public RevisionInternal updateAttachment(java.lang.String filename, BlobStoreWriter body, java.lang.String contentType, AttachmentInternal.AttachmentEncoding encoding, java.lang.String docID, java.lang.String oldRevID, java.net.URL source) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic void rememberAttachmentWritersForDigests(java.util.Map<java.lang.String,BlobStoreWriter> blobsByDigest)
public void rememberPendingKey(BlobKey key, java.lang.String digest)
public static java.util.List<java.lang.String> parseCouchDBRevisionHistory(java.util.Map<java.lang.String,java.lang.Object> docProperties)
public RevisionInternal putRevision(RevisionInternal rev, java.lang.String prevRevId, boolean allowConflict) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic RevisionInternal putRevision(RevisionInternal putRev, java.lang.String inPrevRevID, boolean allowConflict, Status outStatus) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic RevisionInternal put(java.lang.String docID, java.util.Map<java.lang.String,java.lang.Object> properties, java.lang.String prevRevID, boolean allowConflict, java.net.URL source, Status outStatus) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic void forceInsert(RevisionInternal inRev, java.util.List<java.lang.String> history, java.net.URL source) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic java.lang.String lastSequenceWithCheckpointId(java.lang.String checkpointId)
public boolean setLastSequence(java.lang.String lastSequence,
java.lang.String checkpointId)
public int findMissingRevisions(RevisionList touchRevs) throws SQLException
SQLExceptionpublic java.util.Map<java.lang.String,java.lang.Object> purgeRevisions(java.util.Map<java.lang.String,java.util.List<java.lang.String>> docsToRevs)
docsToRevs - A dictionary mapping document IDs to arrays of revision IDs.public RevisionInternal getLocalDocument(java.lang.String docID, java.lang.String revID)
public long getStartTime()
public boolean isOpen()
public void addActiveReplication(Replication replication)
public PersistentCookieJar getPersistentCookieStore()
protected void clearDocumentCache()
protected Document getCachedDocument(java.lang.String documentID)
protected void removeDocumentFromCache(Document document)
protected java.lang.String getAttachmentStorePath()
protected java.lang.String getPath()
protected Store getStore()
protected ViewStore getViewStorage(java.lang.String name, boolean create) throws CouchbaseLiteException
CouchbaseLiteExceptionprotected long setInfo(java.lang.String key,
java.lang.String info)
protected java.lang.String getInfo(java.lang.String key)
protected long expirationOfDocument(java.lang.String docID)
public RevisionList getAllRevisions(java.lang.String docID, boolean onlyCurrent)
public java.lang.String findCommonAncestorOf(RevisionInternal rev, java.util.List<java.lang.String> revIDs)
public RevisionInternal putLocalRevision(RevisionInternal revision, java.lang.String prevRevID, boolean obeyMVCC) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic java.util.List<RevisionInternal> getRevisionHistory(RevisionInternal rev)
protected void setViewDocumentType(java.lang.String docType,
java.lang.String viewName)
docType - document typeviewName - view nameprotected java.lang.String getViewDocumentType(java.lang.String viewName)
viewName - view nameprotected void forgetView(java.lang.String name)
protected java.util.List<QueryRow> queryViewNamed(java.lang.String viewName, QueryOptions options, java.util.List<java.lang.Long> outLastSequence) throws CouchbaseLiteException
CouchbaseLiteExceptionprotected View makeAnonymousView()
protected java.util.List<View> getAllViews()
protected java.util.Map<java.lang.String,java.lang.Object> getAttachments(java.lang.String docID,
java.lang.String revID)
public AttachmentInternal getAttachment(RevisionInternal rev, java.lang.String filename) throws CouchbaseLiteException
CouchbaseLiteExceptionprotected void rememberAttachmentWriter(BlobStoreWriter writer)
protected void rememberAttachmentWriter(BlobStoreWriter writer, java.lang.String digest)
protected Replication findActiveReplicator(Replication replicator)
protected Query slowQuery(Mapper map)
protected RevisionInternal getParentRevision(RevisionInternal rev)
protected boolean replaceUUIDs()
protected void setName(java.lang.String name)
protected boolean saveLocalUUIDInLocalCheckpointDocument()
protected boolean putLocalCheckpointDocumentWithKey(java.lang.String key,
java.lang.Object value)
protected java.lang.Object getLocalCheckpointDocumentPropertyValueForKey(java.lang.String key)
protected java.util.Map<java.lang.String,java.lang.Object> getLocalCheckpointDocument()