Skip to content

Commit 5b6d9a6

Browse files
author
a-brandt
committed
fixes for ArangoDB 3.0.0
1 parent 6e0e202 commit 5b6d9a6

16 files changed

+771
-825
lines changed

src/main/java/com/arangodb/ArangoClient.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,16 @@ public ArangoClient(ArangoConfigure configure) {
3636
driver = new ArangoDriver(configure);
3737
}
3838

39-
private void importDocumentsImpl(
40-
String collectionName,
41-
boolean createCollection,
42-
List<String> values,
43-
ImportResultEntity total) throws ArangoException {
44-
ImportResultEntity result = driver.importDocuments(collectionName, createCollection, values);
39+
private void importDocumentsImpl(String collectionName, List<String> values, ImportResultEntity total)
40+
throws ArangoException {
41+
ImportResultEntity result = driver.importDocuments(collectionName, values);
4542
total.setCreated(total.getCreated() + result.getCreated());
4643
total.setErrors(total.getErrors() + result.getErrors());
4744
total.setEmpty(total.getEmpty() + result.getEmpty());
4845
}
4946

50-
public ImportResultEntity importRawJsonDocuments(
51-
String collectionName,
52-
boolean createCollection,
53-
Iterator<String> itr,
54-
int bufferCount) throws ArangoException {
47+
public ImportResultEntity importRawJsonDocuments(String collectionName, Iterator<String> itr, int bufferCount)
48+
throws ArangoException {
5549

5650
int tmpBufferCount = bufferCount;
5751
if (tmpBufferCount <= 0) {
@@ -64,12 +58,12 @@ public ImportResultEntity importRawJsonDocuments(
6458
while (itr.hasNext()) {
6559
buffers.add(itr.next());
6660
if (buffers.size() % tmpBufferCount == 0) {
67-
importDocumentsImpl(collectionName, createCollection, buffers, total);
61+
importDocumentsImpl(collectionName, buffers, total);
6862
buffers.clear();
6963
}
7064
}
7165
if (!buffers.isEmpty()) {
72-
importDocumentsImpl(collectionName, createCollection, buffers, total);
66+
importDocumentsImpl(collectionName, buffers, total);
7367
}
7468

7569
return total;

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

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,18 +1608,6 @@ public <T> DocumentEntity<T> updateDocument(
16081608
keepNull);
16091609
}
16101610

1611-
/**
1612-
* This method returns all document handles from a collection.
1613-
*
1614-
* @param collectionId
1615-
* The collection id.
1616-
* @return List<String> - The list of document handles
1617-
* @throws ArangoException
1618-
*/
1619-
public List<String> getDocuments(long collectionId) throws ArangoException {
1620-
return getDocuments(String.valueOf(collectionId), false);
1621-
}
1622-
16231611
/**
16241612
* This method returns all document handles from a collection.
16251613
*
@@ -1629,35 +1617,7 @@ public List<String> getDocuments(long collectionId) throws ArangoException {
16291617
* @throws ArangoException
16301618
*/
16311619
public List<String> getDocuments(String collectionName) throws ArangoException {
1632-
return documentDriver.getDocuments(getDefaultDatabase(), collectionName, false);
1633-
}
1634-
1635-
/**
1636-
* This method returns all document handles from a collection.
1637-
*
1638-
* @param collectionId
1639-
* The collection id.
1640-
* @param handleConvert
1641-
* if set to true only the document identifiers are returned
1642-
* @return List<String> - The list of document handles
1643-
* @throws ArangoException
1644-
*/
1645-
public List<String> getDocuments(long collectionId, boolean handleConvert) throws ArangoException {
1646-
return getDocuments(String.valueOf(collectionId), handleConvert);
1647-
}
1648-
1649-
/**
1650-
* This method returns all document handles from a collection.
1651-
*
1652-
* @param collectionName
1653-
* The collection name.
1654-
* @param handleConvert
1655-
* if set to true only the document identifiers are returned
1656-
* @return List<String> - The list of document handles
1657-
* @throws ArangoException
1658-
*/
1659-
public List<String> getDocuments(String collectionName, boolean handleConvert) throws ArangoException {
1660-
return documentDriver.getDocuments(getDefaultDatabase(), collectionName, handleConvert);
1620+
return documentDriver.getDocuments(getDefaultDatabase(), collectionName);
16611621
}
16621622

16631623
/**
@@ -3713,36 +3673,29 @@ public List<UserEntity> getUsers() throws ArangoException {
37133673
*
37143674
* @param collection
37153675
* the collection as a string
3716-
* @param createCollection
3717-
* if set to true the collection is created if it does not exist
37183676
* @param values
37193677
* a list of Objects that will be stored as documents
37203678
* @return ImportResultEntity
37213679
* @throws ArangoException
37223680
*/
3723-
public ImportResultEntity importDocuments(String collection, Boolean createCollection, Collection<?> values)
3724-
throws ArangoException {
3725-
return importDriver.importDocuments(getDefaultDatabase(), collection, createCollection, values);
3681+
public ImportResultEntity importDocuments(String collection, Collection<?> values) throws ArangoException {
3682+
return importDriver.importDocuments(getDefaultDatabase(), collection, values);
37263683
}
37273684

37283685
/**
37293686
* Creates documents in the collection.
37303687
*
37313688
* @param collection
37323689
* the collection as a string
3733-
* @param createCollection
3734-
* if set to true the collection is created if it does not exist
37353690
* @param headerValues
37363691
* a list of lists that will be stored as documents
37373692
* @return ImportResultEntity
37383693
* @throws ArangoException
37393694
*/
37403695
public ImportResultEntity importDocumentsByHeaderValues(
37413696
String collection,
3742-
Boolean createCollection,
37433697
Collection<? extends Collection<?>> headerValues) throws ArangoException {
3744-
return importDriver.importDocumentsByHeaderValues(getDefaultDatabase(), collection, createCollection,
3745-
headerValues);
3698+
return importDriver.importDocumentsByHeaderValues(getDefaultDatabase(), collection, headerValues);
37463699
}
37473700

37483701
/**

src/main/java/com/arangodb/InternalDocumentDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ DocumentEntity<String> updateDocumentRaw(
5959
Boolean waitForSync,
6060
Boolean keepNull) throws ArangoException;
6161

62-
List<String> getDocuments(String database, String collectionName, boolean handleConvert) throws ArangoException;
62+
List<String> getDocuments(String database, String collectionName) throws ArangoException;
6363

6464
long checkDocument(String database, String documentHandle) throws ArangoException;
6565

src/main/java/com/arangodb/InternalImportDriver.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
/**
99
* Created by fbartels on 10/27/14.
1010
*/
11-
public interface InternalImportDriver extends BaseDriverInterface {
12-
ImportResultEntity importDocuments(String database, String collection, Boolean createCollection, Collection<?> values) throws ArangoException;
11+
public interface InternalImportDriver extends BaseDriverInterface {
12+
13+
ImportResultEntity importDocuments(String database, String collection, Collection<?> values) throws ArangoException;
14+
15+
ImportResultEntity importDocumentsByHeaderValues(
16+
String database,
17+
String collection,
18+
Collection<? extends Collection<?>> headerValues) throws ArangoException;
1319

14-
ImportResultEntity importDocumentsByHeaderValues(String database, String collection, Boolean createCollection, Collection<? extends Collection<?>> headerValues) throws ArangoException;
1520
}

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616

1717
package com.arangodb.entity;
1818

19+
import java.util.HashMap;
1920
import java.util.List;
2021
import java.util.Map;
2122

23+
import com.arangodb.util.CollectionUtils;
24+
2225
/**
2326
* A entity representing a list of ArangoDB collections
2427
*
@@ -30,30 +33,28 @@ public class CollectionsEntity extends BaseEntity {
3033
/**
3134
* The list of collections
3235
*/
33-
List<CollectionEntity> collections;
34-
35-
/**
36-
* A map containing the collection names as keys and the collections as
37-
* values
38-
*/
39-
Map<String, CollectionEntity> names;
36+
private List<CollectionEntity> collections;
4037

4138
public List<CollectionEntity> getCollections() {
4239
return collections;
4340
}
4441

4542
public Map<String, CollectionEntity> getNames() {
43+
Map<String, CollectionEntity> names = new HashMap<String, CollectionEntity>();
44+
45+
if (CollectionUtils.isNotEmpty(collections)) {
46+
for (CollectionEntity collectionEntity : collections) {
47+
names.put(collectionEntity.getName(), collectionEntity);
48+
}
49+
}
50+
4651
return names;
4752
}
4853

4954
public void setCollections(List<CollectionEntity> collections) {
5055
this.collections = collections;
5156
}
5257

53-
public void setNames(Map<String, CollectionEntity> names) {
54-
this.names = names;
55-
}
56-
5758
@Override
5859
public String toString() {
5960
return "CollectionsEntity [collections=" + collections + "]";

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,8 @@ public CollectionEntity deserialize(JsonElement json, Type typeOfT, JsonDeserial
537537
public static class CollectionsEntityDeserializer implements JsonDeserializer<CollectionsEntity> {
538538
private Type collectionsType = new TypeToken<List<CollectionEntity>>() {
539539
}.getType();
540-
private Type namesType = new TypeToken<Map<String, CollectionEntity>>() {
541-
}.getType();
542540

541+
@SuppressWarnings("unchecked")
543542
@Override
544543
public CollectionsEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
545544

@@ -550,11 +549,10 @@ public CollectionsEntity deserialize(JsonElement json, Type typeOfT, JsonDeseria
550549
JsonObject obj = json.getAsJsonObject();
551550
CollectionsEntity entity = deserializeBaseParameter(obj, new CollectionsEntity());
552551

553-
if (obj.has(COLLECTIONS)) {
554-
entity.collections = context.deserialize(obj.get(COLLECTIONS), collectionsType);
555-
}
556-
if (obj.has("names")) {
557-
entity.names = context.deserialize(obj.get("names"), namesType);
552+
if (obj.has(RESULT)) {
553+
entity.setCollections((List<CollectionEntity>) context.deserialize(obj.get(RESULT), collectionsType));
554+
} else {
555+
entity.setCollections(new ArrayList<CollectionEntity>());
558556
}
559557

560558
return entity;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static GsonBuilder getGsonBuilder() {
5959
.setFieldNamingStrategy(new ArangoFieldNamingStrategy())
6060
.registerTypeAdapter(CollectionStatus.class, new CollectionStatusTypeAdapter())
6161
.registerTypeAdapter(CollectionEntity.class, new EntityDeserializers.CollectionEntityDeserializer())
62+
.registerTypeAdapter(CollectionsEntity.class, new EntityDeserializers.CollectionsEntityDeserializer())
6263
.registerTypeAdapter(DocumentEntity.class, new EntityDeserializers.DocumentEntityDeserializer())
6364
.registerTypeAdapter(DocumentsEntity.class, new EntityDeserializers.DocumentsEntityDeserializer())
6465
.registerTypeAdapter(AqlFunctionsEntity.class, new EntityDeserializers.AqlfunctionsEntityDeserializer())

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,31 +205,14 @@ public DocumentEntity<String> updateDocumentRaw(
205205
}
206206

207207
@Override
208-
public List<String> getDocuments(String database, String collectionName, boolean handleConvert)
209-
throws ArangoException {
210-
211-
// HttpResponseEntity res =
212-
// httpManager.doGet(createDocumentEndpointUrl(database),
213-
// new MapBuilder("collection", collectionName).get());
214-
208+
public List<String> getDocuments(String database, String collectionName) throws ArangoException {
215209
HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/all-keys"), null,
216-
EntityFactory.toJsonString(new MapBuilder().put("collection", collectionName).get()));
210+
EntityFactory.toJsonString(new MapBuilder().put("collection", collectionName).put("type", "id").get()));
217211

218212
@SuppressWarnings("unchecked")
219213
CursorEntity<String> tmp = createEntity(res, CursorEntity.class, String.class);
220214

221215
return tmp.getResults();
222-
//
223-
//
224-
// DocumentResultEntity entity = createEntity(res,
225-
// DocumentResultEntity.class);
226-
// List<String> documents =
227-
// CollectionUtils.safety(entity.getDocuments());
228-
//
229-
// if (handleConvert && !documents.isEmpty()) {
230-
// updateDocumentHandles(documents);
231-
// }
232-
// return documents;
233216
}
234217

235218
private void updateDocumentHandles(List<String> documents) {

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,11 @@ public class InternalImportDriverImpl extends BaseArangoDriverImpl implements co
3939
}
4040

4141
@Override
42-
public ImportResultEntity importDocuments(
43-
String database,
44-
String collection,
45-
Boolean createCollection,
46-
Collection<?> values) throws ArangoException {
42+
public ImportResultEntity importDocuments(String database, String collection, Collection<?> values)
43+
throws ArangoException {
4744

48-
HttpResponseEntity res = httpManager.doPost(
49-
createEndpointUrl(database, "/_api/import"), new MapBuilder().put("collection", collection)
50-
.put("createCollection", createCollection).put("type", "array").get(),
45+
HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/import"),
46+
new MapBuilder().put("collection", collection).put("type", "array").get(),
5147
EntityFactory.toJsonString(values));
5248

5349
return createEntity(res, ImportResultEntity.class);
@@ -58,12 +54,10 @@ public ImportResultEntity importDocuments(
5854
public ImportResultEntity importDocumentsByHeaderValues(
5955
String database,
6056
String collection,
61-
Boolean createCollection,
6257
Collection<? extends Collection<?>> headerValues) throws ArangoException {
6358

6459
HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/import"),
65-
new MapBuilder().put("collection", collection).put("createCollection", createCollection).get(),
66-
EntityFactory.toImportHeaderValues(headerValues));
60+
new MapBuilder().put("collection", collection).get(), EntityFactory.toImportHeaderValues(headerValues));
6761

6862
return createEntity(res, ImportResultEntity.class);
6963

0 commit comments

Comments
 (0)