本文整理汇总了Java中com.couchbase.lite.Mapper类的典型用法代码示例。如果您正苦于以下问题:Java Mapper类的具体用法?Java Mapper怎么用?Java Mapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mapper类属于com.couchbase.lite包,在下文中一共展示了Mapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTasksView
import com.couchbase.lite.Mapper; //导入依赖的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.Mapper; //导入依赖的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.Mapper; //导入依赖的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.Mapper; //导入依赖的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: testScopeSeparation
import com.couchbase.lite.Mapper; //导入依赖的package包/类
public void testScopeSeparation() {
Map doc = new HashMap();
doc.put("_id", "foo");
// try to put a var "x" into global scope
Mapper map = viewCompiler.compileMap("function(doc){var x = x || 0; emit(x++,null);}", "javascript");
map.map(doc, emiter);
map.map(doc, emiter);
map.map(doc, emiter);
assertEquals(3, emiter.count());
assertEquals(new EmitPair(0.0, null), emiter.get(0));
assertEquals(new EmitPair(0.0, null), emiter.get(1));
assertEquals(new EmitPair(0.0, null), emiter.get(2));
}
示例6: testJavaScriptDesignDocument
import com.couchbase.lite.Mapper; //导入依赖的package包/类
public void testJavaScriptDesignDocument() {
Map<String, Object> doc1 = new HashMap<String, Object>();
doc1.put("_id", "doc1");
doc1.put("message", "hello");
Map<String, Object> doc2 = new HashMap<String, Object>();
doc2.put("_id", "doc2");
doc2.put("message", "guten tag");
Map<String, Object> doc3 = new HashMap<String, Object>();
doc3.put("_id", "doc3");
doc3.put("message", "bonjour");
Mapper map = viewCompiler.compileMap("function(doc) { if(doc.message) { emit(doc.message, 1); } }", "javascript");
map.map(doc1, emiter);
map.map(doc2, emiter);
map.map(doc3, emiter);
assertEquals(3, emiter.count());
assertEquals(new EmitPair("hello", 1.0), emiter.get(0));
assertEquals(new EmitPair("guten tag", 1.0), emiter.get(1));
assertEquals(new EmitPair("bonjour", 1.0), emiter.get(2));
}
示例7: createViewWithReduce
import com.couchbase.lite.Mapper; //导入依赖的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;
}
示例8: getListsView
import com.couchbase.lite.Mapper; //导入依赖的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;
}
示例9: getUserProfilesView
import com.couchbase.lite.Mapper; //导入依赖的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;
}
示例10: searchPostsByAuthor
import com.couchbase.lite.Mapper; //导入依赖的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;
}
示例11: registerViews
import com.couchbase.lite.Mapper; //导入依赖的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");
}
示例12: compileView
import com.couchbase.lite.Mapper; //导入依赖的package包/类
/**
* VIEW QUERIES: *
*/
private View compileView(String viewName, Map<String, Object> viewProps) {
String language = (String) viewProps.get("language");
if (language == null) {
language = "javascript";
}
String mapSource = (String) viewProps.get("map");
if (mapSource == null) {
return null;
}
Mapper mapBlock = View.getCompiler().compileMap(mapSource, language);
if (mapBlock == null) {
Log.w(TAG, "View %s has unknown map function: %s", viewName, mapSource);
return null;
}
String reduceSource = (String) viewProps.get("reduce");
Reducer reduceBlock = null;
if (reduceSource != null) {
reduceBlock = View.getCompiler().compileReduce(reduceSource, language);
if (reduceBlock == null) {
Log.w(TAG, "View %s has unknown reduce function: %s", viewName, reduceBlock);
return null;
}
}
String version = Misc.HexSHA1Digest(viewProps.toString().getBytes());
View view = db.getView(viewName);
view.setMapReduce(mapBlock, reduceBlock, version);
String collation = (String) viewProps.get("collation");
if ("raw".equals(collation)) {
view.setCollation(View.TDViewCollation.TDViewCollationRaw);
}
return view;
}
示例13: compileMap
import com.couchbase.lite.Mapper; //导入依赖的package包/类
@Override
public Mapper compileMap(String source, String language) {
if (language != null && language.equalsIgnoreCase("javascript")) {
return new ViewMapBlockRhino(source);
}
throw new IllegalArgumentException(language + " is not supported");
}
示例14: test200SimpleJavaScriptView
import com.couchbase.lite.Mapper; //导入依赖的package包/类
public void test200SimpleJavaScriptView() {
MockEmiter jsEmiter = new MockEmiter();
Map doc = new HashMap();
doc.put("_id", "foo");
Mapper jsMap = viewCompiler.compileMap("function(doc){emit(doc._id,null);}", "javascript");
for (int i = 0; i < 20000; i++) {
jsMap.map(doc, jsEmiter);
}
assertEquals(20000, jsEmiter.count());
}
示例15: testSimpleJavaScriptView
import com.couchbase.lite.Mapper; //导入依赖的package包/类
public void testSimpleJavaScriptView() {
Map doc = new HashMap();
doc.put("_id", "foo");
Mapper map = viewCompiler.compileMap("function(doc){emit(doc._id,null);}", "javascript");
map.map(doc, emiter);
assertEquals(1, emiter.count());
assertEquals(new EmitPair("foo", null), emiter.get(0));
}