Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit a9d6b53

Browse files
Hideki Itakurapasin
authored andcommitted
Fixed Java Core 1629 - Wrong return code for listener causes problems with puller and deleted items (#98)
This PR is for adapt latest implementation of getDocument() from other platform.
1 parent ffe26dd commit a9d6b53

3 files changed

Lines changed: 24 additions & 21 deletions

File tree

src/main/java/com/couchbase/lite/store/ForestBridge.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ public static RevisionInternal revisionObject(
4242
String docID,
4343
String revID,
4444
boolean withBody) {
45+
46+
boolean deleted = doc.selectedRevDeleted();
4547
if (revID == null)
4648
revID = doc.getSelectedRevID();
47-
RevisionInternal rev = new RevisionInternal(docID, revID, doc.selectedRevDeleted());
49+
RevisionInternal rev = new RevisionInternal(docID, revID, deleted);
4850
rev.setSequence(doc.getSelectedSequence());
4951
if (withBody) {
5052
Status status = loadBodyOfRevisionObject(rev, doc);
51-
if (status.isError())
53+
if (status.isError() && status.getCode() != Status.GONE)
5254
return null;
5355
}
5456
return rev;
@@ -61,14 +63,12 @@ public static RevisionInternal revisionObject(
6163
*/
6264
public static Status loadBodyOfRevisionObject(RevisionInternal rev, Document doc) {
6365
try {
64-
if (!doc.selectRevID(rev.getRevID(), true))
65-
return new Status(Status.NOT_FOUND);
66-
byte[] json = doc.getSelectedBody();
67-
if (json != null)
68-
rev.setJSON(json);
6966
rev.setSequence(doc.getSelectedSequence());
67+
doc.selectRevID(rev.getRevID(), true);
68+
rev.setJSON(doc.getSelectedBody());
7069
return new Status(Status.OK);
7170
} catch (ForestException ex) {
71+
rev.setMissing(true);
7272
return err2status(ex);
7373
}
7474
}

src/main/java/com/couchbase/lite/store/ForestDBStore.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public boolean databaseExists(String directory) {
147147
public void open() throws CouchbaseLiteException {
148148
// Flag:
149149
int flags = readOnly ? Database.ReadOnly : Database.Create;
150-
if(autoCompact)
150+
if (autoCompact)
151151
flags |= Database.AutoCompact;
152152

153153
// Encryption:
@@ -292,7 +292,7 @@ public void compact() throws CouchbaseLiteException {
292292

293293
/**
294294
* @note Throw RuntimeException if TransactionalTask throw Exception.
295-
* Otherwise return true or false
295+
* Otherwise return true or false
296296
*/
297297
@Override
298298
public boolean runInTransaction(TransactionalTask task) {
@@ -317,17 +317,20 @@ public boolean runInTransaction(TransactionalTask task) {
317317
}
318318

319319
@Override
320-
public RevisionInternal getDocument(String docID, String revID, boolean withBody) {
320+
public RevisionInternal getDocument(String docID, String inRevID, boolean withBody, Status outStatus) {
321321
Document doc = getDocument(docID);
322322
if (doc == null)
323323
return null;
324324
try {
325-
Status status = selectRev(doc, revID, withBody);
326-
if (status.isError())
325+
Status res = selectRev(doc, inRevID, withBody);
326+
outStatus.setCode(res.getCode());
327+
if (outStatus.isError() && outStatus.getCode() != Status.GONE)
327328
return null;
328-
if (revID == null && doc.selectedRevDeleted())
329+
if (inRevID == null && doc.selectedRevDeleted()) {
330+
outStatus.setCode(Status.DELETED);
329331
return null;
330-
return ForestBridge.revisionObject(doc, docID, revID, withBody);
332+
}
333+
return ForestBridge.revisionObject(doc, docID, inRevID, withBody);
331334
} finally {
332335
doc.free();
333336
}

src/main/java/com/couchbase/lite/store/ForestDBViewStore.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.couchbase.lite.Reducer;
3434
import com.couchbase.lite.Status;
3535
import com.couchbase.lite.internal.RevisionInternal;
36-
import com.couchbase.lite.support.FileDirUtils;
3736
import com.couchbase.lite.support.action.Action;
3837
import com.couchbase.lite.support.action.ActionBlock;
3938
import com.couchbase.lite.support.action.ActionException;
@@ -50,7 +49,6 @@
5049
import java.util.List;
5150
import java.util.Locale;
5251
import java.util.Map;
53-
import java.util.Objects;
5452
import java.util.regex.Matcher;
5553
import java.util.regex.Pattern;
5654

@@ -406,17 +404,19 @@ public List<QueryRow> regularQuery(QueryOptions options) throws CouchbaseLiteExc
406404
String linkedID = null;
407405
if (value instanceof Map)
408406
linkedID = (String) ((Map) value).get("_id");
407+
Status status = new Status();
409408
if (linkedID != null) {
410409
// http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views
411410
// #Linked_documents
412411
String linkedRev = (String) ((Map) value).get("_rev");
413-
docRevision = _dbStore.getDocument(linkedID, linkedRev, true);
412+
docRevision = _dbStore.getDocument(linkedID, linkedRev, true, status);
414413
if (docRevision != null)
415414
sequence = docRevision.getSequence();
416415
else
417-
Log.w(TAG, "Couldn't load linked doc %s rev %s", linkedID, linkedRev);
416+
Log.w(TAG, "Couldn't load linked doc %s rev %s: status %d",
417+
linkedID, linkedRev, status.getCode());
418418
} else {
419-
docRevision = _dbStore.getDocument(docID, null, true);
419+
docRevision = _dbStore.getDocument(docID, null, true, status);
420420
}
421421
}
422422
Log.v(TAG, "Query %s: Found row with key=%s, value=%s, id=%s",
@@ -583,7 +583,7 @@ private View openIndex(int flags) throws ForestException {
583583
private View openIndex(int flags, boolean dryRun) throws ForestException {
584584
if (_view == null) {
585585
// Flags:
586-
if(_dbStore.getAutoCompact())
586+
if (_dbStore.getAutoCompact())
587587
flags |= Database.AutoCompact;
588588

589589
// Encryption:
@@ -746,7 +746,7 @@ private static String oldViewNameToFileName(String viewName) throws CouchbaseLit
746746

747747
protected static String fileNameToViewName(String fileName) throws CouchbaseLiteException {
748748
Matcher m = kViewNameRegex.matcher(fileName);
749-
if(!m.matches())
749+
if (!m.matches())
750750
throw new CouchbaseLiteException(Status.BAD_PARAM);
751751
String viewName = fileName.substring(0, fileName.indexOf("."));
752752
return unescapeViewName(viewName);

0 commit comments

Comments
 (0)