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.
|
| Constructor and Description |
|---|
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)
Set the given DatabaseChangeListener to the this database.
|
ListenerToken |
addChangeListener(Executor executor,
DatabaseChangeListener listener)
Set the given DatabaseChangeListener to the this database with an executor on which the
the changes will be posted to the listener.
|
ListenerToken |
addDocumentChangeListener(String id,
DocumentChangeListener listener)
Add the given DocumentChangeListener to the specified document.
|
ListenerToken |
addDocumentChangeListener(String id,
Executor executor,
DocumentChangeListener listener)
Add the given DocumentChangeListener to the specified document with an executor on which
the changes will be posted to the listener.
|
void |
close()
Closes a database.
|
void |
compact()
Compacts the database file by deleting unused attachment files and vacuuming the SQLite 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 |
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.
|
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)
Remove the given DatabaseChangeListener from the this 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 has
been replaced with a no-op to preserve API compatibility. |
String |
toString() |
public static final Log log
This is part of the Public API.
public Database(String name, DatabaseConfiguration config) throws CouchbaseLiteException
name - The name of the database. May NOT contain capital letters!config - The database config, Note: null config parameter is not allowed with Android platformCouchbaseLiteException - Throws an exception if any error occurs during the open operation.public static void copy(File path, String name, DatabaseConfiguration config) throws CouchbaseLiteException
path - where the db is nowname - the db's nameconfig - a config with the new locationCouchbaseLiteException - on copy failurepublic static void delete(String name, File directory) throws CouchbaseLiteException
name - the database's namedirectory - the path where the database is located.CouchbaseLiteException - Throws an exception if any error occurs during the operation.public static boolean exists(String name, File directory)
name - the database's namedirectory - the path where the database is located.@Deprecated public static void setLogLevel(LogDomain domain, LogLevel level)
getConsole method
from the log property. This method has
been replaced with a no-op to preserve API compatibility.domain - The log domainlevel - The log levelpublic String getName()
public String getPath()
public long getCount()
public DatabaseConfiguration getConfig()
public Document getDocument(String id)
id - the document IDpublic void save(MutableDocument document) throws CouchbaseLiteException
document - The document.CouchbaseLiteException - on errorpublic boolean save(MutableDocument document, ConcurrencyControl concurrencyControl) throws CouchbaseLiteException
document - The document.concurrencyControl - The concurrency control.CouchbaseLiteException - on errorpublic boolean save(MutableDocument document, ConflictHandler conflictHandler) throws CouchbaseLiteException
document - The document.conflictHandler - A conflict handler.CouchbaseLiteException - on errorpublic void delete(Document document) throws CouchbaseLiteException
document - The document.CouchbaseLiteException - on errorpublic boolean delete(Document document, ConcurrencyControl concurrencyControl) throws CouchbaseLiteException
document - The document.concurrencyControl - The concurrency control.CouchbaseLiteException - on errorpublic void purge(Document document) throws CouchbaseLiteException
document - the document to be purged.CouchbaseLiteExceptionpublic void purge(String id) throws CouchbaseLiteException
id - the document IDCouchbaseLiteExceptionpublic void setDocumentExpiration(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(String id) throws CouchbaseLiteException
id - The ID of the DocumentCouchbaseLiteException - Throws an exception if any error occurs during the operation.public void inBatch(Runnable runnable) throws CouchbaseLiteException
runnable - the action which is implementation of Runnable interfaceCouchbaseLiteException - Throws an exception if any error occurs during the operation.public void compact()
throws CouchbaseLiteException
CouchbaseLiteExceptionpublic ListenerToken addChangeListener(DatabaseChangeListener listener)
listener - callbackpublic ListenerToken addChangeListener(Executor executor, DatabaseChangeListener listener)
listener - callbackpublic void removeChangeListener(ListenerToken token)
token - returned by a previous call to addChangeListener or addDocumentListener.public ListenerToken addDocumentChangeListener(String id, DocumentChangeListener listener)
public ListenerToken addDocumentChangeListener(String id, Executor executor, 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.public List<String> getIndexes() throws CouchbaseLiteException
CouchbaseLiteExceptionpublic void createIndex(String name, Index index) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic void deleteIndex(String name) throws CouchbaseLiteException
CouchbaseLiteException