Skip to content

add smartJoinAttribute and shardingStrategy #259

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

Merged
merged 1 commit into from
May 6, 2019
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
4 changes: 0 additions & 4 deletions src/main/java/com/arangodb/entity/ArangoDBVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
*/
public class ArangoDBVersion implements Entity {

public enum License {
ENTERPRISE, COMMUNITY
}

private String server;
private String version;
private License license;
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class CollectionPropertiesEntity extends CollectionEntity {
private Collection<String> shardKeys;
private final ReplicationFactor replicationFactor;

private String shardingStrategy; // cluster option
private String smartJoinAttribute; // enterprise option

public CollectionPropertiesEntity() {
super();
replicationFactor = new ReplicationFactor();
Expand Down Expand Up @@ -126,4 +129,20 @@ public void setSatellite(final Boolean satellite) {
this.replicationFactor.setSatellite(satellite);
}

public String getShardingStrategy() {
return shardingStrategy;
}

public void setShardingStrategy(String shardingStrategy) {
this.shardingStrategy = shardingStrategy;
}

public String getSmartJoinAttribute() {
return smartJoinAttribute;
}

public void setSmartJoinAttribute(String smartJoinAttribute) {
this.smartJoinAttribute = smartJoinAttribute;
}

}
30 changes: 30 additions & 0 deletions src/main/java/com/arangodb/entity/License.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* DISCLAIMER
*
* Copyright 2019 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.entity;

/**
* @author Axel Becker
*/
public enum License {

ENTERPRISE, COMMUNITY

}
45 changes: 45 additions & 0 deletions src/main/java/com/arangodb/entity/ShardingStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* DISCLAIMER
*
* Copyright 2019 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.entity;

/**
* @author Axel Becker
* https://www.arangodb.com/docs/3.4/http/collection-creating.html
*/
public enum ShardingStrategy {

COMMUNITY_COMPAT("community-compat"),
ENTERPRISE_COMPAT("enterprise-compat"),
ENTERPRISE_SMART_EDGE_COMPAT("enterprise-smart-edge-compat"),
HASH("hash"),
ENTERPRISE_HASH_SMART_EDGE("enterprise-hash-smart-edge");

private String internalName;

private ShardingStrategy(String internalName) {
this.internalName = internalName;
}

public String getInternalName() {
return this.internalName;
}

}
13 changes: 9 additions & 4 deletions src/main/java/com/arangodb/internal/ArangoExecutorSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,28 @@ public <T> T execute(final Request request, final Type type, final HostHandle ho
return execute(request, new ResponseDeserializer<T>() {
@Override
public T deserialize(final Response response) throws VPackException {
return createResult(type, response);
T result = createResult(type, response);
return result;
}
}, hostHandle);
}

public <T> T execute(final Request request, final ResponseDeserializer<T> responseDeserializer)
throws ArangoDBException {
public <T> T execute(final Request request, final ResponseDeserializer<T> responseDeserializer) throws ArangoDBException {
return execute(request, responseDeserializer, null);
}

public <T> T execute(
final Request request,
final ResponseDeserializer<T> responseDeserializer,
final HostHandle hostHandle) throws ArangoDBException {

try {

final Response response = protocol.execute(request, hostHandle);
return responseDeserializer.deserialize(response);
T deserialize = responseDeserializer.deserialize(response);

return deserialize;

} catch (final VPackException e) {
throw new ArangoDBException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ protected Request getVersionRequest() {
}

protected Request createCollectionRequest(final String name, final CollectionCreateOptions options) {
return request(name(), RequestType.POST, InternalArangoCollection.PATH_API_COLLECTION).setBody(
util().serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)));

VPackSlice body = util().serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name));

return request(
name(),
RequestType.POST,
InternalArangoCollection.PATH_API_COLLECTION).setBody(body);
}

protected Request getCollectionsRequest(final CollectionsReadOptions options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import org.slf4j.LoggerFactory;

import com.arangodb.entity.ArangoDBVersion;
import com.arangodb.entity.ArangoDBVersion.License;
import com.arangodb.entity.BaseDocument;
import com.arangodb.entity.BaseEdgeDocument;
import com.arangodb.entity.CollectionStatus;
import com.arangodb.entity.CollectionType;
import com.arangodb.entity.License;
import com.arangodb.entity.LogLevel;
import com.arangodb.entity.Permissions;
import com.arangodb.entity.QueryExecutionState;
Expand All @@ -45,8 +45,8 @@
import com.arangodb.entity.arangosearch.ArangoSearchProperties;
import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity;
import com.arangodb.entity.arangosearch.CollectionLink;
import com.arangodb.entity.arangosearch.ConsolidationType;
import com.arangodb.entity.arangosearch.ConsolidationPolicy;
import com.arangodb.entity.arangosearch.ConsolidationType;
import com.arangodb.entity.arangosearch.FieldLink;
import com.arangodb.entity.arangosearch.StoreValuesType;
import com.arangodb.velocypack.VPackDeserializationContext;
Expand Down Expand Up @@ -153,12 +153,13 @@ public LogLevel deserialize(
}
};

public static final VPackDeserializer<ArangoDBVersion.License> LICENSE = new VPackDeserializer<ArangoDBVersion.License>() {
public static final VPackDeserializer<License> LICENSE = new VPackDeserializer<License>() {
@Override
public License deserialize(
final VPackSlice parent,
final VPackSlice vpack,
final VPackDeserializationContext context) throws VPackException {

return License.valueOf(vpack.getAsString().toUpperCase());
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import java.lang.reflect.Field;
import java.util.Date;

import com.arangodb.entity.ArangoDBVersion;
import com.arangodb.entity.BaseDocument;
import com.arangodb.entity.BaseEdgeDocument;
import com.arangodb.entity.CollectionStatus;
import com.arangodb.entity.CollectionType;
import com.arangodb.entity.DocumentField;
import com.arangodb.entity.License;
import com.arangodb.entity.LogLevel;
import com.arangodb.entity.Permissions;
import com.arangodb.entity.QueryEntity;
Expand All @@ -37,8 +37,8 @@
import com.arangodb.entity.ViewType;
import com.arangodb.entity.arangosearch.ArangoSearchProperties;
import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity;
import com.arangodb.entity.arangosearch.ConsolidationType;
import com.arangodb.entity.arangosearch.ConsolidationPolicy;
import com.arangodb.entity.arangosearch.ConsolidationType;
import com.arangodb.internal.velocystream.internal.AuthenticationRequest;
import com.arangodb.model.TraversalOptions;
import com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions;
Expand Down Expand Up @@ -78,8 +78,7 @@ public String translateName(final Field field) {
context.registerSerializer(Permissions.class, VPackSerializers.PERMISSIONS);
context.registerSerializer(ReplicationFactor.class, VPackSerializers.REPLICATION_FACTOR);
context.registerSerializer(ViewType.class, VPackSerializers.VIEW_TYPE);
context.registerSerializer(ArangoSearchPropertiesOptions.class,
VPackSerializers.ARANGO_SEARCH_PROPERTIES_OPTIONS);
context.registerSerializer(ArangoSearchPropertiesOptions.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES_OPTIONS);
context.registerSerializer(ArangoSearchProperties.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES);
context.registerSerializer(ConsolidationType.class, VPackSerializers.CONSOLIDATE_TYPE);

Expand All @@ -90,14 +89,13 @@ public String translateName(final Field field) {
context.registerDeserializer(BaseEdgeDocument.class, VPackDeserializers.BASE_EDGE_DOCUMENT);
context.registerDeserializer(QueryEntity.PROPERTY_STARTED, Date.class, VPackDeserializers.DATE_STRING);
context.registerDeserializer(LogLevel.class, VPackDeserializers.LOG_LEVEL);
context.registerDeserializer(ArangoDBVersion.License.class, VPackDeserializers.LICENSE);
context.registerDeserializer(License.class, VPackDeserializers.LICENSE);
context.registerDeserializer(Permissions.class, VPackDeserializers.PERMISSIONS);
context.registerDeserializer(QueryExecutionState.class, VPackDeserializers.QUERY_EXECUTION_STATE);
context.registerDeserializer(ReplicationFactor.class, VPackDeserializers.REPLICATION_FACTOR);
context.registerDeserializer(ViewType.class, VPackDeserializers.VIEW_TYPE);
context.registerDeserializer(ArangoSearchProperties.class, VPackDeserializers.ARANGO_SEARCH_PROPERTIES);
context.registerDeserializer(ArangoSearchPropertiesEntity.class,
VPackDeserializers.ARANGO_SEARCH_PROPERTIES_ENTITY);
context.registerDeserializer(ArangoSearchPropertiesEntity.class, VPackDeserializers.ARANGO_SEARCH_PROPERTIES_ENTITY);
context.registerDeserializer(ConsolidationPolicy.class, VPackDeserializers.CONSOLIDATE);
}

Expand Down
35 changes: 32 additions & 3 deletions src/main/java/com/arangodb/model/CollectionCreateOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class CollectionCreateOptions {
private CollectionType type;
private Integer indexBuckets;
private String distributeShardsLike;

private String shardingStrategy; // cluster option
private String smartJoinAttribute; // enterprise option

public CollectionCreateOptions() {
super();
Expand Down Expand Up @@ -209,10 +212,32 @@ public CollectionCreateOptions shardKeys(final String... shardKeys) {
return this;
}

public Integer getNumberOfShards() {
return numberOfShards;
/**
* @param smartJoinAttribute
* @return options
*/
public CollectionCreateOptions smartJoinAttribute(final String smartJoinAttribute) {
this.smartJoinAttribute = smartJoinAttribute;
return this;
}

public String getSmartJoinAttribute() {
return smartJoinAttribute;
}

/**
* @param shardingStrategy
* @return options
*/
public CollectionCreateOptions shardingStrategy(final String shardingStrategy) {
this.shardingStrategy = shardingStrategy;
return this;
}

public String getShardingStrategy() {
return shardingStrategy;
}

/**
* @param numberOfShards
* (The default is 1): in a cluster, this value determines the number of shards to create for the
Expand All @@ -223,7 +248,11 @@ public CollectionCreateOptions numberOfShards(final Integer numberOfShards) {
this.numberOfShards = numberOfShards;
return this;
}


public Integer getNumberOfShards() {
return numberOfShards;
}

public Boolean getIsSystem() {
return isSystem;
}
Expand Down
Loading