Skip to content

Commit 887b71c

Browse files
BCaxelbeckerhkernbach
authored andcommitted
add smartJoinAttribute and shardingStrategy (#259)
1 parent b363d54 commit 887b71c

File tree

11 files changed

+232
-35
lines changed

11 files changed

+232
-35
lines changed

src/main/java/com/arangodb/entity/ArangoDBVersion.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
*/
2929
public class ArangoDBVersion implements Entity {
3030

31-
public enum License {
32-
ENTERPRISE, COMMUNITY
33-
}
34-
3531
private String server;
3632
private String version;
3733
private License license;

src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public class CollectionPropertiesEntity extends CollectionEntity {
3939
private Collection<String> shardKeys;
4040
private final ReplicationFactor replicationFactor;
4141

42+
private String shardingStrategy; // cluster option
43+
private String smartJoinAttribute; // enterprise option
44+
4245
public CollectionPropertiesEntity() {
4346
super();
4447
replicationFactor = new ReplicationFactor();
@@ -126,4 +129,20 @@ public void setSatellite(final Boolean satellite) {
126129
this.replicationFactor.setSatellite(satellite);
127130
}
128131

132+
public String getShardingStrategy() {
133+
return shardingStrategy;
134+
}
135+
136+
public void setShardingStrategy(String shardingStrategy) {
137+
this.shardingStrategy = shardingStrategy;
138+
}
139+
140+
public String getSmartJoinAttribute() {
141+
return smartJoinAttribute;
142+
}
143+
144+
public void setSmartJoinAttribute(String smartJoinAttribute) {
145+
this.smartJoinAttribute = smartJoinAttribute;
146+
}
147+
129148
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2019 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity;
22+
23+
/**
24+
* @author Axel Becker
25+
*/
26+
public enum License {
27+
28+
ENTERPRISE, COMMUNITY
29+
30+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2019 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity;
22+
23+
/**
24+
* @author Axel Becker
25+
* https://www.arangodb.com/docs/3.4/http/collection-creating.html
26+
*/
27+
public enum ShardingStrategy {
28+
29+
COMMUNITY_COMPAT("community-compat"),
30+
ENTERPRISE_COMPAT("enterprise-compat"),
31+
ENTERPRISE_SMART_EDGE_COMPAT("enterprise-smart-edge-compat"),
32+
HASH("hash"),
33+
ENTERPRISE_HASH_SMART_EDGE("enterprise-hash-smart-edge");
34+
35+
private String internalName;
36+
37+
private ShardingStrategy(String internalName) {
38+
this.internalName = internalName;
39+
}
40+
41+
public String getInternalName() {
42+
return this.internalName;
43+
}
44+
45+
}

src/main/java/com/arangodb/internal/ArangoExecutorSync.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,28 @@ public <T> T execute(final Request request, final Type type, final HostHandle ho
5353
return execute(request, new ResponseDeserializer<T>() {
5454
@Override
5555
public T deserialize(final Response response) throws VPackException {
56-
return createResult(type, response);
56+
T result = createResult(type, response);
57+
return result;
5758
}
5859
}, hostHandle);
5960
}
6061

61-
public <T> T execute(final Request request, final ResponseDeserializer<T> responseDeserializer)
62-
throws ArangoDBException {
62+
public <T> T execute(final Request request, final ResponseDeserializer<T> responseDeserializer) throws ArangoDBException {
6363
return execute(request, responseDeserializer, null);
6464
}
6565

6666
public <T> T execute(
6767
final Request request,
6868
final ResponseDeserializer<T> responseDeserializer,
6969
final HostHandle hostHandle) throws ArangoDBException {
70+
7071
try {
72+
7173
final Response response = protocol.execute(request, hostHandle);
72-
return responseDeserializer.deserialize(response);
74+
T deserialize = responseDeserializer.deserialize(response);
75+
76+
return deserialize;
77+
7378
} catch (final VPackException e) {
7479
throw new ArangoDBException(e);
7580
}

src/main/java/com/arangodb/internal/InternalArangoDatabase.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,13 @@ protected Request getVersionRequest() {
117117
}
118118

119119
protected Request createCollectionRequest(final String name, final CollectionCreateOptions options) {
120-
return request(name(), RequestType.POST, InternalArangoCollection.PATH_API_COLLECTION).setBody(
121-
util().serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)));
120+
121+
VPackSlice body = util().serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name));
122+
123+
return request(
124+
name(),
125+
RequestType.POST,
126+
InternalArangoCollection.PATH_API_COLLECTION).setBody(body);
122127
}
123128

124129
protected Request getCollectionsRequest(final CollectionsReadOptions options) {

src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
import org.slf4j.LoggerFactory;
3232

3333
import com.arangodb.entity.ArangoDBVersion;
34-
import com.arangodb.entity.ArangoDBVersion.License;
3534
import com.arangodb.entity.BaseDocument;
3635
import com.arangodb.entity.BaseEdgeDocument;
3736
import com.arangodb.entity.CollectionStatus;
3837
import com.arangodb.entity.CollectionType;
38+
import com.arangodb.entity.License;
3939
import com.arangodb.entity.LogLevel;
4040
import com.arangodb.entity.Permissions;
4141
import com.arangodb.entity.QueryExecutionState;
@@ -45,8 +45,8 @@
4545
import com.arangodb.entity.arangosearch.ArangoSearchProperties;
4646
import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity;
4747
import com.arangodb.entity.arangosearch.CollectionLink;
48-
import com.arangodb.entity.arangosearch.ConsolidationType;
4948
import com.arangodb.entity.arangosearch.ConsolidationPolicy;
49+
import com.arangodb.entity.arangosearch.ConsolidationType;
5050
import com.arangodb.entity.arangosearch.FieldLink;
5151
import com.arangodb.entity.arangosearch.StoreValuesType;
5252
import com.arangodb.velocypack.VPackDeserializationContext;
@@ -153,12 +153,13 @@ public LogLevel deserialize(
153153
}
154154
};
155155

156-
public static final VPackDeserializer<ArangoDBVersion.License> LICENSE = new VPackDeserializer<ArangoDBVersion.License>() {
156+
public static final VPackDeserializer<License> LICENSE = new VPackDeserializer<License>() {
157157
@Override
158158
public License deserialize(
159159
final VPackSlice parent,
160160
final VPackSlice vpack,
161161
final VPackDeserializationContext context) throws VPackException {
162+
162163
return License.valueOf(vpack.getAsString().toUpperCase());
163164
}
164165
};

src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import java.lang.reflect.Field;
2424
import java.util.Date;
2525

26-
import com.arangodb.entity.ArangoDBVersion;
2726
import com.arangodb.entity.BaseDocument;
2827
import com.arangodb.entity.BaseEdgeDocument;
2928
import com.arangodb.entity.CollectionStatus;
3029
import com.arangodb.entity.CollectionType;
3130
import com.arangodb.entity.DocumentField;
31+
import com.arangodb.entity.License;
3232
import com.arangodb.entity.LogLevel;
3333
import com.arangodb.entity.Permissions;
3434
import com.arangodb.entity.QueryEntity;
@@ -37,8 +37,8 @@
3737
import com.arangodb.entity.ViewType;
3838
import com.arangodb.entity.arangosearch.ArangoSearchProperties;
3939
import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity;
40-
import com.arangodb.entity.arangosearch.ConsolidationType;
4140
import com.arangodb.entity.arangosearch.ConsolidationPolicy;
41+
import com.arangodb.entity.arangosearch.ConsolidationType;
4242
import com.arangodb.internal.velocystream.internal.AuthenticationRequest;
4343
import com.arangodb.model.TraversalOptions;
4444
import com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions;
@@ -78,8 +78,7 @@ public String translateName(final Field field) {
7878
context.registerSerializer(Permissions.class, VPackSerializers.PERMISSIONS);
7979
context.registerSerializer(ReplicationFactor.class, VPackSerializers.REPLICATION_FACTOR);
8080
context.registerSerializer(ViewType.class, VPackSerializers.VIEW_TYPE);
81-
context.registerSerializer(ArangoSearchPropertiesOptions.class,
82-
VPackSerializers.ARANGO_SEARCH_PROPERTIES_OPTIONS);
81+
context.registerSerializer(ArangoSearchPropertiesOptions.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES_OPTIONS);
8382
context.registerSerializer(ArangoSearchProperties.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES);
8483
context.registerSerializer(ConsolidationType.class, VPackSerializers.CONSOLIDATE_TYPE);
8584

@@ -90,14 +89,13 @@ public String translateName(final Field field) {
9089
context.registerDeserializer(BaseEdgeDocument.class, VPackDeserializers.BASE_EDGE_DOCUMENT);
9190
context.registerDeserializer(QueryEntity.PROPERTY_STARTED, Date.class, VPackDeserializers.DATE_STRING);
9291
context.registerDeserializer(LogLevel.class, VPackDeserializers.LOG_LEVEL);
93-
context.registerDeserializer(ArangoDBVersion.License.class, VPackDeserializers.LICENSE);
92+
context.registerDeserializer(License.class, VPackDeserializers.LICENSE);
9493
context.registerDeserializer(Permissions.class, VPackDeserializers.PERMISSIONS);
9594
context.registerDeserializer(QueryExecutionState.class, VPackDeserializers.QUERY_EXECUTION_STATE);
9695
context.registerDeserializer(ReplicationFactor.class, VPackDeserializers.REPLICATION_FACTOR);
9796
context.registerDeserializer(ViewType.class, VPackDeserializers.VIEW_TYPE);
9897
context.registerDeserializer(ArangoSearchProperties.class, VPackDeserializers.ARANGO_SEARCH_PROPERTIES);
99-
context.registerDeserializer(ArangoSearchPropertiesEntity.class,
100-
VPackDeserializers.ARANGO_SEARCH_PROPERTIES_ENTITY);
98+
context.registerDeserializer(ArangoSearchPropertiesEntity.class, VPackDeserializers.ARANGO_SEARCH_PROPERTIES_ENTITY);
10199
context.registerDeserializer(ConsolidationPolicy.class, VPackDeserializers.CONSOLIDATE);
102100
}
103101

src/main/java/com/arangodb/model/CollectionCreateOptions.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class CollectionCreateOptions {
4646
private CollectionType type;
4747
private Integer indexBuckets;
4848
private String distributeShardsLike;
49+
50+
private String shardingStrategy; // cluster option
51+
private String smartJoinAttribute; // enterprise option
4952

5053
public CollectionCreateOptions() {
5154
super();
@@ -209,10 +212,32 @@ public CollectionCreateOptions shardKeys(final String... shardKeys) {
209212
return this;
210213
}
211214

212-
public Integer getNumberOfShards() {
213-
return numberOfShards;
215+
/**
216+
* @param smartJoinAttribute
217+
* @return options
218+
*/
219+
public CollectionCreateOptions smartJoinAttribute(final String smartJoinAttribute) {
220+
this.smartJoinAttribute = smartJoinAttribute;
221+
return this;
222+
}
223+
224+
public String getSmartJoinAttribute() {
225+
return smartJoinAttribute;
214226
}
215227

228+
/**
229+
* @param shardingStrategy
230+
* @return options
231+
*/
232+
public CollectionCreateOptions shardingStrategy(final String shardingStrategy) {
233+
this.shardingStrategy = shardingStrategy;
234+
return this;
235+
}
236+
237+
public String getShardingStrategy() {
238+
return shardingStrategy;
239+
}
240+
216241
/**
217242
* @param numberOfShards
218243
* (The default is 1): in a cluster, this value determines the number of shards to create for the
@@ -223,7 +248,11 @@ public CollectionCreateOptions numberOfShards(final Integer numberOfShards) {
223248
this.numberOfShards = numberOfShards;
224249
return this;
225250
}
226-
251+
252+
public Integer getNumberOfShards() {
253+
return numberOfShards;
254+
}
255+
227256
public Boolean getIsSystem() {
228257
return isSystem;
229258
}

0 commit comments

Comments
 (0)