|
20 | 20 |
|
21 | 21 | package com.arangodb.model;
|
22 | 22 |
|
| 23 | +import com.arangodb.entity.ReplicationFactor; |
| 24 | +import com.fasterxml.jackson.annotation.JsonInclude; |
| 25 | + |
23 | 26 | import java.util.ArrayList;
|
24 | 27 | import java.util.Collections;
|
25 | 28 | import java.util.List;
|
|
29 | 32 | */
|
30 | 33 | public final class CollectionPropertiesOptions {
|
31 | 34 |
|
32 |
| - private Boolean waitForSync; |
33 |
| - private CollectionSchema schema; |
| 35 | + private Boolean cacheEnabled; |
34 | 36 | private List<ComputedValue> computedValues;
|
| 37 | + private ReplicationFactor replicationFactor; |
| 38 | + private CollectionSchema schema; |
| 39 | + private Boolean waitForSync; |
| 40 | + private Integer writeConcern; |
35 | 41 |
|
36 | 42 | public CollectionPropertiesOptions() {
|
37 | 43 | super();
|
38 | 44 | }
|
39 | 45 |
|
40 |
| - public Boolean getWaitForSync() { |
41 |
| - return waitForSync; |
| 46 | + public Boolean getCacheEnabled() { |
| 47 | + return cacheEnabled; |
42 | 48 | }
|
43 | 49 |
|
44 | 50 | /**
|
45 |
| - * @param waitForSync If true then creating or changing a document will wait until the data has been synchronized |
46 |
| - * to disk. |
47 |
| - * @return options |
| 51 | + * @param cacheEnabled Whether the in-memory hash cache for documents should be enabled for this collection. Can be |
| 52 | + * controlled globally with the --cache.size startup option. The cache can speed up repeated |
| 53 | + * reads of the same documents via their document keys. If the same documents are not fetched |
| 54 | + * often or are modified frequently, then you may disable the cache to avoid the maintenance |
| 55 | + * costs. |
| 56 | + * @return this |
48 | 57 | */
|
49 |
| - public CollectionPropertiesOptions waitForSync(final Boolean waitForSync) { |
50 |
| - this.waitForSync = waitForSync; |
| 58 | + public CollectionPropertiesOptions cacheEnabled(final Boolean cacheEnabled) { |
| 59 | + this.cacheEnabled = cacheEnabled; |
| 60 | + return this; |
| 61 | + } |
| 62 | + |
| 63 | + public List<ComputedValue> getComputedValues() { |
| 64 | + return computedValues; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @param computedValues An optional list of computed values. |
| 69 | + * @return this |
| 70 | + * @since ArangoDB 3.10 |
| 71 | + */ |
| 72 | + public CollectionPropertiesOptions computedValues(final ComputedValue... computedValues) { |
| 73 | + if (this.computedValues == null) { |
| 74 | + this.computedValues = new ArrayList<>(); |
| 75 | + } |
| 76 | + Collections.addAll(this.computedValues, computedValues); |
51 | 77 | return this;
|
52 | 78 | }
|
53 | 79 |
|
| 80 | + public ReplicationFactor getReplicationFactor() { |
| 81 | + return replicationFactor; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @param replicationFactor In a cluster, this attribute determines how many copies of each shard are kept on |
| 86 | + * different DB-Servers. The value 1 means that only one copy (no synchronous replication) |
| 87 | + * is kept. A value of k means that k-1 replicas are kept. For SatelliteCollections, it |
| 88 | + * needs to be the string "satellite", which matches the replication factor to the number |
| 89 | + * of DB-Servers (Enterprise Edition only). |
| 90 | + * <p> |
| 91 | + * Any two copies reside on different DB-Servers. Replication between them is synchronous, |
| 92 | + * that is, every write operation to the “leader” copy will be replicated to all “follower” |
| 93 | + * replicas, before the write operation is reported successful. |
| 94 | + * <p> |
| 95 | + * If a server fails, this is detected automatically and one of the servers holding copies |
| 96 | + * take over, usually without an error being reported. |
| 97 | + * @return this |
| 98 | + */ |
| 99 | + public CollectionPropertiesOptions replicationFactor(final ReplicationFactor replicationFactor) { |
| 100 | + this.replicationFactor = replicationFactor; |
| 101 | + return this; |
| 102 | + } |
| 103 | + |
| 104 | + @JsonInclude(JsonInclude.Include.ALWAYS) |
54 | 105 | public CollectionSchema getSchema() {
|
55 | 106 | return schema;
|
56 | 107 | }
|
57 | 108 |
|
58 | 109 | /**
|
59 | 110 | * @param schema object that specifies the collection level schema for documents
|
60 |
| - * @return options |
| 111 | + * @return this |
61 | 112 | * @since ArangoDB 3.7
|
62 | 113 | */
|
63 | 114 | public CollectionPropertiesOptions schema(final CollectionSchema schema) {
|
64 | 115 | this.schema = schema;
|
65 | 116 | return this;
|
66 | 117 | }
|
67 | 118 |
|
| 119 | + public Boolean getWaitForSync() { |
| 120 | + return waitForSync; |
| 121 | + } |
| 122 | + |
68 | 123 | /**
|
69 |
| - * @param computedValues An optional list of computed values. |
70 |
| - * @return options |
71 |
| - * @since ArangoDB 3.10 |
| 124 | + * @param waitForSync If true then creating or changing a document will wait until the data has been synchronized |
| 125 | + * to disk. |
| 126 | + * @return this |
72 | 127 | */
|
73 |
| - public CollectionPropertiesOptions computedValues(final ComputedValue... computedValues) { |
74 |
| - if(this.computedValues == null) { |
75 |
| - this.computedValues = new ArrayList<>(); |
76 |
| - } |
77 |
| - Collections.addAll(this.computedValues, computedValues); |
| 128 | + public CollectionPropertiesOptions waitForSync(final Boolean waitForSync) { |
| 129 | + this.waitForSync = waitForSync; |
78 | 130 | return this;
|
79 | 131 | }
|
80 | 132 |
|
81 |
| - public List<ComputedValue> getComputedValues() { |
82 |
| - return computedValues; |
| 133 | + public Integer getWriteConcern() { |
| 134 | + return writeConcern; |
83 | 135 | }
|
| 136 | + |
| 137 | + /** |
| 138 | + * @param writeConcern Determines how many copies of each shard are required to be in sync on the different |
| 139 | + * DB-Servers. If there are less than these many copies in the cluster, a shard refuses to |
| 140 | + * write. Writes to shards with enough up-to-date copies succeed at the same time, however. |
| 141 | + * The value of writeConcern cannot be greater than replicationFactor. |
| 142 | + * <p> |
| 143 | + * If distributeShardsLike is set, the default writeConcern is that of the prototype collection. |
| 144 | + * For SatelliteCollections, the writeConcern is automatically controlled to equal the number of |
| 145 | + * DB-Servers and has a value of 0. Otherwise, the default value is controlled by the current |
| 146 | + * database’s default writeConcern, which uses the --cluster.write-concern startup option as |
| 147 | + * default, which defaults to 1. (cluster only) |
| 148 | + * @return this |
| 149 | + */ |
| 150 | + public CollectionPropertiesOptions writeConcern(final Integer writeConcern) { |
| 151 | + this.writeConcern = writeConcern; |
| 152 | + return this; |
| 153 | + } |
| 154 | + |
84 | 155 | }
|
0 commit comments