Package com.couchbase.lite
Class Database
java.lang.Object
com.couchbase.lite.BaseDatabase
com.couchbase.lite.Database
- All Implemented Interfaces:
AutoCloseable
A Couchbase Lite database.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.couchbase.lite.internal.ImmutableDatabaseConfigurationstatic final PredictionENTERPRISE EDITION API -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a Database with a given name and the default config.Database(String name, DatabaseConfiguration config) Construct a Database with a given name and database config. -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeEncryptionKey(EncryptionKey encryptionKey) ENTERPRISE EDITION APIvoidclose()Closes a database.static voidcopy(File path, String name, DatabaseConfiguration config) Make a copy of a database in a new location.protected static voidfinal CollectioncreateCollection(String name) Create a named collection in the default scope.final CollectioncreateCollection(String collectionName, String scopeName) Create a named collection in the specified scope.createQuery(String query) Create a SQL++ query.voiddelete()Deletes a database.static voidDeletes a database of the given name in the given directory.final voiddeleteCollection(String name) Delete a collection by name in the default scope.final voiddeleteCollection(String collectionName, String scopeName) Delete a collection by name in the specified scope.booleanstatic booleanChecks whether a database of the given name exists in the given directory or not.protected voidfinalize()(UNCOMMITTED) Use this API if you are developing Javascript language bindings.final CollectiongetCollection(String name) Get a collection in the default scope by name.final CollectiongetCollection(String collectionName, String scopeName) Get a collection in the specified scope by name.final Set<Collection>Get all collections in the default scope.final Set<Collection>getCollections(String scopeName) Get all collections in the named scope.Returns a copy of the database configuration.protected Databasefinal CollectionGet the default collection.final ScopeGet the default scope.getName()Return the database namegetPath()The database's absolute pathfinal ScopeGet a scope object by name.Get scope names that have at least one collection.inthashCode()<T extends Exception>
voidinBatch(UnitOfWork<T> work) Runs a group of database operations in a batch.booleanvoid(UNCOMMITTED) Use this API if you are developing Javascript language bindings.toString()Methods inherited from class com.couchbase.lite.BaseDatabase
assertOpenChecked, assertOpenUnchecked, getBlobStore, getC4DbOrThrowLocked, getDbLock, getDbPath, getOpenC4DbLocked, isOpen, isOpenLocked, setC4DatabaseLocked
-
Field Details
-
prediction
ENTERPRISE EDITION API
The predictive model manager for registering and unregistering predictive models.
-
config
@NonNull protected final com.couchbase.lite.internal.ImmutableDatabaseConfiguration config
-
-
Constructor Details
-
Database
Construct a Database with a given name and the default config. If the database does not yet exist it will be created.- Parameters:
name- The name of the database: May NOT contain capital letters!- Throws:
CouchbaseLiteException- if any error occurs during the open operation.
-
Database
public Database(@NonNull String name, @NonNull DatabaseConfiguration config) throws CouchbaseLiteException Construct a Database with a given name and database config. If the database does not yet exist, it will be created, unless the `readOnly` option is used.- Parameters:
name- The name of the database: May NOT contain capital letters!config- The database config.- Throws:
CouchbaseLiteException- Throws an exception if any error occurs during the open operation.
-
-
Method Details
-
copy
public static void copy(@NonNull File path, @NonNull String name, @NonNull DatabaseConfiguration config) throws CouchbaseLiteException Make a copy of a database in a new location. It is recommended that this method not be used on an open database.- Parameters:
path- path to the existing db filename- the name of the new DBconfig- a config with the new location- Throws:
CouchbaseLiteException- on copy failure
-
changeEncryptionKey
ENTERPRISE EDITION API
Changes the database's encryption key, or removes encryption if the new key is null.
- Parameters:
encryptionKey- The encryption key- Throws:
CouchbaseLiteException- on error
-
getDatabase
-
delete
public static void delete(@NonNull String name, @Nullable File directory) throws CouchbaseLiteException Deletes a database of the given name in the given directory.- Parameters:
name- the database's namedirectory- the directory containing the database: the database's parent directory.- Throws:
CouchbaseLiteException- Throws an exception if any error occurs during the operation.
-
exists
Checks whether a database of the given name exists in the given directory or not.- Parameters:
name- the database's namedirectory- the path where the database is located.- Returns:
- true if exists, false otherwise.
-
copy
protected static void copy(@NonNull File path, @NonNull String name, @NonNull String dbDir, int algorithm, byte[] encryptionKey) throws CouchbaseLiteException - Throws:
CouchbaseLiteException
-
getName
Return the database name- Returns:
- the database's name
-
getPath
The database's absolute path- Returns:
- the database's path or null if the database is closed.
-
performMaintenance
- Throws:
CouchbaseLiteException
-
close
Closes a database. Closing a database will stop all replicators, live queries and all listeners attached to it.- Specified by:
closein interfaceAutoCloseable- Throws:
CouchbaseLiteException- Throws an exception if any error occurs during the operation.
-
delete
Deletes a database. Deleting a database will stop all replicators, live queries and all listeners attached to it. Although attempting to close a closed database is not an error, attempting to delete a closed database is.- Throws:
CouchbaseLiteException- Throws an exception if any error occurs during the operation.
-
getScopes
Get scope names that have at least one collection. Note: the default scope is exceptional as it will always be listed even though there are no collections under it.- Throws:
CouchbaseLiteException
-
getScope
Get a scope object by name. As the scope cannot exist by itself without having a collection, the hull value will be returned if there are no collections under the given scope’s name. Note: The default scope is exceptional, and it will always be returned.- Throws:
CouchbaseLiteException
-
getDefaultScope
Get the default scope.- Throws:
CouchbaseLiteException
-
createCollection
@NonNull public final Collection createCollection(@NonNull String name) throws CouchbaseLiteException Create a named collection in the default scope. If the collection already exists, the existing collection will be returned.- Parameters:
name- the scope in which to create the collection- Returns:
- the named collection in the default scope
- Throws:
CouchbaseLiteException- on failure
-
createCollection
@NonNull public final Collection createCollection(@NonNull String collectionName, @Nullable String scopeName) throws CouchbaseLiteException Create a named collection in the specified scope. If the collection already exists, the existing collection will be returned.- Parameters:
collectionName- the name of the new collectionscopeName- the scope in which to create the collection- Returns:
- the named collection in the default scope
- Throws:
CouchbaseLiteException- on failure
-
getCollections
Get all collections in the default scope.- Throws:
CouchbaseLiteException
-
getCollections
@NonNull public final Set<Collection> getCollections(@Nullable String scopeName) throws CouchbaseLiteException Get all collections in the named scope.- Parameters:
scopeName- the scope name- Returns:
- the collections in the named scope
- Throws:
CouchbaseLiteException
-
getCollection
Get a collection in the default scope by name. If the collection doesn't exist, the function will return null.- Parameters:
name- the collection to find- Returns:
- the named collection or null
- Throws:
CouchbaseLiteException
-
getCollection
@Nullable public final Collection getCollection(@NonNull String collectionName, @Nullable String scopeName) throws CouchbaseLiteException Get a collection in the specified scope by name. If the collection doesn't exist, the function will return null.- Parameters:
collectionName- the collection to findscopeName- the scope in which to create the collection- Returns:
- the named collection or null
- Throws:
CouchbaseLiteException
-
getDefaultCollection
Get the default collection.- Returns:
- the default collection.
- Throws:
CouchbaseLiteException
-
deleteCollection
Delete a collection by name in the default scope. If the collection doesn't exist, the operation will do nothing. Note: the default collection cannot be deleted.- Parameters:
name- the collection to be deleted- Throws:
CouchbaseLiteException- on failure
-
deleteCollection
public final void deleteCollection(@NonNull String collectionName, @Nullable String scopeName) throws CouchbaseLiteException Delete a collection by name in the specified scope. If the collection doesn't exist, the operation will do nothing. Note: the default collection cannot be deleted.- Parameters:
collectionName- the collection to be deletedscopeName- the scope from which to delete the collection- Throws:
CouchbaseLiteException- on failure
-
inBatch
public <T extends Exception> void inBatch(@NonNull UnitOfWork<T> work) throws CouchbaseLiteException, T Runs a group of database operations in a batch. Use this when performing bulk write operations like multiple inserts/updates; it saves the overhead of multiple database commits, greatly improving performance.- Parameters:
work- a unit of work that may terminate abruptly (with an exception)- Throws:
CouchbaseLiteException- Throws an exception if any error occurs during the operation.T extends Exception
-
createQuery
Create a SQL++ query.- Parameters:
query- a valid SQL++ query- Returns:
- the Query object
- Throws:
CouchbaseLiteException
-
saveBlob
(UNCOMMITTED) Use this API if you are developing Javascript language bindings. If you are developing a native app, you must use theBlobAPI.- Parameters:
blob- a blob
-
getBlob
@Internal("This method is not part of the public API") @Nullable public Blob getBlob(@NonNull Map<String, Object> props) (UNCOMMITTED) Use this API if you are developing Javascript language bindings. If you are developing a native app, you must use theBlobAPI.- Parameters:
props- blob properties
-
getConfig
Returns a copy of the database configuration. Mutating the copy will not affect the configuration of the database- Returns:
- a copy of the database configuration
-
toString
-
hashCode
public int hashCode() -
equals
-
finalize
-