DatabaseFactory Class
It’s the entry point class that allows to create and open a database.
A DatabaseFactory object doesn’t keep any state and its only goal is creating a Database instance.
Example:
DatabaseFactory factory = new DatabaseFactory("/databases/mydb");
Methods
close()
Close a database factory. This method frees some resources, but it’s not necessary to call it to unlock the databases.
Syntax:
void close()
Database create()
Creates a new database. If the database already exists, an exception is thrown.
Example:
DatabaseFactory arcade = new DatabaseFactory("/databases/mydb");
Database db = arcade.create();
Database open()
Opens an existent database in READ_WRITE mode. If the database does not exist, an exception is thrown.
Example:
DatabaseFactory arcade = new DatabaseFactory("/databases/mydb");
try( Database db = arcade.open(); ) {
// YOUR CODE
}
Database open(MODE mode)
Opens an existent database by specifying a mode between READ_WRITE and READ_ONLY mode. If the database does not exist, an exception is thrown. In READ_ONLY mode, any attempt to modify the database throws an exception.
Example:
DatabaseFactory arcade = new DatabaseFactory("/databases/mydb");
Database db = arcade.open(MODE.READ_ONLY);
try {
// YOUR CODE
} finally {
db.close();
}