Skip to content

Commit f63d9b7

Browse files
author
Mark
committed
Merge remote-tracking branch 'origin/4.1'
2 parents 012bbed + 1603365 commit f63d9b7

File tree

10 files changed

+236
-3
lines changed

10 files changed

+236
-3
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
v4.1.1 (2016-11-09)
2+
---------------------------
3+
* changed json parsing of VelocyPack types not known in json
4+
* fixed VelocyPack bug with non-ASCII characters
5+
* added missing replicationFactor in CollectionCreateOptions
6+
* added missing replicationFactor in CollectionPropertiesEntity
7+
* added option serializeNull in DocumentUpdateOptions
8+
19
v4.1.0 (2016-10-28)
210
---------------------------
311
* changed VelocyStream communication (send protocol header)

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.arangodb</groupId>
66
<artifactId>arangodb-java-driver</artifactId>
7-
<version>4.1.1-SNAPSHOT</version>
7+
<version>4.1.2-SNAPSHOT</version>
88
<inceptionYear>2016</inceptionYear>
99
<packaging>jar</packaging>
1010

@@ -158,6 +158,7 @@
158158
<artifactId>maven-surefire-plugin</artifactId>
159159
<version>2.19.1</version>
160160
<configuration>
161+
<argLine>-Dfile.encoding=UTF-8</argLine>
161162
<includes>
162163
<include>**/*Test.java</include>
163164
<include>**/*Example.java</include>

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class CollectionPropertiesEntity extends CollectionEntity {
3737
private Long count;
3838
private Integer numberOfShards;
3939
private Collection<String> shardKeys;
40+
private Integer replicationFactor;
4041

4142
public CollectionPropertiesEntity() {
4243
super();
@@ -105,4 +106,12 @@ public void setShardKeys(final Collection<String> shardKeys) {
105106
this.shardKeys = shardKeys;
106107
}
107108

109+
public Integer getReplicationFactor() {
110+
return replicationFactor;
111+
}
112+
113+
public void setReplicationFactor(final Integer replicationFactor) {
114+
this.replicationFactor = replicationFactor;
115+
}
116+
108117
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public <T> Request updateDocumentRequest(final String key, final T value, final
271271
request.putQueryParam(ArangoDBConstants.RETURN_NEW, params.getReturnNew());
272272
request.putQueryParam(ArangoDBConstants.RETURN_OLD, params.getReturnOld());
273273
request.putHeaderParam(ArangoDBConstants.IF_MATCH, params.getIfMatch());
274-
request.setBody(executor.serialize(value, true));
274+
request.setBody(executor.serialize(value, params.getSerializeNull() == null || params.getSerializeNull()));
275275
return request;
276276
}
277277

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class CollectionCreateOptions {
3434

3535
private String name;
3636
private Long journalSize;
37+
private Integer replicationFactor;
3738
private KeyOptions keyOptions;
3839
private Boolean waitForSync;
3940
private Boolean doCompact;
@@ -76,6 +77,26 @@ public CollectionCreateOptions journalSize(final Long journalSize) {
7677
return this;
7778
}
7879

80+
public Integer getReplicationFactor() {
81+
return replicationFactor;
82+
}
83+
84+
/**
85+
* @param replicationFactor
86+
* (The default is 1): in a cluster, this attribute determines how many copies of each shard are kept on
87+
* different DBServers. The value 1 means that only one copy (no synchronous replication) is kept. A
88+
* value of k means that k-1 replicas are kept. Any two copies reside on different DBServers. Replication
89+
* between them is synchronous, that is, every write operation to the "leader" copy will be replicated to
90+
* all "follower" replicas, before the write operation is reported successful. If a server fails, this is
91+
* detected automatically and one of the servers holding copies take over, usually without an error being
92+
* reported.
93+
* @return options
94+
*/
95+
public CollectionCreateOptions replicationFactor(final Integer replicationFactor) {
96+
this.replicationFactor = replicationFactor;
97+
return this;
98+
}
99+
79100
public KeyOptions getKeyOptions() {
80101
return keyOptions;
81102
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class DocumentUpdateOptions {
3535
private String ifMatch;
3636
private Boolean returnNew;
3737
private Boolean returnOld;
38+
private Boolean serializeNull;
3839

3940
public DocumentUpdateOptions() {
4041
super();
@@ -146,4 +147,20 @@ public DocumentUpdateOptions returnOld(final Boolean returnOld) {
146147
return this;
147148
}
148149

150+
public Boolean getSerializeNull() {
151+
return serializeNull;
152+
}
153+
154+
/**
155+
* @param serializeNull
156+
* By default, or if this is set to true, all fields of the document which have null values are
157+
* serialized to VelocyPack otherwise they are excluded from serialization. Use this to update single
158+
* fields from a stored document.
159+
* @return options
160+
*/
161+
public DocumentUpdateOptions serializeNull(final Boolean serializeNull) {
162+
this.serializeNull = serializeNull;
163+
return this;
164+
}
165+
149166
}

src/main/java/com/arangodb/velocypack/VPackBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ private void appendSQLTimestamp(final Timestamp value) {
611611
}
612612

613613
private void appendString(final String value) throws VPackBuilderException {
614-
final int length = value.length();
614+
final int length = value.getBytes().length;
615615
if (length <= 126) {
616616
// short string
617617
add((byte) (0x40 + length));

src/test/java/com/arangodb/ArangoCollectionTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import static org.hamcrest.Matchers.anyOf;
2424
import static org.hamcrest.Matchers.hasItem;
25+
import static org.hamcrest.Matchers.hasItems;
2526
import static org.hamcrest.Matchers.instanceOf;
2627
import static org.hamcrest.Matchers.is;
2728
import static org.hamcrest.Matchers.not;
@@ -364,6 +365,52 @@ public void updateDocumentKeepNullFalse() {
364365
assertThat(readResult.getProperties().keySet(), not(hasItem("a")));
365366
}
366367

368+
private static class TestUpdateEntity {
369+
@SuppressWarnings("unused")
370+
private String a, b;
371+
}
372+
373+
@Test
374+
public void updateDocumentSerializeNullTrue() {
375+
final TestUpdateEntity doc = new TestUpdateEntity();
376+
doc.a = "foo";
377+
doc.b = "foo";
378+
final DocumentCreateEntity<TestUpdateEntity> createResult = db.collection(COLLECTION_NAME).insertDocument(doc);
379+
final TestUpdateEntity patchDoc = new TestUpdateEntity();
380+
patchDoc.a = "bar";
381+
final DocumentUpdateEntity<TestUpdateEntity> updateResult = db.collection(COLLECTION_NAME)
382+
.updateDocument(createResult.getKey(), patchDoc);
383+
assertThat(updateResult, is(notNullValue()));
384+
assertThat(updateResult.getKey(), is(createResult.getKey()));
385+
386+
final BaseDocument readResult = db.collection(COLLECTION_NAME).getDocument(createResult.getKey(),
387+
BaseDocument.class);
388+
assertThat(readResult.getKey(), is(createResult.getKey()));
389+
assertThat(readResult.getProperties().keySet(), hasItem("a"));
390+
assertThat(readResult.getAttribute("a").toString(), is("bar"));
391+
}
392+
393+
@Test
394+
public void updateDocumentSerializeNullFalse() {
395+
final TestUpdateEntity doc = new TestUpdateEntity();
396+
doc.a = "foo";
397+
doc.b = "foo";
398+
final DocumentCreateEntity<TestUpdateEntity> createResult = db.collection(COLLECTION_NAME).insertDocument(doc);
399+
final TestUpdateEntity patchDoc = new TestUpdateEntity();
400+
patchDoc.a = "bar";
401+
final DocumentUpdateEntity<TestUpdateEntity> updateResult = db.collection(COLLECTION_NAME)
402+
.updateDocument(createResult.getKey(), patchDoc, new DocumentUpdateOptions().serializeNull(false));
403+
assertThat(updateResult, is(notNullValue()));
404+
assertThat(updateResult.getKey(), is(createResult.getKey()));
405+
406+
final BaseDocument readResult = db.collection(COLLECTION_NAME).getDocument(createResult.getKey(),
407+
BaseDocument.class);
408+
assertThat(readResult.getKey(), is(createResult.getKey()));
409+
assertThat(readResult.getProperties().keySet(), hasItems("a", "b"));
410+
assertThat(readResult.getAttribute("a").toString(), is("bar"));
411+
assertThat(readResult.getAttribute("b").toString(), is("foo"));
412+
}
413+
367414
@SuppressWarnings("unchecked")
368415
@Test
369416
public void updateDocumentMergeObjectsTrue() {
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb;
22+
23+
import static org.hamcrest.Matchers.is;
24+
import static org.hamcrest.Matchers.notNullValue;
25+
import static org.junit.Assert.assertThat;
26+
27+
import java.util.Map;
28+
29+
import org.junit.Before;
30+
import org.junit.Test;
31+
32+
import com.arangodb.entity.BaseDocument;
33+
import com.arangodb.entity.DocumentCreateEntity;
34+
35+
/**
36+
* @author Mark - mark at arangodb.com
37+
*
38+
*/
39+
public class DocumentTest extends BaseTest {
40+
41+
private static final String COLLECTION_NAME = "collection_test";
42+
private ArangoCollection collection;
43+
44+
@Before
45+
public void setup() {
46+
collection = db.collection(COLLECTION_NAME);
47+
try {
48+
collection.drop();
49+
} catch (final ArangoDBException e) {
50+
}
51+
db.createCollection(COLLECTION_NAME);
52+
}
53+
54+
@SuppressWarnings("unchecked")
55+
@Test
56+
public void insertAsJson() {
57+
//@formatter:off
58+
final String json =
59+
"{"
60+
+ "\"article\": {"
61+
+ "\"artist\": \"PREGARDIEN/RHEINISCHE KANTOREI/DAS\","
62+
+ "\"releaseDate\": \"1970-01-01\","
63+
+ "\"composer\": \"BACH\","
64+
+ "\"format\": \"CD\","
65+
+ "\"vat\": \"H\","
66+
+ "\"carriers\": 1,"
67+
+ "\"label\": \"CAPRICCIO\","
68+
+ "\"title\": \"BACH ST MATTHEW PASSION BWV244\","
69+
+ "\"barcode\": ["
70+
+ "\"4006408600466\""
71+
+ "],"
72+
+ "\"conductor\": \"MAX, H.\""
73+
+ "},"
74+
+ "\"stock\": {"
75+
+ "\"status\": \"RMV\","
76+
+ "\"lastUpdate\": \"2016-11-01 00:00\""
77+
+ "}"
78+
+ "}";
79+
//@formatter:on
80+
final DocumentCreateEntity<String> createResult = collection.insertDocument(json);
81+
final BaseDocument doc = collection.getDocument(createResult.getKey(), BaseDocument.class);
82+
assertThat(doc, is(notNullValue()));
83+
final Object article = doc.getAttribute("article");
84+
assertThat(article, is(notNullValue()));
85+
final Object artist = ((Map<String, Object>) article).get("artist");
86+
assertThat(artist, is(notNullValue()));
87+
assertThat(artist.toString(), is("PREGARDIEN/RHEINISCHE KANTOREI/DAS"));
88+
}
89+
90+
@SuppressWarnings("unchecked")
91+
@Test
92+
public void insertAsBaseDocument() {
93+
final BaseDocument document = new BaseDocument();
94+
{
95+
final BaseDocument article = new BaseDocument();
96+
document.addAttribute("article", article);
97+
article.addAttribute("artist", "PREGARDIEN/RHEINISCHE KANTOREI/DAS");
98+
article.addAttribute("releaseDate", "1970-01-01");
99+
article.addAttribute("composer", "BACH");
100+
article.addAttribute("format", "CD");
101+
article.addAttribute("vat", "H");
102+
article.addAttribute("carriers", 1);
103+
article.addAttribute("label", "CAPRICCIO");
104+
article.addAttribute("title", "BACH ST MATTHEW PASSION BWV244");
105+
article.addAttribute("barcode", new String[] { "4006408600466" });
106+
article.addAttribute("conductor", "MAX, H.");
107+
final BaseDocument stock = new BaseDocument();
108+
document.addAttribute("stock", stock);
109+
stock.addAttribute("status", "RMV");
110+
stock.addAttribute("lastUpdate", "2016-11-01 00:00");
111+
}
112+
final DocumentCreateEntity<BaseDocument> createResult = collection.insertDocument(document);
113+
final BaseDocument doc = collection.getDocument(createResult.getKey(), BaseDocument.class);
114+
assertThat(doc, is(notNullValue()));
115+
final Object article = doc.getAttribute("article");
116+
assertThat(article, is(notNullValue()));
117+
final Object artist = ((Map<String, Object>) article).get("artist");
118+
assertThat(artist, is(notNullValue()));
119+
assertThat(artist.toString(), is("PREGARDIEN/RHEINISCHE KANTOREI/DAS"));
120+
}
121+
122+
}

src/test/java/com/arangodb/velocypack/VPackBuilderTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,4 +887,12 @@ public void addVPackObjectInArray() throws VPackException {
887887
}
888888
}
889889

890+
@Test
891+
public void nonASCII() {
892+
final String s = "·ÃÂ";
893+
final VPackSlice vpack = new VPackBuilder().add(s).slice();
894+
assertThat(vpack.isString(), is(true));
895+
assertThat(vpack.getAsString(), is(s));
896+
}
897+
890898
}

0 commit comments

Comments
 (0)