From 07ce7583022566422972685188195af6c06e6e15 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Thu, 2 Mar 2017 01:12:02 +1300 Subject: [PATCH] #984 - ENH: DocumentStore API - add RawDoc with findEach() and findEachWhile() --- src/main/java/io/ebean/DocumentStore.java | 19 ++++ .../io/ebeanservice/docstore/api/RawDoc.java | 102 ++++++++++++++++++ .../docstore/none/NoneDocStore.java | 11 ++ 3 files changed, 132 insertions(+) create mode 100644 src/main/java/io/ebeanservice/docstore/api/RawDoc.java diff --git a/src/main/java/io/ebean/DocumentStore.java b/src/main/java/io/ebean/DocumentStore.java index 68bb8a765..cecacbec9 100644 --- a/src/main/java/io/ebean/DocumentStore.java +++ b/src/main/java/io/ebean/DocumentStore.java @@ -1,6 +1,7 @@ package io.ebean; import io.ebeanservice.docstore.api.DocQueryRequest; +import io.ebeanservice.docstore.api.RawDoc; import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -165,6 +166,24 @@ public interface DocumentStore { */ void findEachWhile(DocQueryRequest query, Predicate consumer); + /** + * Find each processing raw documents. + * + * @param indexNameType The full index name and type + * @param rawQuery The query to execute + * @param consumer Consumer to process each document + */ + void findEach(String indexNameType, String rawQuery, Consumer consumer); + + /** + * Find each processing raw documents stopping when the predicate returns false. + * + * @param indexNameType The full index name and type + * @param rawQuery The query to execute + * @param consumer Consumer to process each document until false is returned + */ + void findEachWhile(String indexNameType, String rawQuery, Predicate consumer); + /** * Process the queue entries sending updates to the document store or queuing them for later processing. */ diff --git a/src/main/java/io/ebeanservice/docstore/api/RawDoc.java b/src/main/java/io/ebeanservice/docstore/api/RawDoc.java new file mode 100644 index 000000000..b2f4d4412 --- /dev/null +++ b/src/main/java/io/ebeanservice/docstore/api/RawDoc.java @@ -0,0 +1,102 @@ +package io.ebeanservice.docstore.api; + +import java.util.Map; + +/** + * Raw document. + */ +public class RawDoc { + + private Map source; + private String id; + private double score; + private String index; + private String type; + + /** + * Construct the document with all the meta data. + */ + public RawDoc(Map source, String id, double score, String index, String type) { + this.source = source; + this.id = id; + this.score = score; + this.index = index; + this.type = type; + } + + /** + * Construct empty (typically for JSON marshalling). + */ + public RawDoc() { + } + + /** + * Return the source document as a Map. + */ + public Map getSource() { + return source; + } + + /** + * Return the Id value. + */ + public String getId() { + return id; + } + + /** + * Return the score. + */ + public double getScore() { + return score; + } + + /** + * Return the index name. + */ + public String getIndex() { + return index; + } + + /** + * Return the index type. + */ + public String getType() { + return type; + } + + /** + * Set the source document. + */ + public void setSource(Map source) { + this.source = source; + } + + /** + * Set the id value. + */ + public void setId(String id) { + this.id = id; + } + + /** + * Set the score. + */ + public void setScore(double score) { + this.score = score; + } + + /** + * Set the index name. + */ + public void setIndex(String index) { + this.index = index; + } + + /** + * Set the index type. + */ + public void setType(String type) { + this.type = type; + } +} diff --git a/src/main/java/io/ebeanservice/docstore/none/NoneDocStore.java b/src/main/java/io/ebeanservice/docstore/none/NoneDocStore.java index b5200f78d..8b44d7e9d 100644 --- a/src/main/java/io/ebeanservice/docstore/none/NoneDocStore.java +++ b/src/main/java/io/ebeanservice/docstore/none/NoneDocStore.java @@ -5,6 +5,7 @@ import io.ebean.DocumentStore; import io.ebean.PagedList; import io.ebean.Query; import io.ebeanservice.docstore.api.DocQueryRequest; +import io.ebeanservice.docstore.api.RawDoc; import java.io.IOException; import java.util.List; @@ -91,6 +92,16 @@ public class NoneDocStore implements DocumentStore { throw implementationNotInClassPath(); } + @Override + public void findEach(String indexNameType, String rawQuery, Consumer consumer) { + throw implementationNotInClassPath(); + } + + @Override + public void findEachWhile(String indexNameType, String rawQuery, Predicate consumer) { + throw implementationNotInClassPath(); + } + @Override public long process(List queueEntries) throws IOException { throw implementationNotInClassPath();