Skip to content

Commit 3593c55

Browse files
author
mpv1989
committed
added ArangoCollection.ensure<IndexType>Index()
made ArangoCollection.create<IndexType>Index() deprecated
1 parent fd0e235 commit 3593c55

12 files changed

+145
-59
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ v4.2.x (xxxx-xx-xx)
22
---------------------------
33
* fixed ArangoDatabase.transaction(): ignore null result
44
* added properties validation arangodb.host
5+
* added ArangoCollection.ensure<IndexType>Index()
6+
* made ArangoCollection.create<IndexType>Index() deprecated
57

68
v4.2.3 (2017-07-31)
79
---------------------------

src/main/java/com/arangodb/ArangoCollection.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ public String deleteIndex(final String id) throws ArangoDBException {
588588
/**
589589
* Creates a hash index for the collection if it does not already exist.
590590
*
591+
* @deprecated use {@link #ensureHashIndex(Iterable, HashIndexOptions)} instead
591592
* @see <a href="https://docs.arangodb.com/current/HTTP/Indexes/Hash.html#create-hash-index">API Documentation</a>
592593
* @param fields
593594
* A list of attribute paths
@@ -596,14 +597,32 @@ public String deleteIndex(final String id) throws ArangoDBException {
596597
* @return information about the index
597598
* @throws ArangoDBException
598599
*/
600+
@Deprecated
599601
public IndexEntity createHashIndex(final Collection<String> fields, final HashIndexOptions options)
600602
throws ArangoDBException {
601603
return executor.execute(createHashIndexRequest(fields, options), IndexEntity.class);
602604
}
603605

606+
/**
607+
* Creates a hash index for the collection if it does not already exist.
608+
*
609+
* @see <a href="https://docs.arangodb.com/current/HTTP/Indexes/Hash.html#create-hash-index">API Documentation</a>
610+
* @param fields
611+
* A list of attribute paths
612+
* @param options
613+
* Additional options, can be null
614+
* @return information about the index
615+
* @throws ArangoDBException
616+
*/
617+
public IndexEntity ensureHashIndex(final Iterable<String> fields, final HashIndexOptions options)
618+
throws ArangoDBException {
619+
return executor.execute(createHashIndexRequest(fields, options), IndexEntity.class);
620+
}
621+
604622
/**
605623
* Creates a skip-list index for the collection, if it does not already exist.
606624
*
625+
* @deprecated use {@link #ensureSkiplistIndex(Collection, SkiplistIndexOptions)} instead
607626
* @see <a href="https://docs.arangodb.com/current/HTTP/Indexes/Skiplist.html#create-skip-list">API
608627
* Documentation</a>
609628
* @param fields
@@ -613,14 +632,33 @@ public IndexEntity createHashIndex(final Collection<String> fields, final HashIn
613632
* @return information about the index
614633
* @throws ArangoDBException
615634
*/
635+
@Deprecated
616636
public IndexEntity createSkiplistIndex(final Collection<String> fields, final SkiplistIndexOptions options)
617637
throws ArangoDBException {
618638
return executor.execute(createSkiplistIndexRequest(fields, options), IndexEntity.class);
619639
}
620640

641+
/**
642+
* Creates a skip-list index for the collection, if it does not already exist.
643+
*
644+
* @see <a href="https://docs.arangodb.com/current/HTTP/Indexes/Skiplist.html#create-skip-list">API
645+
* Documentation</a>
646+
* @param fields
647+
* A list of attribute paths
648+
* @param options
649+
* Additional options, can be null
650+
* @return information about the index
651+
* @throws ArangoDBException
652+
*/
653+
public IndexEntity ensureSkiplistIndex(final Iterable<String> fields, final SkiplistIndexOptions options)
654+
throws ArangoDBException {
655+
return executor.execute(createSkiplistIndexRequest(fields, options), IndexEntity.class);
656+
}
657+
621658
/**
622659
* Creates a persistent index for the collection, if it does not already exist.
623660
*
661+
* @deprecated use {@link #ensurePersistentIndex(Collection, PersistentIndexOptions)} instead
624662
* @see <a href="https://docs.arangodb.com/current/HTTP/Indexes/Persistent.html#create-a-persistent-index">API
625663
* Documentation</a>
626664
* @param fields
@@ -630,14 +668,33 @@ public IndexEntity createSkiplistIndex(final Collection<String> fields, final Sk
630668
* @return information about the index
631669
* @throws ArangoDBException
632670
*/
671+
@Deprecated
633672
public IndexEntity createPersistentIndex(final Collection<String> fields, final PersistentIndexOptions options)
634673
throws ArangoDBException {
635674
return executor.execute(createPersistentIndexRequest(fields, options), IndexEntity.class);
636675
}
637676

677+
/**
678+
* Creates a persistent index for the collection, if it does not already exist.
679+
*
680+
* @see <a href="https://docs.arangodb.com/current/HTTP/Indexes/Persistent.html#create-a-persistent-index">API
681+
* Documentation</a>
682+
* @param fields
683+
* A list of attribute paths
684+
* @param options
685+
* Additional options, can be null
686+
* @return information about the index
687+
* @throws ArangoDBException
688+
*/
689+
public IndexEntity ensurePersistentIndex(final Iterable<String> fields, final PersistentIndexOptions options)
690+
throws ArangoDBException {
691+
return executor.execute(createPersistentIndexRequest(fields, options), IndexEntity.class);
692+
}
693+
638694
/**
639695
* Creates a geo-spatial index for the collection, if it does not already exist.
640696
*
697+
* @deprecated use {@link #ensureGeoIndex(Collection, GeoIndexOptions)} instead
641698
* @see <a href="https://docs.arangodb.com/current/HTTP/Indexes/Geo.html#create-geospatial-index">API
642699
* Documentation</a>
643700
* @param fields
@@ -647,14 +704,33 @@ public IndexEntity createPersistentIndex(final Collection<String> fields, final
647704
* @return information about the index
648705
* @throws ArangoDBException
649706
*/
707+
@Deprecated
650708
public IndexEntity createGeoIndex(final Collection<String> fields, final GeoIndexOptions options)
651709
throws ArangoDBException {
652710
return executor.execute(createGeoIndexRequest(fields, options), IndexEntity.class);
653711
}
654712

713+
/**
714+
* Creates a geo-spatial index for the collection, if it does not already exist.
715+
*
716+
* @see <a href="https://docs.arangodb.com/current/HTTP/Indexes/Geo.html#create-geospatial-index">API
717+
* Documentation</a>
718+
* @param fields
719+
* A list of attribute paths
720+
* @param options
721+
* Additional options, can be null
722+
* @return information about the index
723+
* @throws ArangoDBException
724+
*/
725+
public IndexEntity ensureGeoIndex(final Iterable<String> fields, final GeoIndexOptions options)
726+
throws ArangoDBException {
727+
return executor.execute(createGeoIndexRequest(fields, options), IndexEntity.class);
728+
}
729+
655730
/**
656731
* Creates a fulltext index for the collection, if it does not already exist.
657732
*
733+
* @deprecated use {@link #ensureFulltextIndex(Collection, FulltextIndexOptions)} instead
658734
* @see <a href="https://docs.arangodb.com/current/HTTP/Indexes/Fulltext.html#create-fulltext-index">API
659735
* Documentation</a>
660736
* @param fields
@@ -664,11 +740,29 @@ public IndexEntity createGeoIndex(final Collection<String> fields, final GeoInde
664740
* @return information about the index
665741
* @throws ArangoDBException
666742
*/
743+
@Deprecated
667744
public IndexEntity createFulltextIndex(final Collection<String> fields, final FulltextIndexOptions options)
668745
throws ArangoDBException {
669746
return executor.execute(createFulltextIndexRequest(fields, options), IndexEntity.class);
670747
}
671748

749+
/**
750+
* Creates a fulltext index for the collection, if it does not already exist.
751+
*
752+
* @see <a href="https://docs.arangodb.com/current/HTTP/Indexes/Fulltext.html#create-fulltext-index">API
753+
* Documentation</a>
754+
* @param fields
755+
* A list of attribute paths
756+
* @param options
757+
* Additional options, can be null
758+
* @return information about the index
759+
* @throws ArangoDBException
760+
*/
761+
public IndexEntity ensureFulltextIndex(final Iterable<String> fields, final FulltextIndexOptions options)
762+
throws ArangoDBException {
763+
return executor.execute(createFulltextIndexRequest(fields, options), IndexEntity.class);
764+
}
765+
672766
/**
673767
* Returns all indexes of the collection
674768
*

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ private String createIndexId(final String id) {
560560
return index;
561561
}
562562

563-
protected Request createHashIndexRequest(final Collection<String> fields, final HashIndexOptions options) {
563+
protected Request createHashIndexRequest(final Iterable<String> fields, final HashIndexOptions options) {
564564
final Request request;
565565
request = new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
566566
request.putQueryParam(ArangoDBConstants.COLLECTION, name);
@@ -569,7 +569,7 @@ protected Request createHashIndexRequest(final Collection<String> fields, final
569569
return request;
570570
}
571571

572-
protected Request createSkiplistIndexRequest(final Collection<String> fields, final SkiplistIndexOptions options) {
572+
protected Request createSkiplistIndexRequest(final Iterable<String> fields, final SkiplistIndexOptions options) {
573573
final Request request;
574574
request = new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
575575
request.putQueryParam(ArangoDBConstants.COLLECTION, name);
@@ -579,7 +579,7 @@ protected Request createSkiplistIndexRequest(final Collection<String> fields, fi
579579
}
580580

581581
protected Request createPersistentIndexRequest(
582-
final Collection<String> fields,
582+
final Iterable<String> fields,
583583
final PersistentIndexOptions options) {
584584
final Request request;
585585
request = new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
@@ -589,7 +589,7 @@ protected Request createPersistentIndexRequest(
589589
return request;
590590
}
591591

592-
protected Request createGeoIndexRequest(final Collection<String> fields, final GeoIndexOptions options) {
592+
protected Request createGeoIndexRequest(final Iterable<String> fields, final GeoIndexOptions options) {
593593
final Request request;
594594
request = new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
595595
request.putQueryParam(ArangoDBConstants.COLLECTION, name);
@@ -598,6 +598,15 @@ protected Request createGeoIndexRequest(final Collection<String> fields, final G
598598
return request;
599599
}
600600

601+
protected Request createFulltextIndexRequest(final Iterable<String> fields, final FulltextIndexOptions options) {
602+
final Request request;
603+
request = new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
604+
request.putQueryParam(ArangoDBConstants.COLLECTION, name);
605+
request.setBody(
606+
util().serialize(OptionsBuilder.build(options != null ? options : new FulltextIndexOptions(), fields)));
607+
return request;
608+
}
609+
601610
protected Request getIndexesRequest() {
602611
final Request request;
603612
request = new Request(db.name(), RequestType.GET, ArangoDBConstants.PATH_API_INDEX);
@@ -626,15 +635,6 @@ protected Request countRequest() {
626635
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name, ArangoDBConstants.COUNT));
627636
}
628637

629-
protected Request createFulltextIndexRequest(final Collection<String> fields, final FulltextIndexOptions options) {
630-
final Request request;
631-
request = new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
632-
request.putQueryParam(ArangoDBConstants.COLLECTION, name);
633-
request.setBody(
634-
util().serialize(OptionsBuilder.build(options != null ? options : new FulltextIndexOptions(), fields)));
635-
return request;
636-
}
637-
638638
protected Request dropRequest(final Boolean isSystem) {
639639
return new Request(db.name(), RequestType.DELETE,
640640
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name))

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
package com.arangodb.model;
2222

23-
import java.util.Collection;
24-
2523
import com.arangodb.entity.IndexType;
2624

2725
/**
@@ -32,15 +30,15 @@
3230
*/
3331
public class FulltextIndexOptions {
3432

35-
private Collection<String> fields;
33+
private Iterable<String> fields;
3634
private final IndexType type = IndexType.fulltext;
3735
private Integer minLength;
3836

3937
public FulltextIndexOptions() {
4038
super();
4139
}
4240

43-
protected Collection<String> getFields() {
41+
protected Iterable<String> getFields() {
4442
return fields;
4543
}
4644

@@ -49,7 +47,7 @@ protected Collection<String> getFields() {
4947
* A list of attribute paths
5048
* @return options
5149
*/
52-
protected FulltextIndexOptions fields(final Collection<String> fields) {
50+
protected FulltextIndexOptions fields(final Iterable<String> fields) {
5351
this.fields = fields;
5452
return this;
5553
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
package com.arangodb.model;
2222

23-
import java.util.Collection;
24-
2523
import com.arangodb.entity.IndexType;
2624

2725
/**
@@ -31,15 +29,15 @@
3129
*/
3230
public class GeoIndexOptions {
3331

34-
private Collection<String> fields;
32+
private Iterable<String> fields;
3533
private final IndexType type = IndexType.geo;
3634
private Boolean geoJson;
3735

3836
public GeoIndexOptions() {
3937
super();
4038
}
4139

42-
protected Collection<String> getFields() {
40+
protected Iterable<String> getFields() {
4341
return fields;
4442
}
4543

@@ -48,7 +46,7 @@ protected Collection<String> getFields() {
4846
* A list of attribute paths
4947
* @return options
5048
*/
51-
protected GeoIndexOptions fields(final Collection<String> fields) {
49+
protected GeoIndexOptions fields(final Iterable<String> fields) {
5250
this.fields = fields;
5351
return this;
5452
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
package com.arangodb.model;
2222

23-
import java.util.Collection;
24-
2523
import com.arangodb.entity.IndexType;
2624

2725
/**
@@ -31,7 +29,7 @@
3129
*/
3230
public class HashIndexOptions {
3331

34-
private Collection<String> fields;
32+
private Iterable<String> fields;
3533
private final IndexType type = IndexType.hash;
3634
private Boolean unique;
3735
private Boolean sparse;
@@ -41,7 +39,7 @@ public HashIndexOptions() {
4139
super();
4240
}
4341

44-
protected Collection<String> getFields() {
42+
protected Iterable<String> getFields() {
4543
return fields;
4644
}
4745

@@ -50,7 +48,7 @@ protected Collection<String> getFields() {
5048
* A list of attribute paths
5149
* @return options
5250
*/
53-
protected HashIndexOptions fields(final Collection<String> fields) {
51+
protected HashIndexOptions fields(final Iterable<String> fields) {
5452
this.fields = fields;
5553
return this;
5654
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ public static UserCreateOptions build(final UserCreateOptions options, final Str
4040
return options.user(user).passwd(passwd);
4141
}
4242

43-
public static HashIndexOptions build(final HashIndexOptions options, final Collection<String> fields) {
43+
public static HashIndexOptions build(final HashIndexOptions options, final Iterable<String> fields) {
4444
return options.fields(fields);
4545
}
4646

47-
public static SkiplistIndexOptions build(final SkiplistIndexOptions options, final Collection<String> fields) {
47+
public static SkiplistIndexOptions build(final SkiplistIndexOptions options, final Iterable<String> fields) {
4848
return options.fields(fields);
4949
}
5050

51-
public static PersistentIndexOptions build(final PersistentIndexOptions options, final Collection<String> fields) {
51+
public static PersistentIndexOptions build(final PersistentIndexOptions options, final Iterable<String> fields) {
5252
return options.fields(fields);
5353
}
5454

55-
public static GeoIndexOptions build(final GeoIndexOptions options, final Collection<String> fields) {
55+
public static GeoIndexOptions build(final GeoIndexOptions options, final Iterable<String> fields) {
5656
return options.fields(fields);
5757
}
5858

59-
public static FulltextIndexOptions build(final FulltextIndexOptions options, final Collection<String> fields) {
59+
public static FulltextIndexOptions build(final FulltextIndexOptions options, final Iterable<String> fields) {
6060
return options.fields(fields);
6161
}
6262

0 commit comments

Comments
 (0)