MapR OJAI框架中jsonStore变量的类型确定问题
确定OJAI中jsonStore的正确类型
你的代码里jsonStore应该使用org.ojai.store.DocumentStore类型,原因如下:
- 你调用的
query()、queryAsStream()、getAllDocumentsAsStream()这些方法,完全匹配OJAI框架中DocumentStore接口的核心能力——它是OJAI用于文档存储操作的顶层接口,涵盖了文档查询、流式返回、条件构造等所有你用到的操作。 - 注意代码里的一个小错误:
jsonStore.getQueryCondition()应该改为jsonStore.createQueryCondition(),DocumentStore提供的是创建查询条件的createQueryCondition()方法,而非getQueryCondition()。
修改后的父类代码示例:
import org.ojai.Document; import org.ojai.store.DocumentStore; public class JsonRepository { public DocumentStore jsonStore; // 替换为DocumentStore类型 public Document createDocument() { // ... 原有逻辑 } }
子类中修正后的方法片段:
public DocumentStream accountsAsStream(List<String> ids) { QueryCondition condition = jsonStore.createQueryCondition().in("_id", ids); // 注:in方法第一个参数应为字段名,你写的123是笔误,比如改成文档ID字段"_id" List<Document> documents = jsonStore.query(condition); // ... 原有逻辑 return jsonStore.queryAsStream(condition); }
内容的提问来源于stack exchange,提问作者Peter Penzov
相关产品推荐
相关产品推荐

