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


Java Emitter类代码示例

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

示例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());
    }
}
 
开发者ID:greenrobot,项目名称:android-database-performance,代码行数:20,代码来源:PerfTestCouchbase.java

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

示例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());
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-javascript,代码行数:19,代码来源:PerformanceTestCase.java

示例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;
}
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:21,代码来源:Views.java

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

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

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

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

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

示例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();
    }
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-javascript,代码行数:28,代码来源:ViewMapBlockRhino.java

示例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;
}
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:15,代码来源:Views.java

示例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());

    }
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:35,代码来源:Views.java

示例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();
}
 
开发者ID:realm,项目名称:realm-java-benchmarks,代码行数:47,代码来源:TestCouch.java

示例15: setEmitter

import com.couchbase.lite.Emitter; //导入依赖的package包/类
public void setEmitter(Emitter emitter) {
    this.emitter = emitter;
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-javascript,代码行数:4,代码来源:MapGlobalScope.java


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