Configuration
The EmbeddedStorageManager
is mostly created with factory methods of EmbeddedStorage
, where the most common settings, like database directory or the root instance, can be configured.
EmbeddedStorageManager storageManager = EmbeddedStorage.start(
myRoot, // root object of entity graph
Paths.get("data-dir") // storage data directory
);
Foundations
To achieve a more detailed customization, you can utilize the EmbeddedStorageFoundation
factory type.
It holds and creates on demand all the parts that form an EmbeddedStorageManager
.
NioFileSystem fileSystem = NioFileSystem.New();
EmbeddedStorageManager storageManager = EmbeddedStorageFoundation.New()
.setConfiguration(
StorageConfiguration.Builder()
.setStorageFileProvider(
Storage.FileProviderBuilder(fileSystem)
.setDirectory(fileSystem.ensureDirectoryPath("storageDir"))
.createFileProvider()
)
.setChannelCountProvider(StorageChannelCountProvider.New(4))
.setBackupSetup(StorageBackupSetup.New(
fileSystem.ensureDirectoryPath("backupDir")
))
.createConfiguration()
)
.createEmbeddedStorageManager();
External Configuration
The artifact storage-embedded-configuration
provides a convenience layer for configuration purposes, as well as facilities to read external configuration.
<dependencies>
<dependency>
<groupId>org.eclipse.store</groupId>
<artifactId>storage-embedded-configuration</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
The EmbeddedStorageConfigurationBuilder
type consolidates the most widely used parameters from the storage foundations in one place.
It’s output is an EmbeddedStorageFoundation
from which a EmbeddedStorageManager
can be created.
EmbeddedStorageManager storageManager = EmbeddedStorageConfiguration.Builder()
.setStorageDirectoryInUserHome("data-dir")
.setBackupDirectory("backup-dir")
.setChannelCount(4)
.createEmbeddedStorageFoundation()
.createEmbeddedStorageManager();
To read an external configuration use ConfigurationLoader
and ConfigurationParser
or the load*()
methods of EmbeddedStorageConfiguration
.
Out of the box, XML and INI files are supported.
EmbeddedStorageManager storageManager = EmbeddedStorageConfiguration.load(
"/META-INF/eclipsestore/storage.xml"
)
.createEmbeddedStorageFoundation()
.createEmbeddedStorageManager();
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<property name="storage-directory" value ="data" />
<property name="channel-count" value ="4" />
</properties>
EmbeddedStorageManager storageManager = EmbeddedStorageConfiguration.load(
"/META-INF/eclipsestore/storage.ini"
)
.createEmbeddedStorageFoundation()
.createEmbeddedStorageManager();
storage-directory = data
channel-count = 4
If you just use EmbeddedStorageConfiguration.load()
the default configuration file is used, which is either a file in the classpath root named eclipsestore.properties
, or the path configured via the system property org.eclipse.store.configuration.path
.
The full example can be found on GitHub. |
Additional Formats
The EmbeddedStorageConfigurationBuilder
is based on the common configuration layer.
The artifact configuration
, which is a dependency of storage.embedded.configuration
, contains support for XML and INI files.
Other formats are available in different artifacts.
Artifact | Formats |
---|---|
configuration-hocon |
hocon, json |
configuration-yaml |
yaml |
EmbeddedStorageManager storageManager = EmbeddedStorageConfiguration.load(
ConfigurationLoader.New("/META-INF/eclipsestore/storage.yaml"),
ConfigurationParserYaml.New()
)
.createEmbeddedStorageFoundation()
.createEmbeddedStorageManager();
storage-directory: "data"
channel-count: 4
EmbeddedStorageManager storageManager = EmbeddedStorageConfiguration.load(
ConfigurationLoader.New("/META-INF/eclipsestore/storage.json"),
ConfigurationParserHocon.New()
)
.createEmbeddedStorageFoundation()
.createEmbeddedStorageManager();
{
"storage-directory": "data",
"channel-count": 4
}