public final class Database extends Object
| 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) |
ListenerToken |
addDocumentChangeListener(String id,
DocumentChangeListener listener)
Add the given DocumentChangeListener to the specified document.
|
ListenerToken |
addDocumentChangeListener(String id,
Executor executor,
DocumentChangeListener listener) |
void |
changeEncryptionKey(EncryptionKey encryptionKey)
ENTERPRISE EDITION API
|
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) |
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.
|
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 |
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.
|
static void |
setLogLevel(LogDomain domain,
LogLevel level)
Set log level for the given log domain.
|
String |
toString() |
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 void changeEncryptionKey(EncryptionKey encryptionKey) throws CouchbaseLiteException
Changes the database's encryption key, or removes encryption if the new key is null.
encryptionKey - The encryption keyCouchbaseLiteExceptionpublic 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.CouchbaseLiteExceptionpublic boolean save(MutableDocument document, ConcurrencyControl concurrencyControl) throws CouchbaseLiteException
document - The document.concurrencyControl - The concurrency control.CouchbaseLiteExceptionpublic void delete(Document document) throws CouchbaseLiteException
document - The document.CouchbaseLiteExceptionpublic boolean delete(Document document, ConcurrencyControl concurrencyControl) throws CouchbaseLiteException
document - The document.concurrencyControl - The concurrency control.CouchbaseLiteExceptionpublic void purge(Document document) throws CouchbaseLiteException
document - CouchbaseLiteExceptionpublic 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 - public ListenerToken addChangeListener(Executor executor, DatabaseChangeListener listener)
public void removeChangeListener(ListenerToken token)
token - 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
CouchbaseLiteExceptionpublic 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.public static void copy(File path, String name, DatabaseConfiguration config) throws CouchbaseLiteException
CouchbaseLiteExceptionpublic static void setLogLevel(LogDomain domain, LogLevel level)
domain - The log domainlevel - The log level