Search in sources :

Example 26 with Settings

use of jakarta.nosql.Settings in project jnosql-diana by eclipse.

the class SettingsConverterTest method shouldLoadEmptySettings.

@Test
public void shouldLoadEmptySettings() {
    System.setProperty("database", "prefix");
    final Settings settings = config.getValue("database", Settings.class);
    Assertions.assertNotNull(settings);
    assertEquals(0, settings.size());
    System.clearProperty("database");
}
Also used : Settings(jakarta.nosql.Settings) Test(org.junit.jupiter.api.Test)

Example 27 with Settings

use of jakarta.nosql.Settings in project jnosql-diana by eclipse.

the class SettingsConverterTest method shouldSettings.

@Test
public void shouldSettings() {
    final String prefix = UUID.randomUUID().toString();
    System.setProperty(prefix, prefix);
    System.setProperty(prefix + ".settings.key", "value");
    System.setProperty(prefix + ".settings.key2", "value2");
    final Settings settings = config.getValue(prefix, Settings.class);
    Assertions.assertNotNull(settings);
    assertEquals(2, 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");
}
Also used : Settings(jakarta.nosql.Settings) Test(org.junit.jupiter.api.Test)

Example 28 with Settings

use of jakarta.nosql.Settings in project jnosql-diana-driver by eclipse.

the class MongoDBDocumentConfiguration method get.

@Override
public MongoDBDocumentCollectionManagerFactory get(Settings settings) throws NullPointerException {
    requireNonNull(settings, "settings is required");
    List<ServerAddress> servers = settings.prefix(Arrays.asList(OldMongoDBDocumentConfigurations.HOST.get(), MongoDBDocumentConfigurations.HOST.get(), Configurations.HOST.get())).stream().map(Object::toString).map(HostPortConfiguration::new).map(HostPortConfiguration::toServerAddress).collect(Collectors.toList());
    if (servers.isEmpty()) {
        Optional<ConnectionString> connectionString = settings.get(MongoDBDocumentConfigurations.URL.get(), String.class).map(ConnectionString::new);
        return connectionString.map(c -> MongoClientSettings.builder().applyConnectionString(c).build()).map(MongoClients::create).map(MongoDBDocumentCollectionManagerFactory::new).orElseGet(() -> new MongoDBDocumentCollectionManagerFactory(MongoClients.create()));
    }
    Optional<MongoCredential> credential = MongoAuthentication.of(settings);
    final MongoClientSettings mongoClientSettings = credential.map(c -> MongoClientSettings.builder().credential(c).applyToClusterSettings(builder -> builder.hosts(servers))).orElseGet(() -> MongoClientSettings.builder().applyToClusterSettings(builder -> builder.hosts(servers))).build();
    return new MongoDBDocumentCollectionManagerFactory(MongoClients.create(mongoClientSettings));
}
Also used : ServerAddress(com.mongodb.ServerAddress) Arrays(java.util.Arrays) MongoCredential(com.mongodb.MongoCredential) MongoClient(com.mongodb.client.MongoClient) SettingsBuilder(jakarta.nosql.Settings.SettingsBuilder) MongoClients(com.mongodb.client.MongoClients) DocumentConfiguration(jakarta.nosql.document.DocumentConfiguration) Settings(jakarta.nosql.Settings) Collectors(java.util.stream.Collectors) ConfigurationReader(org.eclipse.jnosql.communication.driver.ConfigurationReader) List(java.util.List) ConnectionString(com.mongodb.ConnectionString) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) Configurations(jakarta.nosql.Configurations) MongoClientSettings(com.mongodb.MongoClientSettings) MongoClients(com.mongodb.client.MongoClients) MongoCredential(com.mongodb.MongoCredential) ServerAddress(com.mongodb.ServerAddress) ConnectionString(com.mongodb.ConnectionString) MongoClientSettings(com.mongodb.MongoClientSettings) ConnectionString(com.mongodb.ConnectionString)

Example 29 with Settings

use of jakarta.nosql.Settings in project jnosql-diana-driver by eclipse.

the class MongoAuthenticationTest method shouldReturnOneAuthenticationWithGSSAPI.

@Test
public void shouldReturnOneAuthenticationWithGSSAPI() {
    Settings settings = Settings.builder().put(AUTHENTICATION_SOURCE.get(), "database").put(PASSWORD.get(), "password").put(USER.get(), "user").put(AUTHENTICATION_MECHANISM.get(), "GSSAPI").build();
    MongoCredential credential = MongoAuthentication.of(settings).get();
    assertEquals("$external", credential.getSource());
    assertEquals("user", credential.getUserName());
    assertEquals(GSSAPI.getMechanismName(), credential.getMechanism());
}
Also used : MongoCredential(com.mongodb.MongoCredential) Settings(jakarta.nosql.Settings) Test(org.junit.jupiter.api.Test)

Example 30 with Settings

use of jakarta.nosql.Settings in project jnosql-diana-driver by eclipse.

the class CassandraProperties method of.

public static CassandraProperties of(Map<String, String> configurations) {
    SettingsBuilder builder = Settings.builder();
    configurations.entrySet().forEach(e -> builder.put(e.getKey(), e.getValue()));
    Settings settings = builder.build();
    CassandraProperties cp = new CassandraProperties();
    settings.prefix(Arrays.asList(OldCassandraConfigurations.HOST.get(), CassandraConfigurations.HOST.get(), Configurations.HOST.get())).stream().map(Object::toString).forEach(cp::addNodes);
    settings.prefix(Arrays.asList(OldCassandraConfigurations.QUERY.get(), CassandraConfigurations.QUERY.get())).stream().map(Object::toString).forEach(cp::addQuery);
    cp.port = settings.get(Arrays.asList(OldCassandraConfigurations.PORT.get(), CassandraConfigurations.PORT.get())).map(Object::toString).map(Integer::parseInt).orElse(DEFAULT_PORT);
    cp.name = settings.get(Arrays.asList(OldCassandraConfigurations.NAME.get(), CassandraConfigurations.NAME.get())).map(Object::toString);
    cp.dataCenter = settings.get(CassandraConfigurations.DATA_CENTER.get()).map(Object::toString).orElse(DEFAULT_DATA_CENTER);
    cp.user = settings.get(Configurations.USER.get()).map(Object::toString);
    cp.password = settings.get(Configurations.PASSWORD.get()).map(Object::toString);
    return cp;
}
Also used : SettingsBuilder(jakarta.nosql.Settings.SettingsBuilder) Settings(jakarta.nosql.Settings)

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