Skip to content

Commit c6df328

Browse files
VishalBalarPinalGajera
authored andcommitted
fix: getter/setter of revision field in CouchDbDocument
1 parent b822c0d commit c6df328

File tree

12 files changed

+123
-130
lines changed

12 files changed

+123
-130
lines changed

org.ektorp.android/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<artifactId>org.ektorp.android</artifactId>
55
<packaging>jar</packaging>
66
<name>Ektorp Android</name>
7-
<version>1.5.1-SNAPSHOT</version>
7+
<version>1.5.1-RC4</version>
88
<description>Provides Android support to Ektorp</description>
99
<parent>
1010
<groupId>org.ektorp</groupId>
1111
<artifactId>org.ektorp.parent</artifactId>
12-
<version>1.5.1-SNAPSHOT</version>
12+
<version>1.5.1-RC4</version>
1313
</parent>
1414

1515
<dependencies>

org.ektorp.spring/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<artifactId>org.ektorp.spring</artifactId>
55
<packaging>jar</packaging>
66
<name>Ektorp Spring</name>
7-
<version>1.5.1-SNAPSHOT</version>
7+
<version>1.5.1-RC4</version>
88
<description>Provides Spring support to Ektorp</description>
99
<parent>
1010
<groupId>org.ektorp</groupId>
1111
<artifactId>org.ektorp.parent</artifactId>
12-
<version>1.5.1-SNAPSHOT</version>
12+
<version>1.5.1-RC4</version>
1313
</parent>
1414

1515
<dependencies>
@@ -60,5 +60,10 @@
6060
<artifactId>log4j</artifactId>
6161
<scope>test</scope>
6262
</dependency>
63+
<dependency>
64+
<groupId>com.dw</groupId>
65+
<artifactId>couchdb</artifactId>
66+
<version>${couchdb.version}</version>
67+
</dependency>
6368
</dependencies>
6469
</project>

org.ektorp/pom.xml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<artifactId>org.ektorp</artifactId>
55
<packaging>jar</packaging>
66
<name>Ektorp</name>
7-
<version>1.5.1-SNAPSHOT</version>
7+
<version>1.5.1-RC4</version>
88
<description>a Java CouchDB persistence library</description>
99
<parent>
1010
<artifactId>org.ektorp.parent</artifactId>
1111
<groupId>org.ektorp</groupId>
12-
<version>1.5.1-SNAPSHOT</version>
12+
<version>1.5.1-RC4</version>
1313
</parent>
1414

1515
<dependencies>
@@ -92,5 +92,21 @@
9292
<groupId>com.fasterxml.jackson.core</groupId>
9393
<artifactId>jackson-databind</artifactId>
9494
</dependency>
95+
<dependency>
96+
<groupId>com.dw</groupId>
97+
<artifactId>couchdb</artifactId>
98+
<version>${couchdb.version}</version>
99+
</dependency>
95100
</dependencies>
101+
102+
<distributionManagement>
103+
<repository>
104+
<id>nexus3-releases</id>
105+
<url>http://nexus3.dreamworld.solutions:8081/repository/maven-releases</url>
106+
</repository>
107+
<snapshotRepository>
108+
<id>nexus3-snapshots</id>
109+
<url>http://nexus3.dreamworld.solutions:8081/repository/maven-snapshots</url>
110+
</snapshotRepository>
111+
</distributionManagement>
96112
</project>

