Skip to content

Commit 71b825b

Browse files
author
a-brandt
committed
added function createPersistentIndex() (issue #48)
1 parent be3463f commit 71b825b

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Diff for: src/main/java/com/arangodb/ArangoDriver.java

+26
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,32 @@ public IndexEntity createSkipListIndex(
14911491
fields);
14921492
}
14931493

1494+
/**
1495+
* It is possible to define a persistent index on one or more attributes (or
1496+
* paths) of documents. The index is then used in queries to locate
1497+
* documents within a given range. If the index is declared unique, then no
1498+
* two documents are allowed to have the same set of attribute values.
1499+
*
1500+
* @param collectionName
1501+
* The collection name.
1502+
* @param unique
1503+
* if set to true the index will be a unique index
1504+
* @param sparse
1505+
* if set to true the index will be sparse
1506+
* @param fields
1507+
* the fields (document attributes) the index is created on
1508+
* @return IndexEntity
1509+
* @throws ArangoException
1510+
*/
1511+
public IndexEntity createPersistentIndex(
1512+
final String collectionName,
1513+
final boolean unique,
1514+
final boolean sparse,
1515+
final String... fields) throws ArangoException {
1516+
return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.PERSISTENT, unique, sparse,
1517+
fields);
1518+
}
1519+
14941520
/**
14951521
* This method creates a full text index for a collection.
14961522
*

Diff for: src/test/java/com/arangodb/ArangoDriverIndexTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,22 @@ public void test_create_persistent_index() throws ArangoException {
286286

287287
}
288288

289+
@Test
290+
public void test_create_persistent_index2() throws ArangoException {
291+
292+
final IndexEntity entity = driver.createPersistentIndex(collectionName, true, false, "a", "b", "c", "d", "e",
293+
"f", "g");
294+
295+
assertThat(entity, is(notNullValue()));
296+
assertThat(entity.getCode(), is(201));
297+
assertThat(entity.isError(), is(false));
298+
assertThat(entity.isNewlyCreated(), is(true));
299+
assertThat(entity.isGeoJson(), is(false));
300+
assertThat(entity.getId(), is(notNullValue()));
301+
assertThat(entity.getType(), is(IndexType.PERSISTENT));
302+
303+
}
304+
289305
@Test
290306
public void test_delete_index() throws ArangoException {
291307

0 commit comments

Comments
 (0)