Class NitriteBuilder


  • public class NitriteBuilder
    extends Object
    The NitriteBuilder class provides a fluent API to configure and create a Nitrite database instance.
    Since:
    1.0
    Author:
    Anindya Chatterjee
    See Also:
    Nitrite
    • 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 an EntityConverter with the Nitrite database. An EntityConverter is used to convert between an entity and a Document. This method allows you to provide a custom converter for a specific class.
        Parameters:
        entityConverter - the EntityConverter 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 - the NitriteModule 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 username
        password - 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.