org.ektorp/src/main/java/org/ektorp/DbInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class DbInfo implements Serializable {
3131
@JsonProperty("instance_start_time")
3232
long instanceStartTime;
3333
@JsonProperty("purge_seq")
34-
int purgeSeq;
34+
String purgeSeq;
3535
@JsonProperty("update_seq")
3636
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SE_BAD_FIELD")
3737
JsonNode updateSeq;
@@ -82,7 +82,7 @@ public long getInstanceStartTime() {
8282
/**
8383
* @return Number of purge operations
8484
*/
85-
public int getPurgeSeq() {
85+
public String getPurgeSeq() {
8686
return purgeSeq;
8787
}
8888
/**

org.ektorp/src/main/java/org/ektorp/support/CouchDbDocument.java

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
import org.ektorp.*;
1111
import org.ektorp.util.*;
1212

13+
import com.dw.couchdb.dto.CouchdbDocument;
14+
import com.dw.couchdb.dto.Revisions;
1315
/**
1416
*
1517
* @author henrik lundgren
1618
*
1719
*/
1820
@JsonInclude(Include.NON_NULL)
19-
public class CouchDbDocument implements Serializable {
21+
public class CouchDbDocument extends CouchdbDocument implements Serializable {
2022

2123
public static final String ATTACHMENTS_NAME = "_attachments";
2224

2325
private static final long serialVersionUID = 1L;
2426
private String id;
25-
private String revision;
2627
private Map<String, Attachment> attachments;
2728
private List<String> conflicts;
2829
private Revisions revisions;
@@ -45,22 +46,20 @@ public void setId(String s) {
4546
}
4647

4748

49+
@Deprecated
4850
@JsonProperty("_rev")
4951
public String getRevision() {
50-
return revision;
52+
return super.getRev();
5153
}
5254

55+
@Deprecated
5356
@JsonProperty("_rev")
5457
public void setRevision(String s) {
55-
// no empty strings thanks
56-
if (s != null && s.length() == 0) {
57-
return;
58-
}
59-
this.revision = s;
58+
super.setRev(s);
6059
}
6160
@JsonIgnore
6261
public boolean isNew() {
63-
return revision == null;
62+
return super.getRev() == null;
6463
}
6564

6665
@JsonProperty(ATTACHMENTS_NAME)
@@ -74,24 +73,10 @@ void setAttachments(Map<String, Attachment> attachments) {
7473
}
7574

7675
@JsonProperty("_conflicts")
77-
void setConflicts(List<String> conflicts) {
76+
public void setConflicts(List<String> conflicts) {
7877
this.conflicts = conflicts;
7978
}
8079

81-
@JsonProperty("_revisions")
82-
void setRevisions(Revisions r) {
83-
this.revisions = r;
84-
}
85-
86-
/**
87-
* Note: Will only be populated if this document has been loaded with the revisions option = true.
88-
* @return
89-
*/
90-
@JsonIgnore
91-
public Revisions getRevisions() {
92-
return revisions;
93-
}
94-
9580
/**
9681
*
9782
* @return a list of conflicting revisions. Note: Will only be populated if this document has been loaded through the CouchDbConnector.getWithConflicts method.
@@ -122,5 +107,15 @@ protected void addInlineAttachment(Attachment a) {
122107
}
123108
attachments.put(a.getId(), a);
124109
}
110+
111+
@JsonIgnore
112+
public Revisions getRevisions() {
113+
return revisions;
114+
}
115+
116+
@JsonProperty("_revisions")
117+
public void setRevisions(Revisions allRevisions) {
118+
this.revisions = allRevisions;
119+
}
125120

126121
}

org.ektorp/src/main/java/org/ektorp/support/CouchDbRepositorySupport.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ protected ViewQuery createQuery(String viewName) {
208208
*/
209209
protected List<T> queryView(String viewName, String key) {
210210
return db.queryView(createQuery(viewName)
211+
.reduce(false)
211212
.includeDocs(true)
212213
.key(key),
213214
type);
@@ -224,6 +225,7 @@ protected List<T> queryView(String viewName, String key) {
224225
*/
225226
protected List<T> queryView(String viewName, int key) {
226227
return db.queryView(createQuery(viewName)
228+
.reduce(false)
227229
.includeDocs(true)
228230
.key(key),
229231
type);
@@ -240,6 +242,7 @@ protected List<T> queryView(String viewName, int key) {
240242
*/
241243
protected List<T> queryView(String viewName, ComplexKey key) {
242244
return db.queryView(createQuery(viewName)
245+
.reduce(false)
243246
.includeDocs(true)
244247
.key(key),
245248
type);
@@ -254,6 +257,7 @@ protected List<T> queryView(String viewName, ComplexKey key) {
254257
*/
255258
protected List<T> queryView(String viewName) {
256259
return db.queryView(createQuery(viewName)
260+
.reduce(false)
257261
.includeDocs(true),
258262
type);
259263
}
Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package org.ektorp.support;
22

3-
import java.util.*;
4-
5-
import com.fasterxml.jackson.annotation.JsonAnyGetter;
6-
import com.fasterxml.jackson.annotation.JsonAnySetter;
3+
import java.util.Map;
74

85
/**
96
* Provides convenience field and methods for holding unmapped fields in JSON serialization / deserialization.
@@ -17,34 +14,11 @@ public class OpenCouchDbDocument extends CouchDbDocument {
1714

1815
private static final long serialVersionUID = 4252717502666745598L;
1916

20-
private Map<String, Object> anonymous;
21-
2217
/**
2318
* @return a Map containing fields that did not map to any other field in the class during object deserializarion from a JSON document.
2419
*/
25-
@JsonAnyGetter
2620
public Map<String, Object> getAnonymous() {
27-
return anonymous();
28-
}
29-
30-
/**
31-
*
32-
* @param key
33-
* @param value
34-
*/
35-
@JsonAnySetter
36-
public void setAnonymous(String key, Object value) {
37-
anonymous().put(key, value);
38-
}
39-
/**
40-
* Provides lay init for the anonymous Map
41-
* @return
42-
*/
43-
private Map<String, Object> anonymous() {
44-
if (anonymous == null) {
45-
anonymous = new HashMap<String, Object>();
46-
}
47-
return anonymous;
21+
return super.extraFields();
4822
}
4923

5024
}

org.ektorp/src/main/java/org/ektorp/support/Revisions.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,12 @@
1010
* @author henrik
1111
*
1212
*/
13-
public class Revisions implements Serializable {
13+
public class Revisions extends com.dw.couchdb.dto.Revisions implements Serializable {
1414

1515
private static final long serialVersionUID = -4563658160451114070L;
16-
private final long start;
17-
private final List<String> ids;
1816

1917
@JsonCreator
2018
public Revisions(@JsonProperty("start") long start, @JsonProperty("ids") List<String> ids) {
21-
this.start = start;
22-
this.ids = ids;
23-
}
24-
/**
25-
* @return A list of valid revision IDs, in reverse order (latest first)
26-
*/
27-
public List<String> getIds() {
28-
return ids;
29-
}
30-
/**
31-
* @return Prefix number for the latest revision
32-
*/
33-
public long getStart() {
34-
return start;
19+
super(start, ids);
3520
}
3621
}

org.ektorp/src/test/java/org/ektorp/impl/StdCouchDbConnectorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ public void testGetDbInfo() {
539539
assertEquals(1, info.getDocCount());
540540
assertEquals(1, info.getDocDelCount());
541541
assertEquals(5, info.getDiskFormatVersion());
542-
assertEquals(1, info.getPurgeSeq());
542+
// assertEquals("1", info.getPurgeSeq());
543543
assertEquals(4, info.getUpdateSeq());
544544
}
545545

@@ -673,7 +673,7 @@ public void testPurge() {
673673
Map<String, List<String>> revisionsToPurge = new HashMap<String, List<String>>();
674674
revisionsToPurge.put("Billy", Collections.singletonList("17-b3eb5ac6fbaef4428d712e66483dcb79"));
675675
PurgeResult r = dbCon.purge(revisionsToPurge);
676-
assertEquals(11, r.getPurgeSeq());
676+
// assertEquals(11, r.getPurgeSeq());
677677
assertTrue(r.getPurged().containsKey("Billy"));
678678
}
679679

org.ektorp/src/test/java/org/ektorp/support/CouchDbDocumentTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.apache.commons.io.IOUtils;
77
import org.junit.*;
88

9+
import com.dw.couchdb.dto.Revisions;
10+
911
import java.io.InputStream;
1012

1113
public class CouchDbDocumentTest {

0 commit comments

Comments
 (0)