Skip to content

Commit 32a41e7

Browse files
author
a-brandt
committed
fixed sonarlint issue
1 parent 9ef8181 commit 32a41e7

File tree

3 files changed

+69
-130
lines changed

3 files changed

+69
-130
lines changed

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

Lines changed: 43 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
*/
104104
public class ArangoDriver extends BaseArangoDriver {
105105

106+
private static final String GRAPH_NAME = "graphName";
107+
private static final String VERTEX_EXAMPLE = "vertexExample";
106108
private ArangoConfigure configure;
107109
private BatchHttpManager httpManager;
108110

@@ -450,8 +452,7 @@ public DefaultEntity executeBatch() throws ArangoException {
450452
}
451453
List<BatchPart> callStack = this.httpManager.getCallStack();
452454
this.cancelBatchMode();
453-
DefaultEntity result = this.batchDriver.executeBatch(callStack, this.getDefaultDatabase());
454-
return result;
455+
return this.batchDriver.executeBatch(callStack, this.getDefaultDatabase());
455456
}
456457

457458
/**
@@ -1977,10 +1978,6 @@ public <T> DocumentEntity<T> getDocument(String collectionName, String documentK
19771978
* @throws ArangoException
19781979
*/
19791980
public <T> DocumentEntity<T> getDocument(String documentHandle, Class<T> clazz) throws ArangoException {
1980-
// if (clazz.getName() == BaseDocument.class.getName()) {
1981-
// return documentDriver.getDocument(getDefaultDatabase(),
1982-
// documentHandle, clazz, null, null);
1983-
// }
19841981
return documentDriver.getDocument(getDefaultDatabase(), documentHandle, clazz, null, null);
19851982
}
19861983

@@ -2431,13 +2428,9 @@ public <T> DocumentCursor<T> executeDocumentQuery(
24312428
AqlQueryOptions aqlQueryOptions,
24322429
Class<T> clazz) throws ArangoException {
24332430

2434-
if (aqlQueryOptions == null) {
2435-
aqlQueryOptions = getDefaultAqlQueryOptions();
2436-
}
2437-
24382431
@SuppressWarnings("unchecked")
24392432
DocumentCursorResult<T, DocumentEntity<T>> baseCursor = cursorDriver.executeBaseCursorQuery(
2440-
getDefaultDatabase(), query, bindVars, aqlQueryOptions, DocumentEntity.class, clazz);
2433+
getDefaultDatabase(), query, bindVars, getAqlQueryOptions(aqlQueryOptions), DocumentEntity.class, clazz);
24412434
return new DocumentCursor<T>(baseCursor);
24422435
}
24432436

@@ -2462,11 +2455,8 @@ public <T> CursorResult<T> executeAqlQuery(
24622455
AqlQueryOptions aqlQueryOptions,
24632456
Class<T> clazz) throws ArangoException {
24642457

2465-
if (aqlQueryOptions == null) {
2466-
aqlQueryOptions = getDefaultAqlQueryOptions();
2467-
}
2468-
2469-
return cursorDriver.executeAqlQuery(getDefaultDatabase(), query, bindVars, aqlQueryOptions, clazz);
2458+
return cursorDriver.executeAqlQuery(getDefaultDatabase(), query, bindVars, getAqlQueryOptions(aqlQueryOptions),
2459+
clazz);
24702460
}
24712461

