use of jakarta.nosql.Settings in project jnosql-diana by eclipse.
the class SettingsConverter method success.
@Override
public Settings success(String value) {
Config config = BeanManagers.getInstance(Config.class);
final Spliterator<String> spliterator = config.getPropertyNames().spliterator();
final String settingsPrefix = getSettingsPrefix(value);
final Map<String, Object> settings = stream(spliterator, false).filter(isSettings(settingsPrefix)).distinct().collect(toMap(s -> s.replace(value + ".settings.", ""), s -> config.getValue(s, String.class)));
return Settings.of(settings);
}
use of jakarta.nosql.Settings in project jnosql-diana by eclipse.
the class SettingsConverterTest method shouldReturnNotDuplicatedValue.
@Test
public void shouldReturnNotDuplicatedValue() {
final String prefix = "database";
System.setProperty(prefix, prefix);
System.setProperty("database.settings.jakarta.nosql.host", "updated");
System.setProperty(prefix + ".settings.key2", "value2");
System.setProperty(prefix + ".settings.key", "value");
final Settings settings = config.getValue(prefix, Settings.class);
Assertions.assertNotNull(settings);
assertEquals(3, settings.size());
assertEquals(settings.get("key").get(), "value");
assertEquals(settings.get("key2").get(), "value2");
System.clearProperty(prefix);
System.clearProperty(prefix + ".settings.key");
System.clearProperty(prefix + ".settings.key2");
System.clearProperty("database.settings.jakarta.nosql.host");
}
use of jakarta.nosql.Settings in project jnosql-diana by eclipse.
the class DocumentCollectionManagerFactoryConverter method success.
@Override
public DocumentCollectionManagerFactory success(String value) {
final SettingsConverter settingsConverter = BeanManagers.getInstance(SettingsConverter.class);
Config config = BeanManagers.getInstance(Config.class);
final Settings settings = settingsConverter.convert(value);
String provider = value + ".provider";
final Class<?> configurationClass = config.getValue(provider, Class.class);
if (DocumentConfiguration.class.isAssignableFrom(configurationClass)) {
final Reflections reflections = BeanManagers.getInstance(Reflections.class);
final DocumentConfiguration configuration = (DocumentConfiguration) reflections.newInstance(configurationClass);
return configuration.get(settings);
}
throw new ConfigurationException("The class " + configurationClass + " is not valid to " + DocumentConfiguration.class);
}
use of jakarta.nosql.Settings in project jnosql-diana by eclipse.
the class GraphConverter method success.
@Override
protected Graph success(String value) {
final SettingsConverter settingsConverter = BeanManagers.getInstance(SettingsConverter.class);
Config config = BeanManagers.getInstance(Config.class);
final Settings settings = settingsConverter.convert(value);
final String provider = value + ".provider";
final Class<?> configurationClass = config.getValue(provider, Class.class);
if (GraphConfiguration.class.isAssignableFrom(configurationClass)) {
final Reflections reflections = BeanManagers.getInstance(Reflections.class);
final GraphConfiguration configuration = (GraphConfiguration) reflections.newInstance(configurationClass);
return configuration.apply(settings);
}
throw new ConfigurationException("The class " + configurationClass + " is not valid to " + GraphConfiguration.class);
}
use of jakarta.nosql.Settings in project jnosql-diana by eclipse.
the class DefaultSettingsTest method shouldIsEmpty.
@Test
public void shouldIsEmpty() {
Settings settings = Settings.of(singletonMap("key", "value"));
assertFalse(settings.isEmpty());
settings = Settings.of(Collections.emptyMap());
assertTrue(settings.isEmpty());
}
Aggregations