public final class Database extends Object
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.
|
void |
compact()
Deprecated.
Use Database.performMaintenance(MaintenanceType.COMPACT)
|
static void |
copy(File path,
String name,
DatabaseConfiguration config)
Make a copy of a database in a new location.
|
void |
createIndex(String name,
Index idx) |
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.
|
DatabaseConfiguration |
getConfig()
Returns a READONLY config object which will throw a runtime exception
when any setter methods are called.
|
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()
Return the database's path.
|
void |
inBatch(Runnable runnable)
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 |
setDocumentExpiration(String id,
Date expiration)
Sets an expiration date on a document.
|
static void |
setLogLevel(LogDomain domain,
LogLevel level)
Deprecated.
As of 2.5 because it is being replaced with the
getConsole method from the log property.
This method will eventually be replaced with a no-op to preserve API compatibility.
Until it is, its interactions with other logging maybe be fairly unpredictable. |
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, @NonNull File directory)
name
- the database's namedirectory
- the path where the database is located.@Deprecated public static void setLogLevel(@NonNull LogDomain domain, @NonNull LogLevel level)
getConsole
method from the log
property.
This method will eventually be replaced with a no-op to preserve API compatibility.
Until it is, its interactions with other logging maybe be fairly unpredictable.domain
- The log domainlevel
- The log level@NonNull public String getName()
public String getPath()
public long getCount()
@NonNull public DatabaseConfiguration getConfig()
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, 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.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 void inBatch(@NonNull Runnable runnable) throws CouchbaseLiteException
runnable
- the action which is implementation of Runnable interfaceCouchbaseLiteException
- Throws an exception if any error occurs during the operation.@Deprecated public void compact() throws CouchbaseLiteException
CouchbaseLiteException
@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 List<String> getIndexes() throws CouchbaseLiteException
CouchbaseLiteException
public void createIndex(@NonNull String name, @NonNull Index idx) throws CouchbaseLiteException
CouchbaseLiteException
public void deleteIndex(@NonNull String name) throws CouchbaseLiteException
CouchbaseLiteException
public boolean performMaintenance(MaintenanceType type) throws CouchbaseLiteException
CouchbaseLiteException