public final class Database extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Database.LogDomain |
static class |
Database.LogLevel |
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 docID,
DocumentChangeListener listener)
Add the given DocumentChangeListener to the specified document.
|
ListenerToken |
addDocumentChangeListener(String docID,
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
|
boolean |
contains(String documentID) |
static void |
copy(File path,
String name,
DatabaseConfiguration config) |
void |
createIndex(String name,
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.
|
protected void |
finalize() |
Set<LiveQuery> |
getActiveLiveQueries() |
DatabaseConfiguration |
getConfig()
Returned the copied config object
|
int |
getCount()
The number of documents in the database.
|
Document |
getDocument(String documentID)
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 action)
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, or null for the default config.CouchbaseLiteException
- 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 documentID)
documentID
- the document IDpublic boolean contains(String documentID)
public Document save(MutableDocument document) throws CouchbaseLiteException
document
- CouchbaseLiteException
public void delete(Document document) throws CouchbaseLiteException
document
- CouchbaseLiteException
public void purge(Document document) throws CouchbaseLiteException
document
- CouchbaseLiteException
public void inBatch(Runnable action) throws CouchbaseLiteException
action
- the action which is implementation of Runnable interfaceCouchbaseLiteException
- Throws an exception if any error occurs during the operation.public void compact() throws CouchbaseLiteException
CouchbaseLiteException
public ListenerToken addChangeListener(DatabaseChangeListener listener)
listener
- public ListenerToken addChangeListener(Executor executor, DatabaseChangeListener listener)
public void removeChangeListener(ListenerToken token)
token
- public ListenerToken addDocumentChangeListener(String docID, DocumentChangeListener listener)
public ListenerToken addDocumentChangeListener(String docID, 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 keyCouchbaseLiteException
public List<String> getIndexes() throws CouchbaseLiteException
CouchbaseLiteException
public void createIndex(String name, Index index) throws CouchbaseLiteException
CouchbaseLiteException
public void deleteIndex(String name) throws CouchbaseLiteException
CouchbaseLiteException
public 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
CouchbaseLiteException
public static void setLogLevel(Database.LogDomain domain, Database.LogLevel level)
protected void finalize() throws Throwable
public Set<LiveQuery> getActiveLiveQueries()