本文整理汇总了Java中com.couchbase.lite.QueryEnumerator类的典型用法代码示例。如果您正苦于以下问题:Java QueryEnumerator类的具体用法?Java QueryEnumerator怎么用?Java QueryEnumerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryEnumerator类属于com.couchbase.lite包,在下文中一共展示了QueryEnumerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: searchAllPostsOrderByDate
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
@Override
protected List<Post> searchAllPostsOrderByDate() {
List<Post> postList = new ArrayList<>();
try {
Query query = couchDbPost.createAllDocumentsQuery();
query.setAllDocsMode(Query.AllDocsMode.ONLY_CONFLICTS);
QueryEnumerator result = query.run();
for (Iterator<QueryRow> it = result; it.hasNext();) {
QueryRow row = it.next();
postList.add(fillPost(row.getDocument(), row.getDocumentId()));
}
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
Collections.sort(postList, new PostComparator());
return postList;
}
示例2: loadInBackground
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
@Override
public List<QueryRow> loadInBackground() {
try {
List<QueryRow> ret = new ArrayList<QueryRow>();
QueryEnumerator enumerator = query.run();
if (enumerator != null) {
while (enumerator.hasNext()) {
QueryRow row = enumerator.next();
ret.add(row);
}
}
return ret;
} catch (CouchbaseLiteException e) {
throw new RuntimeException(e);
}
}
示例3: getContactDocumentByEmail
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
public Document getContactDocumentByEmail(String email) {
Query query = contactView.createQuery();
query.setStartKey(email);
query.setEndKey(email);
QueryEnumerator enumerator;
try {
enumerator = query.run();
} catch (CouchbaseLiteException e) {
throw new RuntimeException(e);
}
Document ret = null;
if (enumerator.hasNext()) {
QueryRow row = enumerator.next();
ret = row.getDocument();
}
return ret;
}
示例4: getMessagesByGame
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
public List<Document> getMessagesByGame(String modelId) {
Query query = messageByGameView.createQuery();
query.setStartKey(modelId);
query.setEndKey(modelId);
QueryEnumerator enumerator;
try {
enumerator = query.run();
} catch (CouchbaseLiteException e) {
throw new RuntimeException(e);
}
List<Document> ret = new ArrayList<>();
while (enumerator.hasNext()) {
QueryRow row = enumerator.next();
ret.add(row.getDocument());
}
Collections.sort(ret, new Comparator<Document>() {
@Override
public int compare(Document left, Document right) {
return ((String) left.getProperty("id")).compareTo((String) right.getProperty("id"));
}
});
return ret;
}
示例5: getGameDocumentByModelId
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
public Document getGameDocumentByModelId(String id) {
Query query = gameView.createQuery();
query.setStartKey(id);
query.setEndKey(id);
query.setEndKey(id);
QueryEnumerator enumerator;
try {
enumerator = query.run();
} catch (CouchbaseLiteException e) {
throw new RuntimeException(e);
}
Document ret = null;
if (enumerator.hasNext()) {
QueryRow row = enumerator.next();
ret = row.getDocument();
}
return ret;
}
示例6: getGamesByContactQuery
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
public Query getGamesByContactQuery(String email) {
final Query gameQueryByContact = gameIdsByContactView.createQuery();
gameQueryByContact.setStartKey(email);
gameQueryByContact.setEndKey(email);
gameQueryByContact.setDescending(true);
gameQueryByContact.setGroupLevel(1);
Query gameQuery = gameView.createQuery();
try {
List<Object> keys = Collections.emptyList();
if (gameQueryByContact != null) {
QueryEnumerator run = gameQueryByContact.run();
if (run != null) {
QueryRow next = run.next();
if (next != null) {
keys = (List<Object>) next.getValue();
}
}
}
gameQuery.setKeys(keys);
} catch (CouchbaseLiteException e) {
throw new RuntimeException(e);
}
return gameQuery;
}
示例7: queryCities
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
private void queryCities() {
final Query query = database.getView(CITIES_VIEW).createQuery();
query.setGroupLevel(1);
LiveQuery liveQuery = query.toLiveQuery();
liveQuery.addChangeListener(new LiveQuery.ChangeListener() {
@Override
public void changed(LiveQuery.ChangeEvent event) {
try {
QueryEnumerator enumeration = query.run();
for (QueryRow row : enumeration) {
Log.d("CityExplorer", "Row is " + row.getValue() + " and key " + row.getKey());
}
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
}
});
liveQuery.start();
}
示例8: initialize_firstRunPreCouchbase
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
@Test
public void initialize_firstRunPreCouchbase() throws CouchbaseLiteException, IOException {
Context context = InstrumentationRegistry.getTargetContext();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
preferences.edit().putInt("pref_version_code", 23).apply();
PuzzleType.initialize(context);
Query puzzleTypesQuery = App.getDatabase(context).getView("puzzletypes").createQuery();
QueryEnumerator rows = puzzleTypesQuery.run();
for (QueryRow row : rows) {
Log.d("Test", row.getDocument().getUserProperties().toString());
//Actual stuff to test?
}
}
示例9: deleteList
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
private void deleteList(final Document list) {
Application application = (Application) getApplication();
final Query query = application.getTasksView().createQuery();
query.setDescending(true);
List<Object> startKeys = new ArrayList<Object>();
startKeys.add(list.getId());
startKeys.add(new HashMap<String, Object>());
List<Object> endKeys = new ArrayList<Object>();
endKeys.add(list.getId());
query.setStartKey(startKeys);
query.setEndKey(endKeys);
mDatabase.runInTransaction(new TransactionalTask() {
@Override
public boolean run() {
try {
QueryEnumerator tasks = query.run();
while (tasks.hasNext()) {
QueryRow task = tasks.next();
task.getDocument().getCurrentRevision().deleteDocument();
}
list.delete();
} catch (CouchbaseLiteException e) {
Log.e(Application.TAG, "Cannot delete list", e);
return false;
}
return true;
}
});
}
示例10: migrateGuestData
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
public static boolean migrateGuestData(final Database guestDb, final Document profile) {
boolean success = true;
final Database userDB = profile.getDatabase();
if (guestDb.getLastSequenceNumber() > 0 && userDB.getLastSequenceNumber() == 0) {
success = userDB.runInTransaction(new TransactionalTask() {
@Override
public boolean run() {
try {
QueryEnumerator rows = guestDb.createAllDocumentsQuery().run();
for (QueryRow row : rows) {
Document doc = row.getDocument();
Document newDoc = userDB.getDocument(doc.getId());
newDoc.putProperties(doc.getUserProperties());
List<Attachment> attachments = doc.getCurrentRevision().getAttachments();
if (attachments.size() > 0) {
UnsavedRevision rev = newDoc.getCurrentRevision().createRevision();
for (Attachment attachment : attachments) {
rev.setAttachment(
attachment.getName(),
attachment.getContentType(),
attachment.getContent());
}
rev.save();
}
}
// Delete guest database:
guestDb.delete();
} catch (CouchbaseLiteException e) {
Log.e(Application.TAG, "Error when migrating guest data to user", e);
return false;
}
return true;
}
});
}
return success;
}
示例11: searchPostsByAuthor
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
@Override
protected List<Post> searchPostsByAuthor(final Author author) {
List<Post> postList = new ArrayList<>();
try {
com.couchbase.lite.View viewsByAuthor = couchDbPost.getView("viewsByAuthor");
viewsByAuthor.setMap(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
emitter.emit(author.getKey(), document);
}
}, "1.0");
Query query = viewsByAuthor.createQuery();
List<Object> keyArray = new ArrayList<>();
keyArray.add(author.getKey());
query.setKeys(keyArray);
QueryEnumerator rowEnum = query.run();
for (; rowEnum.hasNext(); ) {
QueryRow row = rowEnum.next();
postList.add(fillPost(row.getDocument(), row.getDocumentId()));
}
} catch (Exception e){
e.printStackTrace();
}
return postList;
}
示例12: deleteData
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
public void deleteData() {
try {
for (QueryEnumerator en = database.createAllDocumentsQuery().run(); en.hasNext(); ) {
QueryRow row = en.next();
row.getDocument().delete();
}
database.compact();
} catch (CouchbaseLiteException e) {
throw new RuntimeException(e);
}
}
示例13: queryItemsByIds
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
/**
* 查询指定的json对象,以字符串形式返回
* view 查询的version 为1
*
* @param ids
* @param dataType
* @return
*/
@Override
public List<Map<String, Object>> queryItemsByIds(final String dataType, Object... ids) {
List<Map<String, Object>> datas = new ArrayList<>();
View phoneView = mDatabase.getView(dataType);
if (phoneView != null) {
//建立索引,只建立一次
indexView(phoneView, dataType);
Query query = phoneView.createQuery();
query.setKeys(Arrays.<Object>asList(ids));
query.setLimit(ids.length);
try {
QueryEnumerator qe = query.run();
for (Iterator<QueryRow> it = qe; it.hasNext(); ) {
QueryRow row = it.next();
Document doc = row.getDocument();
Map<String, Object> map = doc.getProperties();
if (map != null && map.size() > 0) {
datas.add(map);
}
}
} catch (Exception e) {
LogUtils.e(e);
}
}
return datas;
}
示例14: queryItemsByTypes
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
@Override
public List<Map<String, Object>> queryItemsByTypes(final String dataType) {
List<Map<String, Object>> datas = new ArrayList<>();
View phoneView = mDatabase.getView(dataType);
if (phoneView != null) {
//建立索引,只建立一次
indexView(phoneView, dataType);
Query query = phoneView.createQuery();
try {
QueryEnumerator qe = query.run();
for (Iterator<QueryRow> it = qe; it.hasNext(); ) {
QueryRow row = it.next();
Document doc = row.getDocument();
Map<String, Object> map = doc.getProperties();
if (map != null && map.size() > 0) {
datas.add(map);
}
}
} catch (Exception e) {
LogUtils.e(e);
String s = e.getMessage();
}
}
return datas;
}
示例15: getAllDocumentIds
import com.couchbase.lite.QueryEnumerator; //导入依赖的package包/类
List<String> getAllDocumentIds(String databaseId) {
Timber.d("getAllDocumentIds: %s", databaseId);
ManagerOptions managerOptions = new ManagerOptions();
managerOptions.setReadOnly(true);
DatabaseOptions databaseOptions = new DatabaseOptions();
databaseOptions.setReadOnly(true);
com.couchbase.lite.Database database = null;
try {
// TODO: Create LiveQuery on this?
// TODO: Open manager/database and cache result - could be expensive operation
Manager manager = new Manager(new AndroidContext(mContext), managerOptions);
database = manager.openDatabase(databaseId, databaseOptions);
List<String> docIds = new ArrayList<>();
QueryEnumerator result = database.createAllDocumentsQuery().run();
while (result.hasNext()) {
QueryRow row = result.next();
docIds.add(row.getDocumentId());
}
return docIds;
} catch (Exception e) {
return Collections.emptyList();
} finally {
if (database != null) {
database.close();
}
}
}