diff --git a/core/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java b/core/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java index cba0f366a..0e19d658e 100644 --- a/core/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java +++ b/core/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java @@ -27,72 +27,86 @@ */ public final class CollectionPropertiesEntity extends CollectionEntity { + private Boolean cacheEnabled; + private String distributeShardsLike; + private Boolean isDisjoint; + private Boolean isSmart; private KeyOptions keyOptions; - private Long count; private Integer numberOfShards; - private Collection shardKeys; private ReplicationFactor replicationFactor; - private Integer writeConcern; + private Collection shardKeys; private String shardingStrategy; // cluster option + private String smartGraphAttribute; private String smartJoinAttribute; // enterprise option + private Integer writeConcern; + private Long count; public CollectionPropertiesEntity() { super(); } - public KeyOptions getKeyOptions() { - return keyOptions; + public Boolean getCacheEnabled() { + return cacheEnabled; } - public void setKeyOptions(final KeyOptions keyOptions) { - this.keyOptions = keyOptions; + public void setCacheEnabled(Boolean cacheEnabled) { + this.cacheEnabled = cacheEnabled; } - public Long getCount() { - return count; + public String getDistributeShardsLike() { + return distributeShardsLike; } - public void setCount(final Long count) { - this.count = count; + public void setDistributeShardsLike(String distributeShardsLike) { + this.distributeShardsLike = distributeShardsLike; } - /** - * @return the number of shards of the collection. Only in a cluster setup (else returning null). - */ - public Integer getNumberOfShards() { - return numberOfShards; + public Boolean getDisjoint() { + return isDisjoint; } - public void setNumberOfShards(final Integer numberOfShards) { - this.numberOfShards = numberOfShards; + public void setDisjoint(Boolean disjoint) { + isDisjoint = disjoint; } - /** - * @return the names of document attributes that are used to determine the target shard for documents. - * Only in a cluster setup (else returning null). - */ - public Collection getShardKeys() { - return shardKeys; + public Boolean getSmart() { + return isSmart; } - public void setShardKeys(final Collection shardKeys) { - this.shardKeys = shardKeys; + public void setSmart(Boolean smart) { + isSmart = smart; + } + + public KeyOptions getKeyOptions() { + return keyOptions; + } + + public void setKeyOptions(KeyOptions keyOptions) { + this.keyOptions = keyOptions; + } + + public Integer getNumberOfShards() { + return numberOfShards; + } + + public void setNumberOfShards(Integer numberOfShards) { + this.numberOfShards = numberOfShards; } public ReplicationFactor getReplicationFactor() { return replicationFactor; } - public void setReplicationFactor(final ReplicationFactor replicationFactor) { + public void setReplicationFactor(ReplicationFactor replicationFactor) { this.replicationFactor = replicationFactor; } - public Integer getWriteConcern() { - return writeConcern; + public Collection getShardKeys() { + return shardKeys; } - public void setWriteConcern(final Integer writeConcern) { - this.writeConcern = writeConcern; + public void setShardKeys(Collection shardKeys) { + this.shardKeys = shardKeys; } public String getShardingStrategy() { @@ -103,6 +117,14 @@ public void setShardingStrategy(String shardingStrategy) { this.shardingStrategy = shardingStrategy; } + public String getSmartGraphAttribute() { + return smartGraphAttribute; + } + + public void setSmartGraphAttribute(String smartGraphAttribute) { + this.smartGraphAttribute = smartGraphAttribute; + } + public String getSmartJoinAttribute() { return smartJoinAttribute; } @@ -111,4 +133,19 @@ public void setSmartJoinAttribute(String smartJoinAttribute) { this.smartJoinAttribute = smartJoinAttribute; } + public Integer getWriteConcern() { + return writeConcern; + } + + public void setWriteConcern(Integer writeConcern) { + this.writeConcern = writeConcern; + } + + public Long getCount() { + return count; + } + + public void setCount(Long count) { + this.count = count; + } } diff --git a/core/src/main/java/com/arangodb/model/CollectionPropertiesOptions.java b/core/src/main/java/com/arangodb/model/CollectionPropertiesOptions.java index 519e81c28..691b4344d 100644 --- a/core/src/main/java/com/arangodb/model/CollectionPropertiesOptions.java +++ b/core/src/main/java/com/arangodb/model/CollectionPropertiesOptions.java @@ -20,6 +20,9 @@ package com.arangodb.model; +import com.arangodb.entity.ReplicationFactor; +import com.fasterxml.jackson.annotation.JsonInclude; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -29,35 +32,83 @@ */ public final class CollectionPropertiesOptions { - private Boolean waitForSync; - private CollectionSchema schema; + private Boolean cacheEnabled; private List computedValues; + private ReplicationFactor replicationFactor; + private CollectionSchema schema; + private Boolean waitForSync; + private Integer writeConcern; public CollectionPropertiesOptions() { super(); } - public Boolean getWaitForSync() { - return waitForSync; + public Boolean getCacheEnabled() { + return cacheEnabled; } /** - * @param waitForSync If true then creating or changing a document will wait until the data has been synchronized - * to disk. - * @return options + * @param cacheEnabled Whether the in-memory hash cache for documents should be enabled for this collection. Can be + * controlled globally with the --cache.size startup option. The cache can speed up repeated + * reads of the same documents via their document keys. If the same documents are not fetched + * often or are modified frequently, then you may disable the cache to avoid the maintenance + * costs. + * @return this */ - public CollectionPropertiesOptions waitForSync(final Boolean waitForSync) { - this.waitForSync = waitForSync; + public CollectionPropertiesOptions cacheEnabled(final Boolean cacheEnabled) { + this.cacheEnabled = cacheEnabled; + return this; + } + + public List getComputedValues() { + return computedValues; + } + + /** + * @param computedValues An optional list of computed values. + * @return this + * @since ArangoDB 3.10 + */ + public CollectionPropertiesOptions computedValues(final ComputedValue... computedValues) { + if (this.computedValues == null) { + this.computedValues = new ArrayList<>(); + } + Collections.addAll(this.computedValues, computedValues); return this; } + public ReplicationFactor getReplicationFactor() { + return replicationFactor; + } + + /** + * @param replicationFactor In a cluster, this attribute determines how many copies of each shard are kept on + * different DB-Servers. The value 1 means that only one copy (no synchronous replication) + * is kept. A value of k means that k-1 replicas are kept. For SatelliteCollections, it + * needs to be the string "satellite", which matches the replication factor to the number + * of DB-Servers (Enterprise Edition only). + *

+ * Any two copies reside on different DB-Servers. Replication between them is synchronous, + * that is, every write operation to the “leader” copy will be replicated to all “follower” + * replicas, before the write operation is reported successful. + *

+ * If a server fails, this is detected automatically and one of the servers holding copies + * take over, usually without an error being reported. + * @return this + */ + public CollectionPropertiesOptions replicationFactor(final ReplicationFactor replicationFactor) { + this.replicationFactor = replicationFactor; + return this; + } + + @JsonInclude(JsonInclude.Include.ALWAYS) public CollectionSchema getSchema() { return schema; } /** * @param schema object that specifies the collection level schema for documents - * @return options + * @return this * @since ArangoDB 3.7 */ public CollectionPropertiesOptions schema(final CollectionSchema schema) { @@ -65,20 +116,40 @@ public CollectionPropertiesOptions schema(final CollectionSchema schema) { return this; } + public Boolean getWaitForSync() { + return waitForSync; + } + /** - * @param computedValues An optional list of computed values. - * @return options - * @since ArangoDB 3.10 + * @param waitForSync If true then creating or changing a document will wait until the data has been synchronized + * to disk. + * @return this */ - public CollectionPropertiesOptions computedValues(final ComputedValue... computedValues) { - if(this.computedValues == null) { - this.computedValues = new ArrayList<>(); - } - Collections.addAll(this.computedValues, computedValues); + public CollectionPropertiesOptions waitForSync(final Boolean waitForSync) { + this.waitForSync = waitForSync; return this; } - public List getComputedValues() { - return computedValues; + public Integer getWriteConcern() { + return writeConcern; } + + /** + * @param writeConcern Determines how many copies of each shard are required to be in sync on the different + * DB-Servers. If there are less than these many copies in the cluster, a shard refuses to + * write. Writes to shards with enough up-to-date copies succeed at the same time, however. + * The value of writeConcern cannot be greater than replicationFactor. + *

+ * If distributeShardsLike is set, the default writeConcern is that of the prototype collection. + * For SatelliteCollections, the writeConcern is automatically controlled to equal the number of + * DB-Servers and has a value of 0. Otherwise, the default value is controlled by the current + * database’s default writeConcern, which uses the --cluster.write-concern startup option as + * default, which defaults to 1. (cluster only) + * @return this + */ + public CollectionPropertiesOptions writeConcern(final Integer writeConcern) { + this.writeConcern = writeConcern; + return this; + } + } diff --git a/test-functional/src/test/java/com/arangodb/ArangoCollectionTest.java b/test-functional/src/test/java/com/arangodb/ArangoCollectionTest.java index ea21964db..aa28ef9c1 100644 --- a/test-functional/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/test-functional/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -3453,36 +3453,51 @@ void getPropeties(ArangoCollection collection) { @ParameterizedTest @MethodSource("cols") void changeProperties(ArangoCollection collection) { + assumeTrue(isCluster()); final CollectionPropertiesEntity properties = collection.getProperties(); assertThat(properties.getWaitForSync()).isNotNull(); - if (isAtLeastVersion(3, 7)) { - assertThat(properties.getSchema()).isNull(); - } + assertThat(properties.getSchema()).isNull(); String schemaRule = ("{ " + " \"properties\": {" + " \"number\": {" + " " + " \"type\": \"number\"" + " }" + " }" + " }").replaceAll("\\s", ""); String schemaMessage = "The document has problems!"; CollectionPropertiesOptions updatedOptions = - new CollectionPropertiesOptions().waitForSync(!properties.getWaitForSync()).schema(new CollectionSchema().setLevel(CollectionSchema.Level.NEW).setMessage(schemaMessage).setRule(schemaRule)); + new CollectionPropertiesOptions() + .cacheEnabled(!properties.getCacheEnabled()) + .computedValues(new ComputedValue() + .name("foo") + .expression("RETURN 11") + .overwrite(false) + .computeOn(ComputedValue.ComputeOn.insert) + .keepNull(false) + .failOnWarning(true)) + .replicationFactor(ReplicationFactor.of(3)) + .schema(new CollectionSchema().setLevel(CollectionSchema.Level.NEW).setMessage(schemaMessage).setRule(schemaRule)) + .waitForSync(!properties.getWaitForSync()) + .writeConcern(2); final CollectionPropertiesEntity changedProperties = collection.changeProperties(updatedOptions); - assertThat(changedProperties.getWaitForSync()).isNotNull(); - assertThat(changedProperties.getWaitForSync()).isEqualTo(!properties.getWaitForSync()); - if (isAtLeastVersion(3, 7)) { - assertThat(changedProperties.getSchema()).isNotNull(); - assertThat(changedProperties.getSchema().getLevel()).isEqualTo(CollectionSchema.Level.NEW); - assertThat(changedProperties.getSchema().getMessage()).isEqualTo(schemaMessage); - assertThat(changedProperties.getSchema().getRule()).isEqualTo(schemaRule); - } + assertThat(changedProperties.getCacheEnabled()).isEqualTo(updatedOptions.getCacheEnabled()); + assertThat(changedProperties.getComputedValues()) + .hasSize(1) + .contains(updatedOptions.getComputedValues().get(0)); + assertThat(changedProperties.getReplicationFactor().get()).isEqualTo(updatedOptions.getReplicationFactor().get()); + assertThat(changedProperties.getSchema().getLevel()).isEqualTo(CollectionSchema.Level.NEW); + assertThat(changedProperties.getSchema().getMessage()).isEqualTo(schemaMessage); + assertThat(changedProperties.getSchema().getRule()).isEqualTo(schemaRule); + assertThat(changedProperties.getWaitForSync()).isEqualTo(updatedOptions.getWaitForSync()); + assertThat(changedProperties.getWriteConcern()).isEqualTo(updatedOptions.getWriteConcern()); // revert changes - CollectionPropertiesEntity revertedProperties = collection.changeProperties(new CollectionPropertiesOptions() - .waitForSync(properties.getWaitForSync()).schema(new CollectionSchema())); - if (isAtLeastVersion(3, 7)) { - assertThat(revertedProperties.getSchema()).isNull(); - } - + CollectionPropertiesOptions revertOptions = new CollectionPropertiesOptions() + .cacheEnabled(properties.getCacheEnabled()) + .computedValues() + .replicationFactor(properties.getReplicationFactor()) + .schema(properties.getSchema()) + .waitForSync(properties.getWaitForSync()) + .writeConcern(properties.getWriteConcern()); + collection.changeProperties(revertOptions); } @ParameterizedTest