Skip to content

Commit 2d12326

Browse files
author
a-brandt
committed
fixed sonarlint issue
1 parent d36aa68 commit 2d12326

File tree

4 files changed

+55
-51
lines changed

4 files changed

+55
-51
lines changed

src/main/java/com/arangodb/BaseArangoDriver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,8 @@ protected String createIndexEndpointUrl(String database, Object... paths) throws
467467
protected String createGharialEndpointUrl(String database, Object... paths) throws ArangoException {
468468
return createEndpointUrl(database, "/_api/gharial", paths);
469469
}
470+
471+
protected String createDocumentEndpointUrl(String database, Object... paths) throws ArangoException {
472+
return createEndpointUrl(database, "/_api/document", paths);
473+
}
470474
}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ private HttpResponseEntity getCursor(
9090
map.put("query", query);
9191
map.put("bindVars", bindVars == null ? Collections.emptyMap() : bindVars);
9292

93-
HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/cursor"), null,
94-
EntityFactory.toJsonString(map));
95-
return res;
93+
return httpManager.doPost(createEndpointUrl(database, "/_api/cursor"), null, EntityFactory.toJsonString(map));
9694
}
9795

9896
@SuppressWarnings("unchecked")
@@ -220,9 +218,7 @@ public <T> CursorResultSet<T> executeQueryWithResultSet(
220218
Boolean fullCount) throws ArangoException {
221219

222220
CursorEntity<T> entity = executeQuery(database, query, bindVars, clazz, calcCount, batchSize, fullCount);
223-
CursorResultSet<T> rs = new CursorResultSet<T>(database, this, entity, clazz);
224-
return rs;
225-
221+
return new CursorResultSet<T>(database, this, entity, clazz);
226222
}
227223

228224
@Deprecated
@@ -236,9 +232,7 @@ public <T> CursorResultSet<T> executeQueryWithResultSet(
236232
Integer batchSize) throws ArangoException {
237233

238234
CursorEntity<T> entity = executeQuery(database, query, bindVars, clazz, calcCount, batchSize, false);
239-
CursorResultSet<T> rs = new CursorResultSet<T>(database, this, entity, clazz);
240-
return rs;
241-
235+
return new CursorResultSet<T>(database, this, entity, clazz);
242236
}
243237

