Search in sources :

Example 1 with Settings

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);
}
Also used : Converter(org.eclipse.microprofile.config.spi.Converter) Collectors.toMap(java.util.stream.Collectors.toMap) StreamSupport.stream(java.util.stream.StreamSupport.stream) Predicate(java.util.function.Predicate) Map(java.util.Map) BeanManagers(org.eclipse.jnosql.mapping.util.BeanManagers) Settings(jakarta.nosql.Settings) Config(org.eclipse.microprofile.config.Config) Spliterator(java.util.Spliterator) StringUtils(org.eclipse.jnosql.mapping.util.StringUtils) Config(org.eclipse.microprofile.config.Config)

Example 2 with 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");
}
Also used : Settings(jakarta.nosql.Settings) Test(org.junit.jupiter.api.Test)

Example 3 with Settings

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);
}
Also used : SettingsConverter(org.eclipse.jnosql.mapping.configuration.SettingsConverter) ConfigurationException(org.eclipse.jnosql.mapping.configuration.ConfigurationException) Config(org.eclipse.microprofile.config.Config) DocumentConfiguration(jakarta.nosql.document.DocumentConfiguration) Settings(jakarta.nosql.Settings) Reflections(org.eclipse.jnosql.mapping.reflection.Reflections)

Example 4 with Settings

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);
}
Also used : GraphConfiguration(org.eclipse.jnosql.mapping.graph.GraphConfiguration) SettingsConverter(org.eclipse.jnosql.mapping.configuration.SettingsConverter) ConfigurationException(org.eclipse.jnosql.mapping.configuration.ConfigurationException) Config(org.eclipse.microprofile.config.Config) Settings(jakarta.nosql.Settings) Reflections(org.eclipse.jnosql.mapping.reflection.Reflections)

Example 5 with Settings

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());
}
Also used : Settings(jakarta.nosql.Settings) Test(org.junit.jupiter.api.Test)

Aggregations

Settings (jakarta.nosql.Settings)42 Test (org.junit.jupiter.api.Test)34 MongoCredential (com.mongodb.MongoCredential)6 Config (org.eclipse.microprofile.config.Config)5 Map (java.util.Map)4 ConfigurationException (org.eclipse.jnosql.mapping.configuration.ConfigurationException)4 SettingsConverter (org.eclipse.jnosql.mapping.configuration.SettingsConverter)4 Reflections (org.eclipse.jnosql.mapping.reflection.Reflections)4 SettingsBuilder (jakarta.nosql.Settings.SettingsBuilder)3 ColumnFamilyManagerFactory (jakarta.nosql.column.ColumnFamilyManagerFactory)3 DocumentConfiguration (jakarta.nosql.document.DocumentConfiguration)2 AbstractMap (java.util.AbstractMap)2 ArrayList (java.util.ArrayList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 ConnectionString (com.mongodb.ConnectionString)1 MongoClientSettings (com.mongodb.MongoClientSettings)1 ServerAddress (com.mongodb.ServerAddress)1 MongoClient (com.mongodb.client.MongoClient)1 MongoClients (com.mongodb.client.MongoClients)1 Configurations (jakarta.nosql.Configurations)1