Skip to content
Browse files

Merge pull request #240 from willholley/DbInfo-array-updateseq

Support array-based sequence numbers (e.g. BigCouch) in DbInfo
  • Loading branch information...
2 parents ca696c9 + 89987b0 commit 78743dd6a1ac7b50a80f86e267100b9a861d2232 @helun committed Nov 6, 2015
View
11 org.ektorp/src/main/java/org/ektorp/DbInfo.java
@@ -5,6 +5,8 @@
import com.fasterxml.jackson.annotation.*;
import org.ektorp.util.*;
+import com.fasterxml.jackson.databind.JsonNode;
+
/**
*
* @author henrik lundgren
@@ -31,7 +33,8 @@
@JsonProperty("purge_seq")
int purgeSeq;
@JsonProperty("update_seq")
- String updateSeq;
+ @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SE_BAD_FIELD")
+ JsonNode updateSeq;
/**
* Used to future proof this class, if new fields are added by CouchDb they will be found here.
*/
@@ -86,20 +89,20 @@ public int getPurgeSeq() {
* @return Current number of updates to the database
*/
public long getUpdateSeq() {
- return Long.parseLong(updateSeq);
+ return updateSeq.asLong();
}
/**
* Cloudant uses generated strings for update sequence.
* @return
*/
public String getUpdateSeqAsString() {
- return updateSeq;
+ return updateSeq.asText();
}
/**
* @return false if db is an Cloudant instance.
*/
public boolean isUpdateSeqNumeric() {
- return updateSeq != null && updateSeq.matches("^\\d*$");
+ return updateSeq != null && (updateSeq.isInt() || updateSeq.isLong());
}
@JsonCreator
View
20 org.ektorp/src/test/java/org/ektorp/DbInfoTest.java
@@ -2,21 +2,33 @@
import static org.junit.Assert.*;
+import com.fasterxml.jackson.databind.*;
+
import org.junit.Test;
public class DbInfoTest {
@Test
- public void given_updateSeq_is_numeric_then_isUpdateSeqNumeric_should_return_true() {
+ public void given_updateSeq_is_numeric_then_isUpdateSeqNumeric_should_return_true() throws Exception {
DbInfo info = new DbInfo("test");
- info.updateSeq = "1234";
+ String json = "{\"update_seq\":123456789123}";
+ info.updateSeq = new ObjectMapper().readTree(json).get("update_seq");
assertTrue(info.isUpdateSeqNumeric());
}
@Test
- public void given_updateSeq_is_not_numeric_then_isUpdateSeqNumeric_should_return_false() {
+ public void given_updateSeq_is_not_numeric_then_isUpdateSeqNumeric_should_return_false() throws Exception {
+ DbInfo info = new DbInfo("test");
+ String json = "{\"update_seq\":\"dqwEFWEGRGQ34Q\"}";
+ info.updateSeq = new ObjectMapper().readTree(json).get("update_seq");
+ assertFalse(info.isUpdateSeqNumeric());
+ }
+
+ @Test
+ public void given_updateSeq_is_array_then_isUpdateSeqNumeric_should_return_false() throws Exception {
DbInfo info = new DbInfo("test");
- info.updateSeq = "dqwEFWEGRGQ34Q";
+ String json = "{\"update_seq\":[123,\"dqwEFWEGRGQ34Q\"]}";
+ info.updateSeq = new ObjectMapper().readTree(json).get("update_seq");
assertFalse(info.isUpdateSeqNumeric());
}

0 comments on commit 78743dd

Please sign in to comment.
Something went wrong with that request. Please try again.