Skip to content

Commit 4dd75a5

Browse files
committed
2 parents 24cc5bd + 07ceff4 commit 4dd75a5

File tree

8 files changed

+115
-6
lines changed

8 files changed

+115
-6
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11

22
This library is a Java driver for ArangoDB.
33

4-
Supported version: ArangoDB-2.4.x
4+
Supported version: ArangoDB-2.4.x or ArangoDB 2.5.x
55

66
# Required
77

8-
* [ArangoDB](https://github.com/triAGENS/ArangoDB) version 2.4.x
8+
* [ArangoDB](https://github.com/arangodb/arangodb) version 2.4.x or 2.5.x
99
* Java 1.6 later
1010

1111

1212
# Basics
1313

1414
## Maven
1515

16-
To add the driver to your project with maven, add the following code to your pom.xml:
16+
To add the driver to your project with maven, add the following code to your pom.xml
17+
(please use a driver with a version number compatible to your ArangoDB server's version):
1718

1819
```XML
1920
<dependencies>
@@ -349,10 +350,13 @@ Now an edge can be created to set a relation between vertices
349350
null);
350351
```
351352

352-
# What's new in 2.4
353+
# What's new in 2.4 / 2.5
353354

354355
## since 2.4.1
355356
httpclient version 4.3.6
356357

357358
## since 2.4.2
358359
Fixed issue#2
360+
361+
## since 2.5.0
362+
Added support for sparse indexes

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.arangodb</groupId>
66
<artifactId>arangodb-java-driver</artifactId>
7-
<version>2.4.2</version>
7+
<version>2.5.0</version>
88
<inceptionYear>2012</inceptionYear>
99
<packaging>jar</packaging>
1010

src/main/java/com/arangodb/ArangoDriver.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,22 @@ public IndexEntity createIndex(long collectionId, IndexType type, boolean unique
19771977
throws ArangoException {
19781978
return createIndex(String.valueOf(collectionId), type, unique, fields);
19791979
}
1980+
1981+
/**
1982+
* This method creates an index for a collection.
1983+
*
1984+
* @param collectionId The collection id.
1985+
* @param type the index type.
1986+
* @param unique if set to true the index will be a unique index
1987+
* @param sparse if set to true the index will be sparse
1988+
* @param fields the fields (document attributes) the index is created on
1989+
* @return IndexEntity
1990+
* @throws ArangoException
1991+
*/
1992+
public IndexEntity createIndex(long collectionId, IndexType type, boolean unique, boolean sparse, String... fields)
1993+
throws ArangoException {
1994+
return createIndex(String.valueOf(collectionId), type, unique, sparse, fields);
1995+
}
19801996

19811997
/**
19821998
* This method creates an index for a collection.
@@ -1992,6 +2008,22 @@ public IndexEntity createIndex(String collectionName, IndexType type, boolean un
19922008
throws ArangoException {
19932009
return indexDriver.createIndex(getDefaultDatabase(), collectionName, type, unique, fields);
19942010
}
2011+
2012+
/**
2013+
* This method creates an index for a collection.
2014+
*
2015+
* @param collectionName The collection name.
2016+
* @param type the index type.
2017+
* @param unique if set to true the index will be a unique index
2018+
* @param sparse if set to true the index will be sparse
2019+
* @param fields the fields (document attributes) the index is created on
2020+
* @return IndexEntity
2021+
* @throws ArangoException
2022+
*/
2023+
public IndexEntity createIndex(String collectionName, IndexType type, boolean unique, boolean sparse, String... fields)
2024+
throws ArangoException {
2025+
return indexDriver.createIndex(getDefaultDatabase(), collectionName, type, unique, sparse, fields);
2026+
}
19952027

19962028
/**
19972029
* This method creates a hash index for a collection.
@@ -2005,6 +2037,20 @@ public IndexEntity createIndex(String collectionName, IndexType type, boolean un
20052037
public IndexEntity createHashIndex(String collectionName, boolean unique, String... fields) throws ArangoException {
20062038
return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.HASH, unique, fields);
20072039
}
2040+
2041+
/**
2042+
* This method creates a hash index for a collection.
2043+
*
2044+
* @param collectionName The collection name.
2045+
* @param unique if set to true the index will be a unique index
2046+
* @param sparse if set to true the index will be sparse
2047+
* @param fields the fields (document attributes) the index is created on
2048+
* @return IndexEntity
2049+
* @throws ArangoException
2050+
*/
2051+
public IndexEntity createHashIndex(String collectionName, boolean unique, boolean sparse, String... fields) throws ArangoException {
2052+
return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.HASH, unique, sparse, fields);
2053+
}
20082054

20092055
/**
20102056
* This method creates a geo index for a collection.
@@ -2032,6 +2078,21 @@ public IndexEntity createSkipListIndex(String collectionName, boolean unique, St
20322078
throws ArangoException {
20332079
return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.SKIPLIST, unique, fields);
20342080
}
2081+
2082+
/**
2083+
* This method creates a skip list index for a collection.
2084+
*
2085+
* @param collectionName The collection name.
2086+
* @param unique if set to true the index will be a unique index
2087+
* @param sparse if set to true the index will be sparse
2088+
* @param fields the fields (document attributes) the index is created on
2089+
* @return IndexEntity
2090+
* @throws ArangoException
2091+
*/
2092+
public IndexEntity createSkipListIndex(String collectionName, boolean unique, boolean sparse, String... fields)
2093+
throws ArangoException {
2094+
return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.SKIPLIST, unique, sparse, fields);
2095+
}
20352096

20362097
/**
20372098
* This method creates a capped index for a collection.

src/main/java/com/arangodb/InternalIndexDriver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* Created by fbartels on 10/27/14.
1010
*/
1111
public interface InternalIndexDriver extends BaseDriverInterface {
12+
IndexEntity createIndex(String database, String collectionName, IndexType type, boolean unique, boolean sparse, String... fields) throws ArangoException;
13+
1214
IndexEntity createIndex(String database, String collectionName, IndexType type, boolean unique, String... fields) throws ArangoException;
1315

1416
IndexEntity createCappedIndex(String database, String collectionName, int size) throws ArangoException;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ public IndexEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializati
748748
if (obj.has("unique")) {
749749
entity.unique = obj.getAsJsonPrimitive("unique").getAsBoolean();
750750
}
751+
752+
if (obj.has("sparse")) {
753+
entity.sparse = obj.getAsJsonPrimitive("sparse").getAsBoolean();
754+
}
751755

752756
if (obj.has("size")) {
753757
entity.size = obj.getAsJsonPrimitive("size").getAsInt();
@@ -756,6 +760,10 @@ public IndexEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializati
756760
if (obj.has("minLength")) {
757761
entity.minLength = obj.getAsJsonPrimitive("minLength").getAsInt();
758762
}
763+
764+
if (obj.has("selectivityEstimate")) {
765+
entity.selectivityEstimate = obj.getAsJsonPrimitive("selectivityEstimate").getAsDouble();
766+
}
759767

760768
return entity;
761769
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public class IndexEntity extends BaseEntity {
5757
* if true the index is a unique index.
5858
*/
5959
boolean unique;
60+
61+
/**
62+
* if true the index is sparse
63+
*/
64+
boolean sparse;
6065

6166
/**
6267
* the maximum amount of documents in case the index type is capped
@@ -67,6 +72,11 @@ public class IndexEntity extends BaseEntity {
6772
* minimum character length of words to index in case the index type is a fulltext
6873
*/
6974
int minLength;
75+
76+
/**
77+
* index selectivity estimate (if provided by the index)
78+
*/
79+
double selectivityEstimate;
7080

7181
public String getId() {
7282
return id;
@@ -86,9 +96,15 @@ public boolean isNewlyCreated() {
8696
public boolean isUnique() {
8797
return unique;
8898
}
99+
public boolean isSparse() {
100+
return sparse;
101+
}
89102
public int getSize() {
90103
return size;
91104
}
105+
public double getSelectivityEstimate() {
106+
return selectivityEstimate;
107+
}
92108
public void setId(String id) {
93109
this.id = id;
94110
}
@@ -107,6 +123,9 @@ public void setNewlyCreated(boolean isNewlyCreated) {
107123
public void setUnique(boolean unique) {
108124
this.unique = unique;
109125
}
126+
public void setSparse(boolean sparse) {
127+
this.sparse = sparse;
128+
}
110129
public void setSize(int size) {
111130
this.size = size;
112131
}
@@ -116,5 +135,8 @@ public int getMinLength() {
116135
public void setMinLength(int minLength) {
117136
this.minLength = minLength;
118137
}
138+
public void setSelectivityEstimate(double selectivityEstimate) {
139+
this.selectivityEstimate = selectivityEstimate;
140+
}
119141

120142
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
public enum IndexType {
2525
/** Primary Index */
2626
PRIMARY,
27+
/** Edge Index */
28+
EDGE,
2729
/** Cap Index */
2830
CAP,
2931
/** Geo Index */

src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ public class InternalIndexDriverImpl extends BaseArangoDriverWithCursorImpl impl
3939
}
4040

4141
@Override
42-
public IndexEntity createIndex(String database, String collectionName, IndexType type, boolean unique, String... fields) throws ArangoException {
42+
public IndexEntity createIndex(String database, String collectionName, IndexType type, boolean unique, boolean sparse, String... fields) throws ArangoException {
4343

4444
if (type == IndexType.PRIMARY) {
4545
throw new IllegalArgumentException("cannot create primary index.");
4646
}
47+
if (type == IndexType.EDGE) {
48+
throw new IllegalArgumentException("cannot create edge index.");
49+
}
4750
if (type == IndexType.CAP) {
4851
throw new IllegalArgumentException("cannot create cap index. use createCappedIndex.");
4952
}
@@ -56,6 +59,7 @@ public IndexEntity createIndex(String database, String collectionName, IndexType
5659
new MapBuilder()
5760
.put("type", type.name().toLowerCase(Locale.US))
5861
.put("unique", unique)
62+
.put("sparse", sparse)
5963
.put("fields", fields)
6064
.get()));
6165

@@ -69,6 +73,12 @@ public IndexEntity createIndex(String database, String collectionName, IndexType
6973
}
7074

7175
}
76+
77+
78+
@Override
79+
public IndexEntity createIndex(String database, String collectionName, IndexType type, boolean unique, String... fields) throws ArangoException {
80+
return createIndex(database, collectionName, type, unique, false, fields);
81+
}
7282

7383
@Override
7484
public IndexEntity createCappedIndex(String database, String collectionName, int size) throws ArangoException {

0 commit comments

Comments
 (0)