当前位置: 首页>>代码示例>>Java>>正文


Java QueryEnumerator类代码示例

本文整理汇总了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;
}
 
开发者ID:AmeliaPessoa,项目名称:DBPA,代码行数:18,代码来源:CouchbaseLite.java

示例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);
	}
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:17,代码来源:DataLoader.java

示例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;
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:18,代码来源:DataServiceImpl.java

示例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;
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:24,代码来源:DataServiceImpl.java

示例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;
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:19,代码来源:DataServiceImpl.java

示例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;
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:26,代码来源:DataServiceImpl.java

示例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();
}
 
开发者ID:couchbaselabs,项目名称:mini-hacks,代码行数:23,代码来源:SyncManager.java

示例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?
    }
}
 
开发者ID:plusCubed,项目名称:plusTimer,代码行数:18,代码来源:PuzzleTypeTest.java

示例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;
        }
    });
}
 
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:34,代码来源:ListActivity.java

示例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;
}
 
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:39,代码来源:UserProfile.java

示例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;
}
 
开发者ID:AmeliaPessoa,项目名称:DBPA,代码行数:30,代码来源:CouchbaseLite.java

示例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);
    }
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:12,代码来源:DataServiceImpl.java

示例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;
}
 
开发者ID:jessie345,项目名称:RealArchitecture,代码行数:45,代码来源:CouchBaseStorage.java

示例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;
}
 
开发者ID:jessie345,项目名称:RealArchitecture,代码行数:34,代码来源:CouchBaseStorage.java

示例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();
        }
    }
}
 
开发者ID:RobotPajamas,项目名称:Stetho-Couchbase,代码行数:32,代码来源:CouchbasePeerManager.java


注:本文中的com.couchbase.lite.QueryEnumerator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。