24722462
/**
@@ -2484,11 +2474,8 @@ public <T> CursorResult<T> executeAqlQuery(
24842474
public String executeAqlQueryJSON(String query, Map<String, Object> bindVars, AqlQueryOptions aqlQueryOptions)
24852475
throws ArangoException {
24862476

2487-
if (aqlQueryOptions == null) {
2488-
aqlQueryOptions = getDefaultAqlQueryOptions();
2489-
}
2490-
2491-
return cursorDriver.executeAqlQueryJSON(getDefaultDatabase(), query, bindVars, aqlQueryOptions);
2477+
return cursorDriver.executeAqlQueryJSON(getDefaultDatabase(), query, bindVars,
2478+
getAqlQueryOptions(aqlQueryOptions));
24922479
}
24932480

24942481
/**
@@ -2513,12 +2500,8 @@ public <T, S extends DocumentEntity<T>> DocumentCursorResult<T, S> executeAqlQue
25132500
Class<S> classDocumentEntity,
25142501
Class<T> clazz) throws ArangoException {
25152502

2516-
if (aqlQueryOptions == null) {
2517-
aqlQueryOptions = getDefaultAqlQueryOptions();
2518-
}
2519-
2520-
return cursorDriver.executeBaseCursorQuery(getDefaultDatabase(), query, bindVars, aqlQueryOptions,
2521-
classDocumentEntity, clazz);
2503+
return cursorDriver.executeBaseCursorQuery(getDefaultDatabase(), query, bindVars,
2504+
getAqlQueryOptions(aqlQueryOptions), classDocumentEntity, clazz);
25222505
}
25232506

25242507
/**
@@ -5187,11 +5170,9 @@ public CursorEntity<PlainEdgeEntity> graphGetEdges(String graphName) throws Aran
51875170

51885171
validateCollectionName(graphName);
51895172
String query = "for i in graph_edges(@graphName, null, { includeData: true }) return i";
5190-
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName).get();
5191-
5192-
CursorEntity<PlainEdgeEntity> result = this.executeQuery(query, bindVars, PlainEdgeEntity.class, true, 20);
5173+
Map<String, Object> bindVars = new MapBuilder().put(GRAPH_NAME, graphName).get();
51935174

5194-
return result;
5175+
return this.executeQuery(query, bindVars, PlainEdgeEntity.class, true, 20);
51955176
}
51965177

51975178
/**
@@ -5214,13 +5195,9 @@ public <T> EdgeCursor<T> executeEdgeQuery(
52145195
AqlQueryOptions aqlQueryOptions,
52155196
Class<T> clazz) throws ArangoException {
52165197

5217-
if (aqlQueryOptions == null) {
5218-
aqlQueryOptions = getDefaultAqlQueryOptions();
5219-
}
5220-
52215198
@SuppressWarnings("unchecked")
52225199
DocumentCursorResult<T, EdgeEntity<T>> baseCursor = cursorDriver.executeBaseCursorQuery(getDefaultDatabase(),
5223-
query, bindVars, aqlQueryOptions, EdgeEntity.class, clazz);
5200+
query, bindVars, getAqlQueryOptions(aqlQueryOptions), EdgeEntity.class, clazz);
52245201
return new EdgeCursor<T>(baseCursor);
52255202
}
52265203

@@ -5244,13 +5221,9 @@ public <T> VertexCursor<T> executeVertexQuery(
52445221
AqlQueryOptions aqlQueryOptions,
52455222
Class<T> clazz) throws ArangoException {
52465223

5247-
if (aqlQueryOptions == null) {
5248-
aqlQueryOptions = getDefaultAqlQueryOptions();
5249-
}
5250-
52515224
@SuppressWarnings("unchecked")
52525225
DocumentCursorResult<T, VertexEntity<T>> baseCursor = cursorDriver.executeBaseCursorQuery(getDefaultDatabase(),
5253-
query, bindVars, aqlQueryOptions, VertexEntity.class, clazz);
5226+
query, bindVars, getAqlQueryOptions(aqlQueryOptions), VertexEntity.class, clazz);
52545227
return new VertexCursor<T>(baseCursor);
52555228
}
52565229

@@ -5276,22 +5249,24 @@ public <T> EdgeCursor<T> graphGetEdgeCursor(
52765249
GraphEdgesOptions graphEdgesOptions,
52775250
AqlQueryOptions aqlQueryOptions) throws ArangoException {
52785251

5279-
if (graphEdgesOptions == null) {
5280-
graphEdgesOptions = new GraphEdgesOptions();
5252+
GraphEdgesOptions tmpGraphEdgesOptions = graphEdgesOptions;
5253+
if (tmpGraphEdgesOptions == null) {
5254+
tmpGraphEdgesOptions = new GraphEdgesOptions();
52815255
}
52825256

52835257
validateCollectionName(graphName);
52845258

52855259
String query = "for i in graph_edges(@graphName, @vertexExample, @options) return i";
5286-
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName)
5287-
.put("vertexExample", JsonUtils.convertNullToMap(vertexExample))
5288-
.put("options", JsonUtils.convertNullToMap(graphEdgesOptions)).get();
5260+
Map<String, Object> bindVars = new MapBuilder().put(GRAPH_NAME, graphName)
5261+
.put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample))
5262+
.put("options", JsonUtils.convertNullToMap(tmpGraphEdgesOptions)).get();
52895263

5290-
if (aqlQueryOptions == null) {
5291-
aqlQueryOptions = getDefaultAqlQueryOptions().setCount(true);
5264+
AqlQueryOptions tmpAqlQueryOptions = aqlQueryOptions;
5265+
if (tmpAqlQueryOptions == null) {
5266+
tmpAqlQueryOptions = getDefaultAqlQueryOptions().setCount(true);
52925267
}
52935268

5294-
return executeEdgeQuery(query, bindVars, aqlQueryOptions, clazz);
5269+
return executeEdgeQuery(query, bindVars, tmpAqlQueryOptions, clazz);
52955270
}
52965271

52975272
/**
@@ -5320,8 +5295,8 @@ public <T> VertexCursor<T> graphGetVertexCursor(
53205295

53215296
String query = "for i in graph_vertices(@graphName , @vertexExample, @options) return i";
53225297

5323-
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName)
5324-
.put("vertexExample", JsonUtils.convertNullToMap(vertexExample))
5298+
Map<String, Object> bindVars = new MapBuilder().put(GRAPH_NAME, graphName)
5299+
.put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample))
53255300
.put("options", JsonUtils.convertNullToMap(graphVerticesOptions)).get();
53265301

53275302
return executeVertexQuery(query, bindVars, aqlQueryOptions, clazz);
@@ -5358,7 +5333,7 @@ public <T> CursorEntity<T> graphGetEdges(String graphName, Class<T> clazz, Strin
53585333

53595334
validateCollectionName(graphName);
53605335
String query = "for i in graph_edges(@graphName, @vertexDocumentHandle, { includeData: true }) return i";
5361-
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName)
5336+
Map<String, Object> bindVars = new MapBuilder().put(GRAPH_NAME, graphName)
53625337
.put("vertexDocumentHandle", vertexDocumentHandle).get();
53635338

53645339
return this.executeQuery(query, bindVars, clazz, true, 20);
@@ -5398,12 +5373,10 @@ public <T> CursorEntity<T> graphGetEdgesByExampleObject(String graphName, Class<
53985373
validateCollectionName(graphName);
53995374
String query = "for i in graph_edges(@graphName, @vertexExample, { includeData: true }) return i";
54005375

5401-
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName).put("vertexExample", vertexExample)
5376+
Map<String, Object> bindVars = new MapBuilder().put(GRAPH_NAME, graphName).put(VERTEX_EXAMPLE, vertexExample)
54025377
.get();
54035378

5404-
CursorEntity<T> result = this.executeQuery(query, bindVars, clazz, true, 20);
5405-
5406-
return result;
5379+
return this.executeQuery(query, bindVars, clazz, true, 20);
54075380
}
54085381

54095382
/**
@@ -5428,12 +5401,10 @@ public <T> CursorEntity<T> graphGetEdgesByExampleMap(
54285401
validateCollectionName(graphName);
54295402
String query = "for i in graph_edges(@graphName, @vertexExample, { includeData: true }) return i";
54305403

5431-
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName).put("vertexExample", vertexExample)
5404+
Map<String, Object> bindVars = new MapBuilder().put(GRAPH_NAME, graphName).put(VERTEX_EXAMPLE, vertexExample)
54325405
.get();
54335406

5434-
CursorEntity<T> result = this.executeQuery(query, bindVars, clazz, true, 20, null);
5435-
5436-
return result;
5407+
return this.executeQuery(query, bindVars, clazz, true, 20, null);
54375408
}
54385409

54395410
public <V, E> ShortestPathEntity<V, E> graphGetShortestPath(
@@ -5444,51 +5415,14 @@ public <V, E> ShortestPathEntity<V, E> graphGetShortestPath(
54445415
Class<V> vertexClass,
54455416
Class<E> edgeClass) throws ArangoException {
54465417

5447-
if (shortestPathOptions == null) {
5448-
shortestPathOptions = new ShortestPathOptions();
5418+
ShortestPathOptions tmpShortestPathOptions = shortestPathOptions;
5419+
if (tmpShortestPathOptions == null) {
5420+
tmpShortestPathOptions = new ShortestPathOptions();
54495421
}
54505422

54515423
return cursorDriver.getShortestPath(getDefaultDatabase(), graphName, startVertexExample, endVertexExample,
5452-
shortestPathOptions, getDefaultAqlQueryOptions(), vertexClass, edgeClass);
5453-
}
5454-
5455-
// public <T, S> CursorEntity<EdgeEntity<T>> graphGetEdgesByExampleObject1(
5456-
// String graphName,
5457-
// Class<T> clazzT,
5458-
// S vertexExample) throws ArangoException {
5459-
// validateCollectionName(graphName);
5460-
// String query =
5461-
// "for i in graph_edges(@graphName, @vertexExample) return i";
5462-
//
5463-
// Map<String, Object> bindVars = new MapBuilder().put("graphName",
5464-
// graphName).put("vertexExample", vertexExample)
5465-
// .get();
5466-
//
5467-
// CursorEntity<EdgeEntity<T>> result = this.executeQuery(query, bindVars,
5468-
// EdgeEntity<T>.class, true, 20);
5469-
//
5470-
// return null;
5471-
// }
5472-
5473-
// public <T> CursorEntity<EdgeEntity<T>> graphGetEdgesWithData(
5474-
// String graphName,
5475-
// Class<T> clazz,
5476-
// String vertexDocumentHandle,
5477-
// int i) throws ArangoException {
5478-
//
5479-
// validateCollectionName(graphName);
5480-
// String query =
5481-
// "for i in graph_edges(@graphName, @vertexDocumentHandle) return i";
5482-
// Map<String, Object> bindVars = new MapBuilder().put("graphName",
5483-
// graphName)
5484-
// .put("vertexDocumentHandle", vertexDocumentHandle).get();
5485-
//
5486-
// CursorEntity<T> result = this.executeQuery(query, bindVars, clazz, true,
5487-
// 20);
5488-
//
5489-
// return (CursorEntity<EdgeEntity<T>>) result;
5490-
//
5491-
// }
5424+
tmpShortestPathOptions, getDefaultAqlQueryOptions(), vertexClass, edgeClass);
5425+
}
54925426

54935427
/**
54945428
* Creates an AQL Function
@@ -5830,11 +5764,14 @@ public CursorRawResult executeAqlQueryRaw(
58305764
Map<String, Object> bindVars,
58315765
AqlQueryOptions aqlQueryOptions) throws ArangoException {
58325766

5767+
return cursorDriver.executeAqlQueryRaw(getDefaultDatabase(), query, bindVars,
5768+
getAqlQueryOptions(aqlQueryOptions));
5769+
}
5770+
5771+
private AqlQueryOptions getAqlQueryOptions(AqlQueryOptions aqlQueryOptions) {
58335772
if (aqlQueryOptions == null) {
5834-
aqlQueryOptions = getDefaultAqlQueryOptions();
5773+
return getDefaultAqlQueryOptions();
58355774
}
5836-
5837-
return cursorDriver.executeAqlQueryRaw(getDefaultDatabase(), query, bindVars, aqlQueryOptions);
5775+
return aqlQueryOptions;
58385776
}
5839-
58405777
}

src/main/java/com/arangodb/ArangoException.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
*/
2525
public class ArangoException extends Exception {
2626

27-
protected BaseEntity entity;
27+
protected final BaseEntity entity;
2828

2929
public ArangoException() {
3030
super();
31+
this.entity = null;
3132
}
3233

3334
public ArangoException(BaseEntity entity) {
@@ -37,14 +38,17 @@ public ArangoException(BaseEntity entity) {
3738

3839
public ArangoException(String message, Throwable cause) {
3940
super(message, cause);
41+
this.entity = null;
4042
}
4143

4244
public ArangoException(String message) {
4345
super(message);
46+
this.entity = null;
4447
}
4548

4649
public ArangoException(Throwable cause) {
4750
super(cause);
51+
this.entity = null;
4852
}
4953

5054
public int getErrorNumber() {
@@ -64,19 +68,18 @@ public BaseEntity getEntity() {
6468
}
6569

6670
public boolean isUnauthorized() {
67-
return (entity != null && entity.isUnauthorized());
71+
return entity != null && entity.isUnauthorized();
6872
}
6973

70-
// public boolean isNotFound() {
71-
// return (entity != null && entity.isNotFound());
72-
// }
73-
7474
public void setCode(int code) {
75-
entity.setCode(code);
75+
if (entity != null) {
76+
entity.setCode(code);
77+
}
7678
}
7779

7880
public void setErrorNumber(int errorNumber) {
79-
entity.setErrorNumber(errorNumber);
81+
if (entity != null) {
82+
entity.setErrorNumber(errorNumber);
83+
}
8084
}
81-
8285
}

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,19 @@
3232
*/
3333
public class CollectionStatusTypeAdapter extends TypeAdapter<CollectionStatus> {
3434

35-
@Override
36-
public void write(JsonWriter out, CollectionStatus value) throws IOException {
37-
out.value(value.status());
38-
}
39-
40-
@Override
41-
public CollectionStatus read(JsonReader in) throws IOException {
42-
if (in.peek() == JsonToken.NULL) {
43-
in.nextNull();
44-
return null;
45-
}
46-
47-
CollectionStatus ret = CollectionStatus.valueOf(in.nextInt());
48-
return ret;
49-
}
35+
@Override
36+
public void write(JsonWriter out, CollectionStatus value) throws IOException {
37+
out.value(value.status());
38+
}
39+
40+
@Override
41+
public CollectionStatus read(JsonReader in) throws IOException {
42+
if (in.peek() == JsonToken.NULL) {
43+
in.nextNull();
44+
return null;
45+
}
46+
47+
return CollectionStatus.valueOf(in.nextInt());
48+
}
5049

5150
}

0 commit comments

Comments
 (0)