diff --git a/ChangeLog.md b/ChangeLog.md index af9831534..20fdec3e9 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Added +- added support for named indices - added minReplicationAttribute for collections and graphs ## [5.0.7] - 2019-07-19 diff --git a/src/main/java/com/arangodb/entity/IndexEntity.java b/src/main/java/com/arangodb/entity/IndexEntity.java index 6aeecab6c..fdea737f4 100644 --- a/src/main/java/com/arangodb/entity/IndexEntity.java +++ b/src/main/java/com/arangodb/entity/IndexEntity.java @@ -29,6 +29,7 @@ public class IndexEntity implements Entity { private String id; + private String name; private IndexType type; private Collection fields; private Double selectivityEstimate; @@ -48,6 +49,10 @@ public String getId() { return id; } + public String getName() { + return name; + } + public IndexType getType() { return type; } diff --git a/src/main/java/com/arangodb/model/FulltextIndexOptions.java b/src/main/java/com/arangodb/model/FulltextIndexOptions.java index 5f8602a33..a7154afdd 100644 --- a/src/main/java/com/arangodb/model/FulltextIndexOptions.java +++ b/src/main/java/com/arangodb/model/FulltextIndexOptions.java @@ -33,6 +33,7 @@ public class FulltextIndexOptions { private Iterable fields; private final IndexType type = IndexType.fulltext; private Integer minLength; + private String name; public FulltextIndexOptions() { super(); @@ -60,6 +61,20 @@ public Integer getMinLength() { return minLength; } + /** + * @param name + * the name of the index + * @return options + */ + public FulltextIndexOptions name(final String name) { + this.name = name; + return this; + } + + protected String getName() { + return name; + } + /** * @param minLength * Minimum character length of words to index. Will default to a server-defined value if unspecified. It diff --git a/src/main/java/com/arangodb/model/GeoIndexOptions.java b/src/main/java/com/arangodb/model/GeoIndexOptions.java index 526b2e436..be02489c8 100644 --- a/src/main/java/com/arangodb/model/GeoIndexOptions.java +++ b/src/main/java/com/arangodb/model/GeoIndexOptions.java @@ -32,6 +32,7 @@ public class GeoIndexOptions { private Iterable fields; private final IndexType type = IndexType.geo; private Boolean geoJson; + private String name; public GeoIndexOptions() { super(); @@ -55,6 +56,20 @@ protected IndexType getType() { return type; } + /** + * @param name + * the name of the index + * @return options + */ + public GeoIndexOptions name(final String name) { + this.name = name; + return this; + } + + protected String getName() { + return name; + } + public Boolean getGeoJson() { return geoJson; } diff --git a/src/main/java/com/arangodb/model/HashIndexOptions.java b/src/main/java/com/arangodb/model/HashIndexOptions.java index 4e4d39285..20dd13c44 100644 --- a/src/main/java/com/arangodb/model/HashIndexOptions.java +++ b/src/main/java/com/arangodb/model/HashIndexOptions.java @@ -34,6 +34,7 @@ public class HashIndexOptions { private Boolean unique; private Boolean sparse; private Boolean deduplicate; + private String name; public HashIndexOptions() { super(); @@ -99,4 +100,18 @@ public HashIndexOptions deduplicate(final Boolean deduplicate) { return this; } + /** + * @param name + * the name of the index + * @return options + */ + public HashIndexOptions name(final String name) { + this.name = name; + return this; + } + + protected String getName() { + return name; + } + } diff --git a/src/main/java/com/arangodb/model/PersistentIndexOptions.java b/src/main/java/com/arangodb/model/PersistentIndexOptions.java index e294c8782..fbf9a24ee 100644 --- a/src/main/java/com/arangodb/model/PersistentIndexOptions.java +++ b/src/main/java/com/arangodb/model/PersistentIndexOptions.java @@ -32,6 +32,7 @@ public class PersistentIndexOptions { private Iterable fields; protected IndexType type = IndexType.persistent; + private String name; private Boolean unique; private Boolean sparse; @@ -71,6 +72,20 @@ public PersistentIndexOptions unique(final Boolean unique) { return this; } + /** + * @param name + * the name of the index + * @return options + */ + public PersistentIndexOptions name(final String name) { + this.name = name; + return this; + } + + protected String getName() { + return name; + } + public Boolean getSparse() { return sparse; } diff --git a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java index 7ddc8dd92..b6bcd754b 100644 --- a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java +++ b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java @@ -34,6 +34,7 @@ public class SkiplistIndexOptions { private Boolean unique; private Boolean sparse; private Boolean deduplicate; + private String name; public SkiplistIndexOptions() { super(); @@ -99,4 +100,18 @@ public SkiplistIndexOptions deduplicate(final Boolean deduplicate) { return this; } + /** + * @param name + * the name of the index + * @return options + */ + public SkiplistIndexOptions name(final String name) { + this.name = name; + return this; + } + + protected String getName() { + return name; + } + } diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index c19c63473..7fd358fbc 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -42,6 +42,7 @@ import java.util.HashMap; import java.util.Map; +import com.arangodb.model.*; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -63,16 +64,7 @@ import com.arangodb.entity.MultiDocumentEntity; import com.arangodb.entity.Permissions; import com.arangodb.entity.ServerRole; -import com.arangodb.model.CollectionCreateOptions; -import com.arangodb.model.CollectionPropertiesOptions; -import com.arangodb.model.DocumentCreateOptions; -import com.arangodb.model.DocumentDeleteOptions; -import com.arangodb.model.DocumentExistsOptions; -import com.arangodb.model.DocumentImportOptions; import com.arangodb.model.DocumentImportOptions.OnDuplicate; -import com.arangodb.model.DocumentReadOptions; -import com.arangodb.model.DocumentReplaceOptions; -import com.arangodb.model.DocumentUpdateOptions; import com.arangodb.velocypack.VPackSlice; /** @@ -1044,6 +1036,35 @@ public void createHashIndex() { assertThat(indexResult.getUnique(), is(false)); } + @Test + public void createHashIndexWithOptions() { + if (!requireVersion(3, 5)) { + return; + } + + final HashIndexOptions options = new HashIndexOptions(); + options.name("myHashIndex"); + + final Collection fields = new ArrayList(); + fields.add("a"); + fields.add("b"); + final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensureHashIndex(fields, options); + assertThat(indexResult, is(notNullValue())); + assertThat(indexResult.getConstraint(), is(nullValue())); + assertThat(indexResult.getFields(), hasItem("a")); + assertThat(indexResult.getFields(), hasItem("b")); + assertThat(indexResult.getId(), startsWith(COLLECTION_NAME)); + assertThat(indexResult.getIsNewlyCreated(), is(true)); + assertThat(indexResult.getMinLength(), is(nullValue())); + if (arangoDB.getRole() == ServerRole.SINGLE) { + assertThat(indexResult.getSelectivityEstimate(), is(1.)); + } + assertThat(indexResult.getSparse(), is(false)); + assertThat(indexResult.getType(), is(IndexType.hash)); + assertThat(indexResult.getUnique(), is(false)); + assertThat(indexResult.getName(), is("myHashIndex")); + } + @Test public void createGeoIndex() { final Collection fields = new ArrayList(); @@ -1063,6 +1084,33 @@ public void createGeoIndex() { } } + @Test + public void createGeoIndexWithOptions() { + if (!requireVersion(3, 5)) { + return; + } + + final GeoIndexOptions options = new GeoIndexOptions(); + options.name("myGeoIndex1"); + + final Collection fields = new ArrayList(); + fields.add("a"); + final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensureGeoIndex(fields, options); + assertThat(indexResult, is(notNullValue())); + assertThat(indexResult.getFields(), hasItem("a")); + assertThat(indexResult.getId(), startsWith(COLLECTION_NAME)); + assertThat(indexResult.getIsNewlyCreated(), is(true)); + assertThat(indexResult.getMinLength(), is(nullValue())); + assertThat(indexResult.getSparse(), is(true)); + assertThat(indexResult.getUnique(), is(false)); + if (requireVersion(3, 4)) { + assertThat(indexResult.getType(), is(IndexType.geo)); + } else { + assertThat(indexResult.getType(), is(IndexType.geo1)); + } + assertThat(indexResult.getName(), is("myGeoIndex1")); + } + @Test public void createGeo2Index() { final Collection fields = new ArrayList(); @@ -1084,6 +1132,35 @@ public void createGeo2Index() { } } + @Test + public void createGeo2IndexWithOptions() { + if (!requireVersion(3, 5)) { + return; + } + + final GeoIndexOptions options = new GeoIndexOptions(); + options.name("myGeoIndex2"); + + final Collection fields = new ArrayList(); + fields.add("a"); + fields.add("b"); + final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensureGeoIndex(fields, options); + assertThat(indexResult, is(notNullValue())); + assertThat(indexResult.getFields(), hasItem("a")); + assertThat(indexResult.getFields(), hasItem("b")); + assertThat(indexResult.getId(), startsWith(COLLECTION_NAME)); + assertThat(indexResult.getIsNewlyCreated(), is(true)); + assertThat(indexResult.getMinLength(), is(nullValue())); + assertThat(indexResult.getSparse(), is(true)); + assertThat(indexResult.getUnique(), is(false)); + if (requireVersion(3, 4)) { + assertThat(indexResult.getType(), is(IndexType.geo)); + } else { + assertThat(indexResult.getType(), is(IndexType.geo2)); + } + assertThat(indexResult.getName(), is("myGeoIndex2")); + } + @Test public void createSkiplistIndex() { final Collection fields = new ArrayList(); @@ -1102,6 +1179,32 @@ public void createSkiplistIndex() { assertThat(indexResult.getUnique(), is(false)); } + @Test + public void createSkiplistIndexWithOptions() { + if (!requireVersion(3, 5)) { + return; + } + + final SkiplistIndexOptions options = new SkiplistIndexOptions(); + options.name("mySkiplistIndex"); + + final Collection fields = new ArrayList(); + fields.add("a"); + fields.add("b"); + final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensureSkiplistIndex(fields, options); + assertThat(indexResult, is(notNullValue())); + assertThat(indexResult.getConstraint(), is(nullValue())); + assertThat(indexResult.getFields(), hasItem("a")); + assertThat(indexResult.getFields(), hasItem("b")); + assertThat(indexResult.getId(), startsWith(COLLECTION_NAME)); + assertThat(indexResult.getIsNewlyCreated(), is(true)); + assertThat(indexResult.getMinLength(), is(nullValue())); + assertThat(indexResult.getSparse(), is(false)); + assertThat(indexResult.getType(), is(IndexType.skiplist)); + assertThat(indexResult.getUnique(), is(false)); + assertThat(indexResult.getName(), is("mySkiplistIndex")); + } + @Test public void createPersistentIndex() { final Collection fields = new ArrayList(); @@ -1120,6 +1223,32 @@ public void createPersistentIndex() { assertThat(indexResult.getUnique(), is(false)); } + @Test + public void createPersistentIndexWithOptions() { + if (!requireVersion(3, 5)) { + return; + } + + final PersistentIndexOptions options = new PersistentIndexOptions(); + options.name("myPersistentIndex"); + + final Collection fields = new ArrayList(); + fields.add("a"); + fields.add("b"); + final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensurePersistentIndex(fields, options); + assertThat(indexResult, is(notNullValue())); + assertThat(indexResult.getConstraint(), is(nullValue())); + assertThat(indexResult.getFields(), hasItem("a")); + assertThat(indexResult.getFields(), hasItem("b")); + assertThat(indexResult.getId(), startsWith(COLLECTION_NAME)); + assertThat(indexResult.getIsNewlyCreated(), is(true)); + assertThat(indexResult.getMinLength(), is(nullValue())); + assertThat(indexResult.getSparse(), is(false)); + assertThat(indexResult.getType(), is(IndexType.persistent)); + assertThat(indexResult.getUnique(), is(false)); + assertThat(indexResult.getName(), is("myPersistentIndex")); + } + @Test public void createFulltextIndex() { final Collection fields = new ArrayList(); @@ -1135,6 +1264,29 @@ public void createFulltextIndex() { assertThat(indexResult.getUnique(), is(false)); } + @Test + public void createFulltextIndexWithOptions() { + if (!requireVersion(3, 5)) { + return; + } + + final FulltextIndexOptions options = new FulltextIndexOptions(); + options.name("myFulltextIndex"); + + final Collection fields = new ArrayList(); + fields.add("a"); + final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensureFulltextIndex(fields, options); + assertThat(indexResult, is(notNullValue())); + assertThat(indexResult.getConstraint(), is(nullValue())); + assertThat(indexResult.getFields(), hasItem("a")); + assertThat(indexResult.getId(), startsWith(COLLECTION_NAME)); + assertThat(indexResult.getIsNewlyCreated(), is(true)); + assertThat(indexResult.getSparse(), is(true)); + assertThat(indexResult.getType(), is(IndexType.fulltext)); + assertThat(indexResult.getUnique(), is(false)); + assertThat(indexResult.getName(), is("myFulltextIndex")); + } + @Test public void getIndexes() { final Collection fields = new ArrayList();