public class DatastoreManager
extends java.lang.Object
Manages a set of Datastore
objects, with their underlying disk
storage residing in a given directory.
In general, a directory used for storing datastores -- that is, managed by this manager -- shouldn't be used for storing other data. The manager object assumes all data within is managed by itself, so adding other files to the directory may cause them to be deleted.
A datastore's on-disk representation is a single file containing all its data. In future, there may be other files and folders per datastore.
Constructor and Description |
---|
DatastoreManager(java.io.File directoryPath)
Constructs a
DatastoreManager to manage a directory. |
DatastoreManager(java.lang.String directoryPath)
Constructs a
DatastoreManager to manage a directory. |
Modifier and Type | Method and Description |
---|---|
void |
deleteDatastore(java.lang.String dbName)
Deletes a datastore's files from disk.
|
EventBus |
getEventBus()
Returns the EventBus which this DatastoreManager posts
Database Notification Events to. |
java.lang.String |
getPath()
Returns the path to the directory this object manages.
|
java.util.List<java.lang.String> |
listAllDatastores()
Lists all the names of
Datastores managed by this DatastoreManager |
void |
onDatabaseClosed(DatabaseClosed databaseClosed) |
Datastore |
openDatastore(java.lang.String dbName)
Opens a datastore.
|
Datastore |
openDatastore(java.lang.String dbName,
KeyProvider provider)
Opens a datastore.
|
public DatastoreManager(java.lang.String directoryPath)
Constructs a DatastoreManager
to manage a directory.
Datastores are created within the directoryPath
directory.
In general, this folder should be under the control of, and only used
by, a single DatastoreManager
object at any time.
directoryPath
- root directory to manageDatastoreManager(java.io.File)
public DatastoreManager(java.io.File directoryPath)
Constructs a DatastoreManager
to manage a directory.
Datastores are created within the directoryPath
directory.
In general, this folder should be under the control of, and only used
by, a single DatastoreManager
object at any time.
directoryPath
- root directory to managejava.lang.IllegalArgumentException
- if the directoryPath
is not a
directory or isn't writable.public java.util.List<java.lang.String> listAllDatastores()
Datastores
managed by this DatastoreManagerDatastores
names.public java.lang.String getPath()
Returns the path to the directory this object manages.
public Datastore openDatastore(java.lang.String dbName) throws DatastoreNotCreatedException
Opens a datastore.
Equivalent to calling openDatastore(String, KeyProvider)
with
a NullKeyProvider
.
dbName
- name of datastore to openDatastore
with the given nameDatastoreNotCreatedException
- Thrown when
the datastore could not be created or opened.getEventBus()
public Datastore openDatastore(java.lang.String dbName, KeyProvider provider) throws DatastoreNotCreatedException
Opens a datastore.
Opens an existing datastore on disk, or creates a new one with the given name.
If encryption is enabled for this platform, passing a KeyProvider containing a non-null key will open or create an encrypted database. If opening a database, the key used to create the database must be used. If encryption is not enabled for this platform, returning a non-null key will result in an exception.
If there is no existing datastore with the given name, and one is successfully
created, a DatabaseOpened
event is posted on the event bus.
Datastores are uniqued: calling this method with the name of an already open datastore
will return the existing Datastore
object.
dbName
- name of datastore to openprovider
- KeyProvider object; use a NullKeyProvider if database shouldn't be encrypted.Datastore
with the given nameDatastoreNotCreatedException
- if the database cannot be openedgetEventBus()
public void deleteDatastore(java.lang.String dbName) throws java.io.IOException
Deletes a datastore's files from disk.
This operation deletes a datastore's files from disk. It is therefore a not undo-able. To confirm, this only deletes local data; data replicated to remote databases is not affected.
Any Datastore
objects referring to the deleted files will be
in an unknown state. Therefore, they should be disposed of prior to
deleting the data. Currently, no checks for open datastores are carried
out before attempting the delete.
If the datastore was successfully deleted, a
DatabaseDeleted
event is posted on the event bus.
dbName
- Name of database to createjava.io.IOException
- if the datastore doesn't exist on disk or there is
a problem deleting the files.getEventBus()
public EventBus getEventBus()
Returns the EventBus which this DatastoreManager posts
Database Notification Events
to.
public void onDatabaseClosed(DatabaseClosed databaseClosed)