本文整理汇总了Java中com.couchbase.lite.Emitter类的典型用法代码示例。如果您正苦于以下问题:Java Emitter类的具体用法?Java Emitter怎么用?Java Emitter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Emitter类属于com.couchbase.lite包,在下文中一共展示了Emitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTasksView
import com.couchbase.lite.Emitter; //导入依赖的package包/类
public View getTasksView() {
View view = mDatabase.getView("tasks");
if (view.getMap() == null) {
Mapper map = new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
if ("task".equals(document.get("type"))) {
List<Object> keys = new ArrayList<Object>();
keys.add(document.get("list_id"));
keys.add(document.get("created_at"));
emitter.emit(keys, document);
}
}
};
view.setMap(map, "1.0");
}
return view;
}
示例2: doIndexedStringEntityQueries
import com.couchbase.lite.Emitter; //导入依赖的package包/类
@Override
protected void doIndexedStringEntityQueries() throws Exception {
// set up index on string property
View indexedStringView = database.getView("indexedStringView");
indexedStringView.setMap(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
String indexedString = (String) document.get("indexedString");
// only need an index of strings mapped to the document, so provide no value
emitter.emit(indexedString, null);
}
}, "1");
log("Set up view.");
for (int i = 0; i < RUNS; i++) {
log("----Run " + (i + 1) + " of " + RUNS);
indexedStringEntityQueriesRun(indexedStringView, getBatchSize());
}
}
示例3: registerViews
import com.couchbase.lite.Emitter; //导入依赖的package包/类
private void registerViews() {
View citiesView = database.getView(CITIES_VIEW);
citiesView.setMapReduce(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
if (document.get("type") != null && document.get("type").equals("city")) {
List<Object> key = new ArrayList<Object>();
key.add(document.get("city"));
emitter.emit(key, null);
}
}
}, new Reducer() {
@Override
public Object reduce(List<Object> keys, List<Object> values, boolean rereduce) {
return new Integer(values.size());
}
}, "9");
}
示例4: test200SimpleNativeView
import com.couchbase.lite.Emitter; //导入依赖的package包/类
public void test200SimpleNativeView() {
MockEmiter nativeEmiter = new MockEmiter();
Map doc = new HashMap();
doc.put("_id", "foo");
Mapper nativeMap = new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
emitter.emit(document.get("_id"), null);
}
};
for (int i = 0; i < 20000; i++) {
nativeMap.map(doc, nativeEmiter);
}
assertEquals(20000, nativeEmiter.count());
}
示例5: createViewWithReduce
import com.couchbase.lite.Emitter; //导入依赖的package包/类
public static View createViewWithReduce(Database db) {
View view = db.getView(String.format("%s/%s", dDocName, viewReduceName));
view.setMapReduce(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
Assert.assertNotNull(document.get("_id"));
Assert.assertNotNull(document.get("_rev"));
if (document.get("key") != null) {
emitter.emit(document.get("key"), 1);
}
}
}, new Reducer() {
@Override
public Object reduce(List<Object> keys, List<Object> values, boolean rereduce) {
return View.totalValues(values);
}
}, "1"
);
return view;
}
示例6: getListsView
import com.couchbase.lite.Emitter; //导入依赖的package包/类
/** Database View */
public View getListsView() {
View view = mDatabase.getView("lists");
if (view.getMap() == null) {
Mapper mapper = new Mapper() {
public void map(Map<String, Object> document, Emitter emitter) {
String type = (String)document.get("type");
if ("list".equals(type))
emitter.emit(document.get("title"), null);
}
};
view.setMap(mapper, "1.0");
}
return view;
}
示例7: getUserProfilesView
import com.couchbase.lite.Emitter; //导入依赖的package包/类
public View getUserProfilesView() {
View view = mDatabase.getView("profiles");
if (view.getMap() == null) {
Mapper map = new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
if ("profile".equals(document.get("type")))
emitter.emit(document.get("name"), null);
}
};
view.setMap(map, "1.0");
}
return view;
}
示例8: searchPostsByAuthor
import com.couchbase.lite.Emitter; //导入依赖的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;
}
示例9: map
import com.couchbase.lite.Emitter; //导入依赖的package包/类
@Override
public void map(Map<String, Object> document, Emitter emitter) {
String id = (String) document.get("_id");
String type = (String) document.get(CouchBaseStorage.DATA_TYPE);
if (!TextUtils.isEmpty(id) && TextUtils.equals(mType, type)) {
emitter.emit(id, null);
}
}
示例10: registerViews
import com.couchbase.lite.Emitter; //导入依赖的package包/类
private void registerViews() {
View placesView = database.getView(PLACES_VIEW);
placesView.setMap(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
emitter.emit(document.get("_id"), document);
}
}, "1");
}
示例11: map
import com.couchbase.lite.Emitter; //导入依赖的package包/类
@Override
public void map(Map<String, Object> document, Emitter emitter) {
mapGlobalScope.setEmitter(emitter);
org.mozilla.javascript.Context ctx = org.mozilla.javascript.Context.enter();
try {
ctx.setOptimizationLevel(-1);
ctx.setWrapFactory(wrapFactory);
Scriptable localScope = ctx.newObject(globalScope);
localScope.setPrototype(globalScope);
localScope.setParentScope(null);
Object jsDocument = org.mozilla.javascript.Context.javaToJS(document, localScope);
try {
synchronized (lockFunction) {
mapFunction.call(ctx, localScope, null, new Object[]{jsDocument});
}
} catch (org.mozilla.javascript.RhinoException e) {
Log.e(TAG, "Error in calling JavaScript map function", e);
return;
}
} finally {
org.mozilla.javascript.Context.exit();
}
}
示例12: createView
import com.couchbase.lite.Emitter; //导入依赖的package包/类
public static View createView(Database db) {
View view = db.getView(String.format("%s/%s", dDocName, viewName));
view.setMap(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
Assert.assertNotNull(document.get("_id"));
Assert.assertNotNull(document.get("_rev"));
if(document.get("key") != null) {
emitter.emit(document.get("key"), null);
}
}
}, "1");
return view;
}
示例13: testViewQueryFromWeb
import com.couchbase.lite.Emitter; //导入依赖的package包/类
public void testViewQueryFromWeb() throws IOException {
HttpClient httpClient = new CBLiteHttpClient(manager);
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
CouchDbConnector couchDbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);
String dDocName = "ddoc";
String viewName = "people";
View view = database.getView(String.format("%s/%s", dDocName, viewName));
view.setMapReduce(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
String type = (String) document.get("type");
if ("person".equals(type)) {
emitter.emit(null, document.get("_id"));
}
}
}, new Reducer() {
@Override
public Object reduce(List<Object> keys, List<Object> values, boolean rereduce) {
return null;
}
}, "1"
);
ViewQuery viewQuery = new ViewQuery().designDocId("_design/" + dDocName).viewName(viewName);
//viewQuery.descending(true); //use this to reverse the sorting order of the view
ViewResult viewResult = couchDbConnector.queryView(viewQuery);
Assert.assertEquals(0, viewResult.getTotalRows());
}
示例14: testFullScan
import com.couchbase.lite.Emitter; //导入依赖的package包/类
@Override
public void testFullScan() {
setUp();
Benchmark benchmark = new Benchmark() {
@Override
public void setUp() {
delete();
addObjects();
verify();
}
@Override
public void tearDown() {
delete();
}
@Override
public void run() {
View view = database.getView("queries_no_loop");
view.setMap(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
Object name = document.get("name");
Integer age = (Integer)document.get("age");
Boolean hired = (Boolean)document.get("hired");
if (name.equals("Smile1") && (age >= -2 || age <= -1) && hired == false) {
emitter.emit(document.get("id"), document);
}
}
}, "1.0");
Query query = view.createQuery();
QueryEnumerator en;
try {
en = query.run();
} catch (CouchbaseLiteException e) {
throw new RuntimeException("Cannot retrieve object.");
}
}
};
measurements.put(TEST_FULL_SCAN, benchmark.execute(warmupIterations, testIterations));
tearDown();
}
示例15: setEmitter
import com.couchbase.lite.Emitter; //导入依赖的package包/类
public void setEmitter(Emitter emitter) {
this.emitter = emitter;
}