Skip to content

Commit f14d139

Browse files
author
a-brandt
committed
added function createPersistentIndex() (issue #48)
1 parent cbf07b8 commit f14d139

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

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

+26
Original file line numberDiff line numberDiff line change
@@ -2399,6 +2399,32 @@ public IndexEntity createSkipListIndex(
23992399
fields);
24002400
}
24012401

2402+
/**
2403+
* It is possible to define a persistent index on one or more attributes (or
2404+
* paths) of documents. The index is then used in queries to locate
2405+
* documents within a given range. If the index is declared unique, then no
2406+
* two documents are allowed to have the same set of attribute values.
2407+
*
2408+
* @param collectionName
2409+
* The collection name.
2410+
* @param unique
2411+
* if set to true the index will be a unique index
2412+
* @param sparse
2413+
* if set to true the index will be sparse
2414+
* @param fields
2415+
* the fields (document attributes) the index is created on
2416+
* @return IndexEntity
2417+
* @throws ArangoException
2418+
*/
2419+
public IndexEntity createPersistentIndex(
2420+
final String collectionName,
2421+
final boolean unique,
2422+
final boolean sparse,
2423+
final String... fields) throws ArangoException {
2424+
return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.PERSISTENT, unique, sparse,
2425+
fields);
2426+
}
2427+
24022428
/**
24032429
* This method creates a full text index for a collection.
24042430
*

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)