Package org.dizitart.no2
Class NitriteBuilder
- java.lang.Object
-
- org.dizitart.no2.NitriteBuilder
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NitriteBuilder
addMigrations(Migration... migrations)
Adds one or more migrations to the Nitrite database.NitriteBuilder
fieldSeparator(String separator)
Sets the field separator character for Nitrite.NitriteConfig
getNitriteConfig()
The Nitrite configuration object.NitriteBuilder
loadModule(NitriteModule module)
Loads a Nitrite module into the Nitrite database.Nitrite
openOrCreate()
Opens or creates a new Nitrite database.Nitrite
openOrCreate(String username, String password)
Opens or creates a new Nitrite database with the given username and password.NitriteBuilder
registerEntityConverter(EntityConverter<?> entityConverter)
Registers anEntityConverter
with the Nitrite database.NitriteBuilder
schemaVersion(Integer version)
Sets the schema version for the Nitrite database.
-
-
-
Method Detail
-
fieldSeparator
public NitriteBuilder fieldSeparator(String separator)
Sets the field separator character for Nitrite. It is used to separate field names in a nested document. For example, if a document has a field address which is a nested document, then the field street of the nested document can be accessed using address.street syntax.The default value is [.].
- Parameters:
separator
- the field separator character to use- Returns:
- the NitriteBuilder instance
-
registerEntityConverter
public NitriteBuilder registerEntityConverter(EntityConverter<?> entityConverter)
Registers anEntityConverter
with the Nitrite database. AnEntityConverter
is used to convert between an entity and aDocument
. This method allows you to provide a custom converter for a specific class.- Parameters:
entityConverter
- theEntityConverter
to register- Returns:
- the NitriteBuilder instance
-
loadModule
public NitriteBuilder loadModule(NitriteModule module)
Loads a Nitrite module into the Nitrite database. The module can be used to extend the functionality of Nitrite.- Parameters:
module
- theNitriteModule
to be loaded- Returns:
- the
NitriteBuilder
instance
-
addMigrations
public NitriteBuilder addMigrations(Migration... migrations)
Adds one or more migrations to the Nitrite database. Migrations are used to upgrade the database schema when the application version changes.- Parameters:
migrations
- one or more migrations to add to the Nitrite database.- Returns:
- the NitriteBuilder instance.
-
schemaVersion
public NitriteBuilder schemaVersion(Integer version)
Sets the schema version for the Nitrite database.- Parameters:
version
- the schema version to set- Returns:
- the NitriteBuilder instance
-
openOrCreate
public Nitrite openOrCreate()
Opens or creates a new Nitrite database. If it is configured as in-memory database, then it will create a new database everytime. If it is configured as a file based database, and if the file does not exist, then it will create a new file store and open the database; otherwise it will open the existing database file.- Returns:
- the nitrite database instance.
- Throws:
NitriteIOException
- if unable to create a new in-memory database.NitriteIOException
- if the database is corrupt and recovery fails.IllegalArgumentException
- if the directory does not exist.
-
openOrCreate
public Nitrite openOrCreate(String username, String password)
Opens or creates a new Nitrite database with the given username and password. If it is configured as in-memory database, then it will create a new database everytime. If it is configured as a file based database, and if the file does not exist, then it will create a new file store and open the database; otherwise it will open the existing database file.NOTE: Both username and password must be provided or both must be null.
- Parameters:
username
- the usernamepassword
- the password- Returns:
- the nitrite database instance.
- Throws:
NitriteSecurityException
- if the user credentials are wrong or one of them is empty string.NitriteIOException
- if unable to create a new in-memory database.NitriteIOException
- if the database is corrupt and recovery fails.NitriteIOException
- if the directory does not exist.
-
getNitriteConfig
public NitriteConfig getNitriteConfig()
The Nitrite configuration object.
-
-