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


Java Mapper类代码示例

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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