Last active
September 16, 2016 21:29
-
-
Save kombadzomba/fcd27a0a439aa7413f1f12b4e4e354d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public synchronized List<? extends CommonEntity> getData() { | |
Query orderedQuery = view.createQuery(); | |
orderedQuery.setStartKey(startKey); | |
orderedQuery.setEndKey(endKey); | |
orderedQuery.setDescending(descending); | |
// data is protected variable | |
if (data == null) { | |
data = new LinkedList(); | |
} | |
data.clear(); | |
try { | |
QueryEnumerator results = orderedQuery.run(); | |
if (view.getReduce() == null) { | |
// map only | |
for (Iterator<QueryRow> it = results; it.hasNext(); ) { | |
QueryRow row = it.next(); | |
addDocumentToData(row.getDocument()); | |
} | |
} else { | |
// map reduce | |
QueryEnumerator result = orderedQuery.run(); | |
QueryRow aggregate = result.next(); | |
if (getReduceResultClass() == List.class) { | |
if (aggregate != null && aggregate.getValue() != null) { | |
data.addAll((Collection) aggregate.getValue()); | |
} | |
} else if (getReduceResultClass() == Number.class) { | |
data.add(aggregate == null ? 0 : (Number) aggregate.getValue()); | |
} | |
} | |
} catch (CouchbaseLiteException e) { | |
Log.e(TAG, String.format("Error querying view %s.", getViewName()), e); | |
} | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment