Skip to content

Commit 91d6623

Browse files
authored
Merge pull request #130 from eclipse/update_settings
Updates the API to use Settings
2 parents 9b49e06 + 8ba1d51 commit 91d6623

File tree

69 files changed

+1557
-484
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1557
-484
lines changed

arangodb-driver/src/main/java/org/jnosql/diana/arangodb/ArangoDBBuilderAsync.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020

2121
public class ArangoDBBuilderAsync implements ArangoDBBuilder {
2222

23-
private final ArangoDBAsync.Builder arangoDB = new ArangoDBAsync.Builder();
23+
private final ArangoDBAsync.Builder arangoDB;
24+
25+
26+
ArangoDBBuilderAsync(ArangoDBAsync.Builder builder) {
27+
this.arangoDB = builder;
28+
}
2429

2530
@Override
2631
public void host(String host, int port) {

arangodb-driver/src/main/java/org/jnosql/diana/arangodb/ArangoDBBuilderSync.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020

2121
public class ArangoDBBuilderSync implements ArangoDBBuilder {
2222

23-
private final ArangoDB.Builder arangoDB = new ArangoDB.Builder();
23+
private final ArangoDB.Builder arangoDB;
24+
25+
ArangoDBBuilderSync(ArangoDB.Builder arangoDB) {
26+
this.arangoDB = arangoDB;
27+
}
2428

2529
@Override
2630
public void host(String host, int port) {

arangodb-driver/src/main/java/org/jnosql/diana/arangodb/ArangoDBBuilders.java

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,72 @@
1616

1717
import com.arangodb.Protocol;
1818
import com.arangodb.entity.LoadBalancingStrategy;
19+
import org.jnosql.diana.api.Configurations;
1920
import org.jnosql.diana.api.Settings;
2021

2122
import java.util.Arrays;
2223
import java.util.List;
2324

24-
import static java.util.Optional.ofNullable;
25+
import static java.util.Arrays.asList;
26+
import static org.jnosql.diana.arangodb.ArangoDBConfigurations.CHUCK_SIZE;
27+
import static org.jnosql.diana.arangodb.ArangoDBConfigurations.HOST;
28+
import static org.jnosql.diana.arangodb.ArangoDBConfigurations.LOADBALANCING;
29+
import static org.jnosql.diana.arangodb.ArangoDBConfigurations.PASSWORD;
30+
import static org.jnosql.diana.arangodb.ArangoDBConfigurations.PROTOCOL;
31+
import static org.jnosql.diana.arangodb.ArangoDBConfigurations.TIMEOUT;
32+
import static org.jnosql.diana.arangodb.ArangoDBConfigurations.USER;
2533

2634
final class ArangoDBBuilders {
2735

28-
private static final String USER = "arangodb-user";
29-
private static final String PASSWORD = "arangodb-password";
30-
private static final String TIMEOUT = "arangodb-timeout";
31-
private static final String USER_SSL = "arangodb-userSsl";
32-
private static final String LOAD_BALANCING_STRATEGY = "arangodb.loadBalancingStrategy";
33-
private static final String PROTOCOL = "arangodb.protocol";
34-
private static final String CHUNK_CONTENT_SIZE = "arangodb.chunksize";
35-
private static final String MAX_CONNECTIONS = "arangodb.connections.max";
36-
private static final String ACQUIRE_HOST_LIST = "arangodb.acquireHostList";
37-
private static final String KEY_HOSTS = "arangodb.hosts";
3836

3937
private ArangoDBBuilders() {
4038
}
4139

4240
static void load(Settings settings, ArangoDBBuilder arangoDB) {
4341

44-
ofNullable(settings.get(USER)).map(Object::toString).ifPresent(arangoDB::user);
45-
ofNullable(settings.get(PASSWORD)).map(Object::toString).ifPresent(arangoDB::password);
46-
ofNullable(settings.get(TIMEOUT)).map(Object::toString).map(Integer::valueOf).ifPresent(arangoDB::timeout);
42+
settings.get(asList(USER.get(), Configurations.USER.get()))
43+
.map(Object::toString).ifPresent(arangoDB::user);
44+
settings.get(asList(PASSWORD.get(), Configurations.PASSWORD.get()))
45+
.map(Object::toString).ifPresent(arangoDB::password);
46+
settings.get(TIMEOUT.get())
47+
.map(Object::toString).map(Integer::valueOf).ifPresent(arangoDB::timeout);
4748

48-
ofNullable(settings.get(CHUNK_CONTENT_SIZE)).map(Object::toString).map(Integer::valueOf)
49+
settings.get(CHUCK_SIZE.get())
50+
.map(Object::toString).map(Integer::valueOf)
4951
.ifPresent(arangoDB::chunksize);
50-
ofNullable(settings.get(MAX_CONNECTIONS)).map(Object::toString).map(Integer::valueOf)
52+
53+
settings.get(ArangoDBConfigurations.MAX_CONNECTIONS.get())
54+
.map(Object::toString).map(Integer::valueOf)
5155
.ifPresent(arangoDB::maxConnections);
52-
ofNullable(settings.get(USER_SSL)).map(Object::toString).map(Boolean::valueOf)
56+
57+
settings.get(ArangoDBConfigurations.USERSSL.get())
58+
.map(Object::toString).map(Boolean::valueOf)
5359
.ifPresent(arangoDB::useSsl);
54-
ofNullable(settings.get(ACQUIRE_HOST_LIST)).map(Object::toString).map(Boolean::valueOf)
60+
61+
settings.get(ArangoDBConfigurations.HOST_LIST.get())
62+
.map(Object::toString).map(Boolean::valueOf)
5563
.ifPresent(arangoDB::acquireHostList);
56-
ofNullable(settings.get(LOAD_BALANCING_STRATEGY)).map(Object::toString).map(LoadBalancingStrategy::valueOf)
64+
65+
settings.get(LOADBALANCING.get()).map(Object::toString).map(LoadBalancingStrategy::valueOf)
5766
.ifPresent(arangoDB::loadBalancingStrategy);
58-
ofNullable(settings.get(PROTOCOL)).map(Object::toString).map(Protocol::valueOf)
59-
.ifPresent(arangoDB::useProtocol);
6067

61-
ofNullable(settings.get(KEY_HOSTS)).map(Object::toString)
62-
.map(ArangoDBHost::new).map(ArangoDBHost::getHost)
63-
.ifPresent(l ->feed(l, arangoDB));
68+
settings.get(PROTOCOL.get()).map(Object::toString).map(Protocol::valueOf)
69+
.ifPresent(arangoDB::useProtocol);
6470

71+
settings.prefix(Arrays.asList(HOST.get(), Configurations.HOST.get()))
72+
.stream()
73+
.map(Object::toString)
74+
.map(ArangoDBHost::new)
75+
.flatMap(h -> h.getHost().stream())
76+
.forEach(h -> host(arangoDB, h));
6577
}
6678

67-
private static void feed(List<String> hosts, ArangoDBBuilder arangoDB) {
68-
for (String host : hosts) {
69-
final String[] values = host.split(":");
70-
arangoDB.host(values[0], Integer.valueOf(values[0]));
71-
}
79+
80+
private static void host(ArangoDBBuilder arangoDB, String host) {
81+
final String[] values = host.split(":");
82+
arangoDB.host(values[0], Integer.valueOf(values[0]));
7283
}
84+
7385
private static class ArangoDBHost {
7486
private final String hots;
7587

@@ -78,7 +90,7 @@ private ArangoDBHost(String hots) {
7890
}
7991

8092
public List<String> getHost() {
81-
return Arrays.asList(this.hots.split(","));
93+
return asList(this.hots.split(","));
8294
}
8395
}
8496
}

arangodb-driver/src/main/java/org/jnosql/diana/arangodb/ArangoDBConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ public void asyncBuilder(ArangoDBAsync.Builder builderAsync) throws NullPointerE
133133
}
134134

135135
protected ArangoDB getArangoDB(Settings settings) {
136-
ArangoDBBuilderSync aragonDB = new ArangoDBBuilderSync();
136+
ArangoDBBuilderSync aragonDB = new ArangoDBBuilderSync(builder);
137137
ArangoDBBuilders.load(settings, aragonDB);
138138
return aragonDB.build();
139139
}
140140

141141
protected ArangoDBAsync getArangoDBAsync(Settings settings) {
142-
ArangoDBBuilderAsync aragonDB = new ArangoDBBuilderAsync();
142+
ArangoDBBuilderAsync aragonDB = new ArangoDBBuilderAsync(builderAsync);
143143
ArangoDBBuilders.load(settings, aragonDB);
144144
return aragonDB.build();
145145
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2019 Otávio Santana and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.jnosql.diana.arangodb;
16+
17+
import java.util.function.Supplier;
18+
19+
/**
20+
* This class has all the configurations on the arangoDB
21+
*/
22+
public enum ArangoDBConfigurations implements Supplier<String> {
23+
24+
HOST("arangodb.host"),
25+
USER("arangodb.user"),
26+
PASSWORD("arangodb.password"),
27+
TIMEOUT("arangodb.timeout"),
28+
CHUCK_SIZE("arangodb.chuck.size"),
29+
USERSSL("arangodb.userSsl"),
30+
LOADBALANCING("arangodb.loadBalancingStrategy"),
31+
PROTOCOL("arangodb.protocol"),
32+
MAX_CONNECTIONS("arangodb.connections.max"),
33+
HOST_LIST("arangodb.acquireHostList"),
34+
FILE_CONFIGURATION("diana-arangodb.properties");
35+
36+
37+
private final String configuration;
38+
39+
ArangoDBConfigurations(String configuration) {
40+
this.configuration = configuration;
41+
}
42+
43+
44+
@Override
45+
public String get() {
46+
return configuration;
47+
}
48+
}

arangodb-driver/src/main/java/org/jnosql/diana/arangodb/document/ArangoDBDocumentConfiguration.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,22 @@
1818
import com.arangodb.ArangoDB;
1919
import com.arangodb.ArangoDBAsync;
2020
import org.jnosql.diana.api.Settings;
21+
import org.jnosql.diana.api.SettingsBuilder;
2122
import org.jnosql.diana.api.document.UnaryDocumentConfiguration;
2223
import org.jnosql.diana.arangodb.ArangoDBConfiguration;
24+
import org.jnosql.diana.driver.ConfigurationReader;
25+
26+
import java.util.Map;
2327

2428
import static java.util.Objects.requireNonNull;
29+
import static org.jnosql.diana.arangodb.ArangoDBConfigurations.FILE_CONFIGURATION;
2530

2631
/**
2732
* The implementation of {@link UnaryDocumentConfiguration} that returns {@link ArangoDBDocumentCollectionManagerFactory}.
28-
* It tries to read the configuration properties from arangodb.properties file.
33+
* It tries to read the configuration properties from diana-arangodb.properties file.
2934
*
3035
* @see ArangoDBConfiguration
31-
* The Properties:
32-
* <p>arangodb-host: the host</p>
33-
* <p>arangodb-user: the user</p>
34-
* <p>arangodb-password: the password</p>
35-
* <p>arangodb-port: the port</p>
36-
* <p>arangodb-timeout: the timeout</p>
37-
* <p>arangodb-chuckSize: the chuckSize</p>
38-
* <p>arangodb-userSsl: the userSsl</p>
39-
* <p>arangodb-loadBalancingStrategy: the define loadBalancingStrategy</p>
40-
* <p>arangodb.hosts: the hosts</p>
41-
* <p>arangodb.protocol: the protocol</p>
42-
* <p>arangodb.chunksize: the chunksize</p>
43-
* <p>arangodb.connections.max: the max connection</p>
44-
* <p>arangodb.acquireHostList: the max connection</p>
36+
* @see org.jnosql.diana.arangodb.ArangoDBConfigurations
4537
*
4638
*/
4739
public class ArangoDBDocumentConfiguration extends ArangoDBConfiguration
@@ -50,7 +42,10 @@ public class ArangoDBDocumentConfiguration extends ArangoDBConfiguration
5042

5143
@Override
5244
public ArangoDBDocumentCollectionManagerFactory get() throws UnsupportedOperationException {
53-
return new ArangoDBDocumentCollectionManagerFactory(builder.build(), builderAsync.build());
45+
Map<String, String> configuration = ConfigurationReader.from(FILE_CONFIGURATION.get());
46+
SettingsBuilder builder = Settings.builder();
47+
configuration.entrySet().stream().forEach(e -> builder.put(e.getKey(), e.getValue()));
48+
return get(builder.build());
5449
}
5550

5651
@Override
@@ -64,7 +59,10 @@ public ArangoDBDocumentCollectionManagerFactory get(Settings settings) throws Nu
6459

6560
@Override
6661
public ArangoDBDocumentCollectionManagerFactory getAsync() throws UnsupportedOperationException {
67-
return new ArangoDBDocumentCollectionManagerFactory(builder.build(), builderAsync.build());
62+
Map<String, String> configuration = ConfigurationReader.from(FILE_CONFIGURATION.get());
63+
SettingsBuilder builder = Settings.builder();
64+
configuration.entrySet().stream().forEach(e -> builder.put(e.getKey(), e.getValue()));
65+
return getAsync(builder.build());
6866
}
6967

7068
@Override

arangodb-driver/src/main/java/org/jnosql/diana/arangodb/key/ArangoDBKeyValueConfiguration.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,30 @@
1717

1818
import com.arangodb.ArangoDB;
1919
import org.jnosql.diana.api.Settings;
20+
import org.jnosql.diana.api.SettingsBuilder;
2021
import org.jnosql.diana.api.key.KeyValueConfiguration;
2122
import org.jnosql.diana.arangodb.ArangoDBConfiguration;
23+
import org.jnosql.diana.driver.ConfigurationReader;
24+
25+
import java.util.Map;
26+
27+
import static org.jnosql.diana.arangodb.ArangoDBConfigurations.FILE_CONFIGURATION;
2228

2329
/**
2430
* The ArangoDB implementation to {@link KeyValueConfiguration}
25-
* The Properties:
26-
* <p>arangodb-host: the host</p>
27-
* <p>arangodb-user: the user</p>
28-
* <p>arangodb-password: the password</p>
29-
* <p>arangodb-port: the port</p>
30-
* <p>arangodb-timeout: the timeout</p>
31-
* <p>arangodb-chuckSize: the chuckSize</p>
32-
* <p>arangodb-userSsl: the userSsl</p>
33-
* <p>arangodb.hosts: the hosts</p>
34-
* <p>arangodb-loadBalancingStrategy: the define loadBalancingStrategy</p>
35-
* <p>arangodb.protocol: the protocol</p>
36-
* <p>arangodb.connections.max: the max connection</p>
31+
* It tries to read the configuration properties from diana-arangodb.properties file.
32+
*
33+
* @see org.jnosql.diana.arangodb.ArangoDBConfigurations
3734
*/
3835
public class ArangoDBKeyValueConfiguration extends ArangoDBConfiguration
3936
implements KeyValueConfiguration<ArangoDBBucketManagerFactory> {
4037

4138
@Override
4239
public ArangoDBBucketManagerFactory get() {
43-
return new ArangoDBBucketManagerFactory(builder.build());
40+
Map<String, String> configuration = ConfigurationReader.from(FILE_CONFIGURATION.get());
41+
SettingsBuilder builder = Settings.builder();
42+
configuration.entrySet().stream().forEach(e -> builder.put(e.getKey(), e.getValue()));
43+
return get(builder.build());
4444
}
4545

4646
@Override

cassandra-driver/src/main/java/org/jnosql/diana/cassandra/column/CassandraConfiguration.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,23 @@
3131
* The Cassandra implementation to {@link UnaryColumnConfiguration} that returns
3232
* {@link CassandraColumnFamilyManagerFactory}
3333
* This configuration reads "diana-cassandra.properties" files and has the following configuration:
34-
* <p>cassandra-host-: The Cassandra host as prefix, you can set how much you want just setting the number order,
35-
* eg: cassandra-host-1 = host, cassandra-host-2 = host2</p>
36-
* <p>cassandra-query-: The Cassandra query to run when an instance is started, you can set how much you want just
37-
* setting the order number, eg: cassandra-query-1=cql, cassandra-query-2=cql2... </p>
38-
* <p>cassandra-threads-number: The number of executor to run on Async process, if it isn't defined that will use the number of processor</p>
39-
* <p>cassandra-ssl: Define ssl, the default value is false</p>
40-
* <p>cassandra-metrics: enable metrics, the default value is true</p>
41-
* <p>cassandra-jmx: enable JMX, the default value is true</p>
34+
* <p>cassandra.host-: The Cassandra host as prefix, you can set how much you want just setting the number order,
35+
* eg: cassandra.host-1 = host, cassandra.host-2 = host2</p>
36+
* <p>cassandra.query.: The Cassandra query to run when an instance is started, you can set how much you want just
37+
* setting the order number, eg: cassandra.query.1=cql, cassandra.query.2=cql2... </p>
38+
* <p>cassandra.threads.number: The number of executor to run on Async process, if it isn't defined that will use the number of processor</p>
39+
* <p>cassandra.ssl: Define ssl, the default value is false</p>
40+
* <p>cassandra.metrics: enable metrics, the default value is true</p>
41+
* <p>cassandra.jmx: enable JMX, the default value is true</p>
42+
* @see CassandraConfigurations
43+
* @see OldCassandraConfigurations
4244
*/
4345
public class CassandraConfiguration implements UnaryColumnConfiguration<CassandraColumnFamilyManagerFactory> {
4446

4547
static final String CASSANDRA_FILE_CONFIGURATION = "diana-cassandra.properties";
4648

47-
public CassandraColumnFamilyManagerFactory getManagerFactory(Map<String, String> configurations) {
49+
50+
private CassandraColumnFamilyManagerFactory getManagerFactory(Map<String, String> configurations) {
4851
requireNonNull(configurations);
4952
CassandraProperties properties = CassandraProperties.of(configurations);
5053
ExecutorService executorService = properties.createExecutorService();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2019 Otávio Santana and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.jnosql.diana.cassandra.column;
16+
17+
import java.util.function.Supplier;
18+
19+
public enum CassandraConfigurations implements Supplier<String> {
20+
21+
HOST("cassandra.host"),
22+
NAME("cassandra.name"),
23+
PORT("cassandra.port"),
24+
QUERY("cassandra.query"),
25+
SSL("cassandra.ssl"),
26+
METRICS("cassandra.metrics"),
27+
JMX("cassandra.jmx");
28+
29+
private final String configuration;
30+
31+
CassandraConfigurations(String configuration) {
32+
this.configuration = configuration;
33+
}
34+
35+
@Override
36+
public String get() {
37+
return configuration;
38+
}
39+
}

0 commit comments

Comments
 (0)