public final class Database extends BaseDatabase
Modifier and Type | Field and Description |
---|---|
static Log |
log
Gets the logging controller for the Couchbase Lite library to configure the
logging settings and add custom logging.
|
static Prediction |
prediction
ENTERPRISE EDITION API
|
Constructor and Description |
---|
Database(String name)
Construct a Database with a given name and the default config.
|
Database(String name,
DatabaseConfiguration config)
Construct a AbstractDatabase with a given name and database config.
|
Modifier and Type | Method and Description |
---|---|
ListenerToken |
addChangeListener(DatabaseChangeListener listener)
Adds a change listener for the changes that occur in the database.
|
ListenerToken |
addChangeListener(Executor executor,
DatabaseChangeListener listener)
Adds a change listener for the changes that occur in the database with an executor on which the changes will be
posted to the listener.
|
ListenerToken |
addDocumentChangeListener(String id,
DocumentChangeListener listener)
Adds a change listener for the changes that occur to the specified document.
|
ListenerToken |
addDocumentChangeListener(String id,
Executor executor,
DocumentChangeListener listener)
Adds a change listener for the changes that occur to the specified document with an executor on which
the changes will be posted to the listener.
|
void |
changeEncryptionKey(EncryptionKey encryptionKey)
ENTERPRISE EDITION API
|
void |
close()
Closes a database.
|
static void |
copy(File path,
String name,
DatabaseConfiguration config)
Make a copy of a database in a new location.
|
void |
createIndex(String name,
Index index) |
void |
createIndex(String name,
IndexConfiguration config) |
Query |
createQuery(String query) |
void |
delete()
Deletes a database.
|
void |
delete(Document document)
Deletes a document from the database.
|
boolean |
delete(Document document,
ConcurrencyControl concurrencyControl)
Deletes a document from the database.
|
static void |
delete(String name,
File directory)
Deletes a database of the given name in the given directory.
|
void |
deleteIndex(String name) |
static boolean |
exists(String name,
File directory)
Checks whether a database of the given name exists in the given directory or not.
|
Blob |
getBlob(Map<String,Object> props)
(UNCOMMITTED) Use this API if you are developing Javascript language bindings.
|
DatabaseConfiguration |
getConfig()
Returns a copy of the database configuration.
|
long |
getCount()
The number of documents in the database.
|
Document |
getDocument(String id)
Gets an existing Document object with the given ID.
|
Date |
getDocumentExpiration(String id)
Returns the expiration time of the document.
|
List<String> |
getIndexes() |
String |
getName()
Return the database name
|
String |
getPath()
The database's absolute path
|
<T extends Exception> |
inBatch(UnitOfWork<T> work)
Runs a group of database operations in a batch.
|
boolean |
performMaintenance(MaintenanceType type) |
void |
purge(Document document)
Purges the given document from the database.
|
void |
purge(String id)
Purges the given document id for the document in database.
|
void |
removeChangeListener(ListenerToken token)
Removes the change listener added to the database.
|
void |
save(MutableDocument document)
Saves a document to the database.
|
boolean |
save(MutableDocument document,
ConcurrencyControl concurrencyControl)
Saves a document to the database.
|
boolean |
save(MutableDocument document,
ConflictHandler conflictHandler)
Saves a document to the database.
|
void |
saveBlob(Blob blob)
(UNCOMMITTED) Use this API if you are developing Javascript language bindings.
|
void |
setDocumentExpiration(String id,
Date expiration)
Sets an expiration date on a document.
|
String |
toString() |
@NonNull public static final Prediction prediction
The predictive model manager for registering and unregistering predictive models. This is part of the Public API.
@NonNull public static final Log log
public Database(@NonNull String name) throws CouchbaseLiteException
name
- The name of the database: May NOT contain capital letters!CouchbaseLiteException
- if any error occurs during the open operation.public Database(@NonNull String name, @NonNull DatabaseConfiguration config) throws CouchbaseLiteException
name
- The name of the database: May NOT contain capital letters!config
- The database config.CouchbaseLiteException
- Throws an exception if any error occurs during the open operation.public static void copy(@NonNull File path, @NonNull String name, @NonNull DatabaseConfiguration config) throws CouchbaseLiteException
path
- path to the existing db filename
- the name of the new DBconfig
- a config with the new locationCouchbaseLiteException
- on copy failurepublic void changeEncryptionKey(EncryptionKey encryptionKey) throws CouchbaseLiteException
Changes the database's encryption key, or removes encryption if the new key is null.
encryptionKey
- The encryption keyCouchbaseLiteException
- on errorpublic static void delete(@NonNull String name, @Nullable File directory) throws CouchbaseLiteException
name
- the database's namedirectory
- the directory containing the database: the database's parent directory.CouchbaseLiteException
- Throws an exception if any error occurs during the operation.public static boolean exists(@NonNull String name, @Nullable File directory)
name
- the database's namedirectory
- the path where the database is located. If null, the default db directory will be used.@NonNull public String getName()
@Nullable public String getPath()
public long getCount()
@NonNull public DatabaseConfiguration getConfig()
@Nullable public Document getDocument(@NonNull String id)
id
- the document IDpublic void save(@NonNull MutableDocument document) throws CouchbaseLiteException
document
- The document.CouchbaseLiteException
- on errorpublic boolean save(@NonNull MutableDocument document, @NonNull ConcurrencyControl concurrencyControl) throws CouchbaseLiteException
document
- The document.concurrencyControl
- The concurrency control.CouchbaseLiteException
- on errorpublic boolean save(@NonNull MutableDocument document, @NonNull ConflictHandler conflictHandler) throws CouchbaseLiteException
document
- The document.conflictHandler
- A conflict handler.CouchbaseLiteException
- on errorpublic void delete(@NonNull Document document) throws CouchbaseLiteException
document
- The document.CouchbaseLiteException
- on errorpublic boolean delete(@NonNull Document document, @NonNull ConcurrencyControl concurrencyControl) throws CouchbaseLiteException
document
- The document.concurrencyControl
- The concurrency control.CouchbaseLiteException
- on errorpublic void purge(@NonNull Document document) throws CouchbaseLiteException
document
- the document to be purged.CouchbaseLiteException
public void purge(@NonNull String id) throws CouchbaseLiteException
id
- the document IDCouchbaseLiteException
public void setDocumentExpiration(@NonNull String id, @Nullable Date expiration) throws CouchbaseLiteException
id
- The ID of the Documentexpiration
- Nullable expiration timestamp as a Date, set timestamp to null
to remove expiration date time from doc.CouchbaseLiteException
- Throws an exception if any error occurs during the operation.@Nullable public Date getDocumentExpiration(@NonNull String id) throws CouchbaseLiteException
id
- The ID of the DocumentCouchbaseLiteException
- Throws an exception if any error occurs during the operation.public <T extends Exception> void inBatch(@NonNull UnitOfWork<T> work) throws CouchbaseLiteException, T extends Exception
work
- a unit of work that may terminate abruptly (with an exception)CouchbaseLiteException
- Throws an exception if any error occurs during the operation.T extends Exception
@NonNull public ListenerToken addChangeListener(@NonNull DatabaseChangeListener listener)
listener
- callback@NonNull public ListenerToken addChangeListener(@Nullable Executor executor, @NonNull DatabaseChangeListener listener)
listener
- callbackpublic void removeChangeListener(@NonNull ListenerToken token)
token
- returned by a previous call to addChangeListener or addDocumentListener.@NonNull public ListenerToken addDocumentChangeListener(@NonNull String id, @NonNull DocumentChangeListener listener)
@NonNull public ListenerToken addDocumentChangeListener(@NonNull String id, @Nullable Executor executor, @NonNull DocumentChangeListener listener)
public void close() throws CouchbaseLiteException
CouchbaseLiteException
- Throws an exception if any error occurs during the operation.public void delete() throws CouchbaseLiteException
CouchbaseLiteException
- Throws an exception if any error occurs during the operation.@NonNull public Query createQuery(@NonNull String query) throws CouchbaseLiteException
CouchbaseLiteException
@NonNull public List<String> getIndexes() throws CouchbaseLiteException
CouchbaseLiteException
public void createIndex(@NonNull String name, @NonNull Index index) throws CouchbaseLiteException
CouchbaseLiteException
public void createIndex(@NonNull String name, @NonNull IndexConfiguration config) throws CouchbaseLiteException
CouchbaseLiteException
public void deleteIndex(@NonNull String name) throws CouchbaseLiteException
CouchbaseLiteException
public boolean performMaintenance(MaintenanceType type) throws CouchbaseLiteException
CouchbaseLiteException
@Internal(value="This method is not part of the public API: it is for internal use only") public void saveBlob(@NonNull Blob blob)
Blob
API.blob
- @Internal(value="This method is not part of the public API: it is for internal use only") @Nullable public Blob getBlob(@NonNull Map<String,Object> props)
Blob
API.