public final class Database extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Database.LogDomain
Log domain.
|
static class |
Database.LogLevel
Log level.
|
| Constructor and Description |
|---|
Database(String name,
DatabaseConfiguration config)
Construct a Database 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 |
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,
com.couchbase.lite.Index index) |
void |
delete()
Deletes a database.
|
void |
delete(Document document)
Delete the givin document.
|
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.
|
int |
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
|
File |
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.
|
Document |
save(MutableDocument document)
Saves the given document to the database.
|
void |
setEncryptionKey(EncryptionKey encryptionKey)
Changes the database's encryption key, or removes encryption if the new key is null.
|
static void |
setLogLevel(Database.LogDomain domain,
Database.LogLevel level) |
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 String getName()
public File getPath()
public int getCount()
public DatabaseConfiguration getConfig()
public Document getDocument(String id)
id - the document IDpublic Document save(MutableDocument document) throws CouchbaseLiteException
document - CouchbaseLiteExceptionpublic void delete(Document document) throws CouchbaseLiteException
document - 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 void setEncryptionKey(EncryptionKey encryptionKey) throws CouchbaseLiteException
encryptionKey - The encryption keyCouchbaseLiteExceptionpublic List<String> getIndexes() throws CouchbaseLiteException
CouchbaseLiteExceptionpublic void createIndex(String name, com.couchbase.lite.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(Database.LogDomain domain, Database.LogLevel level)