Skip to content

Commit 9686da5

Browse files
author
mpv1989
committed
Fix serialization of bind parameter with null values (Issue #177)
1 parent 5acf438 commit 9686da5

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
v4.3.4 (2018-xx-xx)
22
---------------------------
3+
4+
* fixed serialization of bind parameter with null values (Issue #177)
35
* made ErrorEntity serializable (Issue #178)
46
* fixed VelocyStream multi-thread authentication bug
57

src/main/java/com/arangodb/internal/InternalArangoDatabase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.arangodb.model.TraversalOptions;
5151
import com.arangodb.model.UserAccessOptions;
5252
import com.arangodb.util.ArangoSerialization;
53+
import com.arangodb.util.ArangoSerializer;
5354
import com.arangodb.velocypack.Type;
5455
import com.arangodb.velocypack.VPackSlice;
5556
import com.arangodb.velocypack.exception.VPackException;
@@ -174,8 +175,9 @@ protected Request queryRequest(
174175
final String query,
175176
final Map<String, Object> bindVars,
176177
final AqlQueryOptions options) {
177-
return new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_CURSOR).setBody(
178-
util().serialize(OptionsBuilder.build(options != null ? options : new AqlQueryOptions(), query, bindVars)));
178+
return new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_CURSOR).setBody(util().serialize(
179+
OptionsBuilder.build(options != null ? options : new AqlQueryOptions(), query, bindVars != null
180+
? util().serialize(bindVars, new ArangoSerializer.Options().serializeNullValues(true)) : null)));
179181
}
180182

181183
protected Request queryNextRequest(final String id) {

src/main/java/com/arangodb/model/AqlQueryOptions.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
package com.arangodb.model;
2222

2323
import java.util.Collection;
24-
import java.util.Map;
24+
25+
import com.arangodb.velocypack.VPackSlice;
2526

2627
/**
2728
* @author Mark Vollmary
@@ -36,7 +37,7 @@ public class AqlQueryOptions {
3637
private Integer batchSize;
3738
private Boolean cache;
3839
private Long memoryLimit;
39-
private Map<String, Object> bindVars;
40+
private VPackSlice bindVars;
4041
private String query;
4142
private Options options;
4243

@@ -126,7 +127,7 @@ public AqlQueryOptions cache(final Boolean cache) {
126127
return this;
127128
}
128129

129-
protected Map<String, Object> getBindVars() {
130+
protected VPackSlice getBindVars() {
130131
return bindVars;
131132
}
132133

@@ -135,7 +136,7 @@ protected Map<String, Object> getBindVars() {
135136
* key/value pairs representing the bind parameters
136137
* @return options
137138
*/
138-
protected AqlQueryOptions bindVars(final Map<String, Object> bindVars) {
139+
protected AqlQueryOptions bindVars(final VPackSlice bindVars) {
139140
this.bindVars = bindVars;
140141
return this;
141142
}

src/main/java/com/arangodb/model/OptionsBuilder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.arangodb.entity.EdgeDefinition;
2727
import com.arangodb.entity.Permissions;
28+
import com.arangodb.velocypack.VPackSlice;
2829

2930
/**
3031
* @author Mark Vollmary
@@ -64,10 +65,7 @@ public static CollectionCreateOptions build(final CollectionCreateOptions option
6465
return options.name(name);
6566
}
6667

67-
public static AqlQueryOptions build(
68-
final AqlQueryOptions options,
69-
final String query,
70-
final Map<String, Object> bindVars) {
68+
public static AqlQueryOptions build(final AqlQueryOptions options, final String query, final VPackSlice bindVars) {
7169
return options.query(query).bindVars(bindVars);
7270
}
7371

src/test/java/com/arangodb/ArangoDatabaseTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,18 @@ public void queryNoResults() throws IOException {
791791
}
792792
}
793793

794+
@Test
795+
public void queryWithNullBindParam() throws IOException {
796+
try {
797+
db.createCollection(COLLECTION_NAME);
798+
final ArangoCursor<BaseDocument> cursor = db.query("FOR i IN @@col FILTER i.test == @test RETURN i",
799+
new MapBuilder().put("@col", COLLECTION_NAME).put("test", null).get(), null, BaseDocument.class);
800+
cursor.close();
801+
} finally {
802+
db.collection(COLLECTION_NAME).drop();
803+
}
804+
}
805+
794806
@Test
795807
public void explainQuery() {
796808
final AqlExecutionExplainEntity explain = arangoDB.db().explainQuery("for i in 1..1 return i", null, null);

0 commit comments

Comments
 (0)