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 |
|---|---|
void |
addChangeListener(DatabaseChangeListener listener)
Set the given DatabaseChangeListener to the this database.
|
void |
addChangeListener(String docID,
DocumentChangeListener listener)
Add the given DocumentChangeListener to the specified document.
|
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() |
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(DatabaseChangeListener listener)
Remove the given DatabaseChangeListener from the this database.
|
void |
removeChangeListener(String docID,
DocumentChangeListener listener)
Remove the given DocumentChangeListener from the specified document.
|
void |
save(Document 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 void save(Document document) throws CouchbaseLiteException
document - CouchbaseLiteExceptionpublic void delete(Document document) throws CouchbaseLiteException
document - CouchbaseLiteExceptionpublic void purge(Document document) throws CouchbaseLiteException
document - CouchbaseLiteExceptionpublic 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
CouchbaseLiteExceptionpublic void addChangeListener(DatabaseChangeListener listener)
listener - public void removeChangeListener(DatabaseChangeListener listener)
listener - public void addChangeListener(String docID, DocumentChangeListener listener)
listener - public void removeChangeListener(String docID, DocumentChangeListener listener)
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, 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)