Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArangoDB: fixed driver lifecycle #296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public <K> void delete(Iterable<K> keys) throws NullPointerException {

@Override
public void close() {

arangoDB.shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public class ArangoDBBucketManagerFactory implements BucketManagerFactory {

private static final String DEFAULT_NAMESPACE = "diana";

private final ArangoDB arangoDB;
private final ArangoDBBuilder arangoDBBuilder;

ArangoDBBucketManagerFactory(ArangoDB arangoDB) {
this.arangoDB = arangoDB;
ArangoDBBucketManagerFactory(ArangoDBBuilder arangoDBBuilder) {
this.arangoDBBuilder = arangoDBBuilder;
}

@Override
Expand All @@ -46,6 +46,7 @@ public ArangoDBBucketManager apply(String bucketName) throws UnsupportedOperatio
}

public ArangoDBBucketManager getBucketManager(String bucketName, String namespace) {
ArangoDB arangoDB = arangoDBBuilder.build();
ArangoDBUtil.checkCollection(bucketName, arangoDB, namespace);
return new ArangoDBBucketManager(arangoDB, bucketName, namespace);
}
Expand All @@ -72,8 +73,8 @@ public List getList(String bucketName, Class clazz) throws UnsupportedOperationE

@Override
public void close() {
arangoDB.shutdown();
// no-op
// ArangoDB driver instance will be closed in ArangoDBBucketManager.close()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,59 @@
*/
package org.eclipse.jnosql.databases.arangodb.communication;

import com.arangodb.ArangoDB;
import com.arangodb.Protocol;
import com.arangodb.entity.LoadBalancingStrategy;

interface ArangoDBBuilder {
public class ArangoDBBuilder {

private final ArangoDB.Builder arangoDB;

void host(String host, int port);
ArangoDBBuilder(ArangoDB.Builder arangoDB) {
this.arangoDB = arangoDB;
}

void timeout(int timeout);
public void host(String host, int port) {
arangoDB.host(host, port);
}

void user(String user);
public void timeout(int timeout) {
arangoDB.timeout(timeout);
}

void password(String password);
public void user(String user) {
arangoDB.user(user);
}

void useSsl(boolean useSsl);
public void password(String password) {
arangoDB.password(password);
}

void chunkSize(int chunkSize);
public void useSsl(boolean useSsl) {
arangoDB.useSsl(useSsl);
}

void maxConnections(int maxConnections);
public void chunkSize(int chunkSize) {
arangoDB.chunkSize(chunkSize);
}

void protocol(Protocol protocol);
public void maxConnections(int maxConnections) {
arangoDB.maxConnections(maxConnections);
}

void acquireHostList(boolean acquireHostList);
public void protocol(Protocol protocol) {
arangoDB.protocol(protocol);
}

void loadBalancingStrategy(LoadBalancingStrategy loadBalancingStrategy);
public void acquireHostList(boolean acquireHostList) {
arangoDB.acquireHostList(acquireHostList);
}

public void loadBalancingStrategy(LoadBalancingStrategy loadBalancingStrategy) {
arangoDB.loadBalancingStrategy(loadBalancingStrategy);
}

public ArangoDB build() {
return arangoDB.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,10 @@ public void setSerde(ArangoSerde serde) {
builder.serde(serde);
}

/**
* Defines a new builder to sync ArangoDB
*
* @param builder the new builder
* @throws NullPointerException when builder is null
*/
public void syncBuilder(ArangoDB.Builder builder) throws NullPointerException {
requireNonNull(builder, "builder is required");
this.builder = builder;
}

protected ArangoDB getArangoDB(Settings settings) {
ArangoDBBuilderSync aragonDB = new ArangoDBBuilderSync(builder);
protected ArangoDBBuilder getArangoDBBuilder(Settings settings) {
ArangoDBBuilder aragonDB = new ArangoDBBuilder(builder);
ArangoDBBuilders.load(settings, aragonDB);
return aragonDB.build();
return aragonDB;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package org.eclipse.jnosql.databases.arangodb.communication;

import com.arangodb.ArangoDB;
import org.eclipse.jnosql.communication.Settings;
import org.eclipse.jnosql.communication.semistructured.DatabaseConfiguration;

Expand All @@ -36,8 +35,8 @@ public final class ArangoDBDocumentConfiguration extends ArangoDBConfiguration
public ArangoDBDocumentManagerFactory apply(Settings settings) throws NullPointerException {
requireNonNull(settings, "settings is required");

ArangoDB arangoDB = getArangoDB(settings);
return new ArangoDBDocumentManagerFactory(arangoDB);
ArangoDBBuilder arangoDBBuilder = getArangoDBBuilder(settings);
return new ArangoDBDocumentManagerFactory(arangoDBBuilder);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@
public final class ArangoDBDocumentManagerFactory implements DatabaseManagerFactory {


private final ArangoDB arangoDB;
private final ArangoDBBuilder arangoDBBuilder;

ArangoDBDocumentManagerFactory(ArangoDB arangoDB) {
this.arangoDB = arangoDB;
ArangoDBDocumentManagerFactory(ArangoDBBuilder arangoDBBuilder) {
this.arangoDBBuilder = arangoDBBuilder;
}

@Override
public ArangoDBDocumentManager apply(String database) {
ArangoDB arangoDB = arangoDBBuilder.build();
ArangoDBUtil.checkDatabase(database, arangoDB);
return new DefaultArangoDBDocumentManager(database, arangoDB);
}

@Override
public void close() {
arangoDB.shutdown();
// no-op
// ArangoDB driver instance will be closed in ArangoDBDocumentManager.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.eclipse.jnosql.databases.arangodb.communication;


import com.arangodb.ArangoDB;
import org.eclipse.jnosql.communication.Settings;
import org.eclipse.jnosql.communication.keyvalue.KeyValueConfiguration;

Expand All @@ -31,7 +30,7 @@ public final class ArangoDBKeyValueConfiguration extends ArangoDBConfiguration

@Override
public ArangoDBBucketManagerFactory apply(Settings settings) {
ArangoDB arangoDB = getArangoDB(settings);
return new ArangoDBBucketManagerFactory(arangoDB);
ArangoDBBuilder arangoDBBuilder = getArangoDBBuilder(settings);
return new ArangoDBBucketManagerFactory(arangoDBBuilder);
}
}