244238
@Override

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,19 @@
4242
*/
4343
public class InternalDocumentDriverImpl extends BaseArangoDriverImpl implements com.arangodb.InternalDocumentDriver {
4444

45+
private static final String WAIT_FOR_SYNC = "waitForSync";
46+
47+
private static final String POLICY = "policy";
48+
49+
private static final String API_DOCUMENT_PREFIX = "/_api/document/";
50+
51+
private static final Pattern pattern = Pattern.compile("^/_db/.*/_api/document/(.*)$");
52+
4553
InternalDocumentDriverImpl(ArangoConfigure configure, HttpManager httpManager) {
4654
super(configure, httpManager);
4755
}
4856

49-
private <T> DocumentEntity<T> _createDocument(
57+
private <T> DocumentEntity<T> internalCreateDocument(
5058
String database,
5159
String collectionName,
5260
String documentKey,
@@ -70,9 +78,9 @@ private <T> DocumentEntity<T> _createDocument(
7078
body = EntityFactory.toJsonString(value);
7179
}
7280

73-
HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/document"),
81+
HttpResponseEntity res = httpManager.doPost(createDocumentEndpointUrl(database),
7482
new MapBuilder().put("collection", collectionName).put("createCollection", createCollection)
75-
.put("waitForSync", waitForSync).get(),
83+
.put(WAIT_FOR_SYNC, waitForSync).get(),
7684
body);
7785

7886
@SuppressWarnings("unchecked")
@@ -93,7 +101,8 @@ public <T> DocumentEntity<T> createDocument(
93101
T value,
94102
Boolean createCollection,
95103
Boolean waitForSync) throws ArangoException {
96-
return _createDocument(database, collectionName, documentKey, value, createCollection, waitForSync, false);
104+
return internalCreateDocument(database, collectionName, documentKey, value, createCollection, waitForSync,
105+
false);
97106
}
98107

99108
@Override
@@ -103,8 +112,8 @@ public DocumentEntity<String> createDocumentRaw(
103112
String rawJsonObjectString,
104113
Boolean createCollection,
105114
Boolean waitForSync) throws ArangoException {
106-
return _createDocument(database, collectionName, null, rawJsonObjectString, createCollection, waitForSync,
107-
true);
115+
return internalCreateDocument(database, collectionName, null, rawJsonObjectString, createCollection,
116+
waitForSync, true);
108117
}
109118

110119
@SuppressWarnings("unchecked")
@@ -119,8 +128,8 @@ public <T> DocumentEntity<T> replaceDocument(
119128

120129
validateDocumentHandle(documentHandle);
121130
HttpResponseEntity res = httpManager.doPut(
122-
createEndpointUrl(database, "/_api/document", documentHandle), new MapBuilder().put("rev", rev)
123-
.put("policy", policy == null ? null : policy.name()).put("waitForSync", waitForSync).get(),
131+
createDocumentEndpointUrl(database, documentHandle), new MapBuilder().put("rev", rev)
132+
.put(POLICY, policy == null ? null : policy.name()).put(WAIT_FOR_SYNC, waitForSync).get(),
124133
EntityFactory.toJsonString(value));
125134

126135
DocumentEntity<T> result = createEntity(res, DocumentEntity.class);
@@ -140,9 +149,9 @@ public <T> DocumentEntity<T> updateDocument(
140149
Boolean keepNull) throws ArangoException {
141150

142151
validateDocumentHandle(documentHandle);
143-
HttpResponseEntity res = httpManager.doPatch(createEndpointUrl(database, "/_api/document", documentHandle),
144-
new MapBuilder().put("rev", rev).put("policy", policy == null ? null : policy.name())
145-
.put("waitForSync", waitForSync).put("keepNull", keepNull).get(),
152+
HttpResponseEntity res = httpManager.doPatch(createDocumentEndpointUrl(database, documentHandle),
153+
new MapBuilder().put("rev", rev).put(POLICY, policy == null ? null : policy.name())
154+
.put(WAIT_FOR_SYNC, waitForSync).put("keepNull", keepNull).get(),
146155
EntityFactory.toJsonString(value, keepNull != null && !keepNull));
147156

148157
@SuppressWarnings("unchecked")
@@ -153,14 +162,11 @@ public <T> DocumentEntity<T> updateDocument(
153162
return result;
154163
}
155164

156-
private static final String API_DOCUMENT_PREFIX = "/_api/document/";
157-
private static final Pattern pattern = Pattern.compile("^/_db/.*/_api/document/(.*)$");
158-
159165
@Override
160166
public List<String> getDocuments(String database, String collectionName, boolean handleConvert)
161167
throws ArangoException {
162168

163-
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/document"),
169+
HttpResponseEntity res = httpManager.doGet(createDocumentEndpointUrl(database),
164170
new MapBuilder("collection", collectionName).get());
165171

166172
DocumentsEntity entity = createEntity(res, DocumentsEntity.class);
@@ -186,8 +192,7 @@ public List<String> getDocuments(String database, String collectionName, boolean
186192
@Override
187193
public long checkDocument(String database, String documentHandle) throws ArangoException {
188194
validateDocumentHandle(documentHandle);
189-
HttpResponseEntity res = httpManager.doHead(createEndpointUrl(database, "/_api/document", documentHandle),
190-
null);
195+
HttpResponseEntity res = httpManager.doHead(createDocumentEndpointUrl(database, documentHandle), null);
191196

192197
DefaultEntity entity = createEntity(res, DefaultEntity.class);
193198
return entity.getEtag();
@@ -203,7 +208,7 @@ public <T> DocumentEntity<T> getDocument(
203208
Long ifMatchRevision) throws ArangoException {
204209

205210
validateDocumentHandle(documentHandle);
206-
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/document", documentHandle),
211+
HttpResponseEntity res = httpManager.doGet(createDocumentEndpointUrl(database, documentHandle),
207212
new MapBuilder().put("If-None-Match", ifNoneMatchRevision, true).put("If-Match", ifMatchRevision).get(),
208213
null);
209214
@SuppressWarnings("unchecked")
@@ -219,7 +224,7 @@ public String getDocumentRaw(String database, String documentHandle, Long ifNone
219224
throws ArangoException {
220225

221226
validateDocumentHandle(documentHandle);
222-
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/document", documentHandle),
227+
HttpResponseEntity res = httpManager.doGet(createDocumentEndpointUrl(database, documentHandle),
223228
new MapBuilder().put("If-None-Match", ifNoneMatchRevision, true).put("If-Match", ifMatchRevision).get(),
224229
null);
225230

@@ -241,12 +246,11 @@ public DocumentEntity<?> deleteDocument(String database, String documentHandle,
241246
throws ArangoException {
242247

243248
validateDocumentHandle(documentHandle);
244-
HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(database, "/_api/document", documentHandle),
245-
new MapBuilder().put("rev", rev).put("policy", policy == null ? null : policy.name().toLowerCase(Locale.US))
249+
HttpResponseEntity res = httpManager.doDelete(createDocumentEndpointUrl(database, documentHandle),
250+
new MapBuilder().put("rev", rev).put(POLICY, policy == null ? null : policy.name().toLowerCase(Locale.US))
246251
.get());
247252

248-
DocumentEntity<?> entity = createEntity(res, DocumentEntity.class);
249-
return entity;
253+
return createEntity(res, DocumentEntity.class);
250254
}
251255

252256
}

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,11 @@ public <T> VertexEntity<T> createVertex(
386386
result = new VertexEntity<T>();
387387
result.setEntity(vertex);
388388
} else {
389-
result = createEntity(res, VertexEntity.class, vertex.getClass());
389+
if (vertex != null) {
390+
result = createEntity(res, VertexEntity.class, vertex.getClass());
391+
} else {
392+
result = createEntity(res, VertexEntity.class);
393+
}
390394
result.setEntity(vertex);
391395
annotationHandler.updateDocumentAttributes(result.getEntity(), result.getDocumentRevision(),
392396
result.getDocumentHandle(), result.getDocumentKey());
@@ -425,8 +429,7 @@ public <T> VertexEntity<T> getVertex(
425429
HttpResponseEntity res = httpManager.doGet(
426430
createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX,
427431
StringUtils.encodeUrl(collectionName), StringUtils.encodeUrl(key)),
428-
new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true)
429-
.get(),
432+
new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true).get(),
430433
new MapBuilder().get());
431434

432435
return createEntity(res, VertexEntity.class, clazz);
@@ -448,15 +451,17 @@ public <T> VertexEntity<T> replaceVertex(
448451
HttpResponseEntity res = httpManager.doPut(
449452
createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX,
450453
StringUtils.encodeUrl(collectionName), StringUtils.encodeUrl(key)),
451-
new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true)
452-
.get(),
454+
new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true).get(),
453455
new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), EntityFactory.toJsonString(vertex));
454456

455-
VertexEntity<T> result = createEntity(res, VertexEntity.class, vertex.getClass());
457+
VertexEntity<T> result;
456458
if (vertex != null) {
459+
result = createEntity(res, VertexEntity.class, vertex.getClass());
457460
result.setEntity(vertex);
458461
annotationHandler.updateDocumentAttributes(result.getEntity(), result.getDocumentRevision(),
459462
result.getDocumentHandle(), result.getDocumentKey());
463+
} else {
464+
result = createEntity(res, VertexEntity.class);
460465
}
461466
return result;
462467
}
@@ -478,16 +483,18 @@ public <T> VertexEntity<T> updateVertex(
478483
HttpResponseEntity res = httpManager.doPatch(
479484
createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX,
480485
StringUtils.encodeUrl(collectionName), StringUtils.encodeUrl(key)),
481-
new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true)
482-
.get(),
486+
new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true).get(),
483487
new MapBuilder().put("keepNull", keepNull).put(WAIT_FOR_SYNC, waitForSync).get(),
484488
EntityFactory.toJsonString(vertex, keepNull != null && !keepNull));
485489

486-
VertexEntity<T> result = createEntity(res, VertexEntity.class, vertex.getClass());
490+
VertexEntity<T> result;
487491
if (vertex != null) {
492+
result = createEntity(res, VertexEntity.class, vertex.getClass());
488493
result.setEntity(vertex);
489494
annotationHandler.updateDocumentAttributes(result.getEntity(), result.getDocumentRevision(),
490495
result.getDocumentHandle(), result.getDocumentKey());
496+
} else {
497+
result = createEntity(res, VertexEntity.class);
491498
}
492499
return result;
493500
}
@@ -506,8 +513,7 @@ public DeletedEntity deleteVertex(
506513
HttpResponseEntity res = httpManager.doDelete(
507514
createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX,
508515
StringUtils.encodeUrl(collectionName), StringUtils.encodeUrl(key)),
509-
new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true)
510-
.get(),
516+
new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true).get(),
511517
new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get());
512518

513519
return createEntity(res, DeletedEntity.class);
@@ -575,8 +581,7 @@ public <T> EdgeEntity<T> getEdge(
575581
HttpResponseEntity res = httpManager.doGet(
576582
createGharialEndpointUrl(database, StringUtils.encodeUrl(graphName), EDGE,
577583
StringUtils.encodeUrl(edgeCollectionName), StringUtils.encodeUrl(key)),
578-
new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true)
579-
.get(),
584+
new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true).get(),
580585
new MapBuilder().get());
581586

582587
return createEntity(res, EdgeEntity.class, clazz);
@@ -596,8 +601,7 @@ public DeletedEntity deleteEdge(
596601
HttpResponseEntity res = httpManager.doDelete(
597602
createEndpointUrl(database, "/_api/gharial", StringUtils.encodeUrl(graphName), EDGE,
598603
StringUtils.encodeUrl(edgeCollectionName), StringUtils.encodeUrl(key)),
599-
new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true)
600-
.get(),
604+
new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true).get(),
601605
new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get());
602606

603607
return createEntity(res, DeletedEntity.class);
@@ -620,8 +624,7 @@ public <T> EdgeEntity<T> replaceEdge(
620624
HttpResponseEntity res = httpManager.doPut(
621625
createGharialEndpointUrl(database, StringUtils.encodeUrl(graphName), EDGE,
622626
StringUtils.encodeUrl(edgeCollectionName), StringUtils.encodeUrl(key)),
623-
new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true)
624-
.get(),
627+
new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true).get(),
625628
new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(),
626629
value == null ? null : EntityFactory.toJsonString(value));
627630

@@ -651,8 +654,7 @@ public <T> EdgeEntity<T> updateEdge(
651654
HttpResponseEntity res = httpManager.doPatch(
652655
createGharialEndpointUrl(database, StringUtils.encodeUrl(graphName), EDGE,
653656
StringUtils.encodeUrl(edgeCollectionName), StringUtils.encodeUrl(key)),
654-
new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true)
655-
.get(),
657+
new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true).get(),
656658
new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).put("keepNull", keepNull).get(),
657659
value == null ? null : EntityFactory.toJsonString(value));
658660

0 commit comments

Comments
 (0)