Package io.objectbox

Class BoxStoreBuilder

    • Field Detail


        public static final int DEFAULT_MAX_DB_SIZE_KBYTE
        The default maximum size the DB can grow to, which can be overwritten using maxSizeInKByte.
        See Also:
        Constant Field Values
    • Constructor Detail

      • BoxStoreBuilder

        public BoxStoreBuilder​(byte[] model)
    • Method Detail

      • createDebugWithoutModel

        public static BoxStoreBuilder createDebugWithoutModel()
        Not for application use.
      • baseDirectory

        public BoxStoreBuilder baseDirectory​( baseDirectory)
        In combination with name(String), this lets you specify the location of where the DB files should be stored. Cannot be used in combination with directory(File).
      • androidContext

        public BoxStoreBuilder androidContext​(java.lang.Object context)
        On Android, you can pass a Context to set the base directory using this method. This will conveniently configure the storage location to be in the files directory of your app.

        In more detail, this assigns the base directory (see baseDirectory) to context.getFilesDir() + "/objectbox/". Thus, when using the default name (also "objectbox" unless overwritten using name(String)), the default location of DB files will be "objectbox/objectbox/" inside the app files directory. If you specify a custom name, for example with name("foobar"), it would become "objectbox/foobar/".

        Alternatively, you can also use baseDirectory or directory(File) instead.

      • androidReLinker

        public BoxStoreBuilder androidReLinker​(java.lang.Object reLinkerInstance)
        Pass a custom ReLinkerInstance, for example ReLinker.log(logger) to use for loading the native library on Android devices. Note that setting androidContext(Object) is required for ReLinker to work.
      • maxReaders

        public BoxStoreBuilder maxReaders​(int maxReaders)
        Sets the maximum number of concurrent readers. For most applications, the default is fine (> 100 readers).

        A "reader" is short for a thread involved in a read transaction.

        If you hit DbMaxReadersExceededException, you should first worry about the amount of threads you are using. For highly concurrent setups (e.g. you are using ObjectBox on the server side) it may make sense to increase the number.

      • maxSizeInKByte

        public BoxStoreBuilder maxSizeInKByte​(long maxSizeInKByte)
        Sets the maximum size the database file can grow to. By default this is 1 GB, which should be sufficient for most applications.

        In general, a maximum size prevents the DB from growing indefinitely when something goes wrong (for example you insert data in an infinite loop).

      • debugTransactions

        public BoxStoreBuilder debugTransactions()
      • debugRelations

        public BoxStoreBuilder debugRelations()
        Enables some debug logging for relations.
      • queryAttempts

        public BoxStoreBuilder queryAttempts​(int queryAttempts)
        For massive concurrent setups (app is using a lot of threads), you can enable automatic retries for queries. This can resolve situations in which resources are getting sparse (e.g. DbMaxReadersExceededException or other variations of DbException are thrown during query execution).
        queryAttempts - number of attempts a query find operation will be executed before failing. Recommended values are in the range of 2 to 5, e.g. a value of 3 as a starting point.
      • initialDbFile

        public BoxStoreBuilder initialDbFile​( initialDbFile)
        Let's you specify an DB file to be used during initial start of the app (no DB file exists yet).
      • initialDbFile

        public BoxStoreBuilder initialDbFile​(Factory<> initialDbFileFactory)
        Let's you specify a provider for a DB file to be used during initial start of the app (no DB file exists yet). The provider will only be called if no DB file exists yet.
      • build

        public BoxStore build()
        Builds a BoxStore using any given configuration.