public class NoneDocStore extends Object implements DocumentStore
| Constructor and Description |
|---|
NoneDocStore() |
| Modifier and Type | Method and Description |
|---|---|
long |
copyIndex(Class<?> beanType,
String newIndex)
Copy the index to a new index.
|
long |
copyIndex(Class<?> beanType,
String newIndex,
long epochMillis)
Copy entries from an index to a new index but limiting to documents that have been
modified since the sinceEpochMillis time.
|
long |
copyIndex(Query<?> query,
String newIndex,
int bulkBatchSize)
Copy from a source index to a new index taking only the documents
matching the given query.
|
void |
createIndex(String indexName,
String alias)
Create an index given a mapping file as a resource in the classPath (similar to DDL create table).
|
void |
dropIndex(String newIndex)
Drop the index from the document store (similar to DDL drop table).
|
<T> T |
find(DocQueryRequest<T> request)
Return the bean by fetching it's content from the document store.
|
<T> void |
findEach(DocQueryRequest<T> query,
java.util.function.Consumer<T> consumer)
Execute the query against the document store with the expectation of a large set of results
that are processed in a scrolling resultSet fashion.
|
void |
findEach(String indexNameType,
String rawQuery,
java.util.function.Consumer<RawDoc> consumer)
Find each processing raw documents.
|
<T> void |
findEachWhile(DocQueryRequest<T> query,
java.util.function.Predicate<T> consumer)
Execute the query against the document store with the expectation of a large set of results
that are processed in a scrolling resultSet fashion.
|
void |
findEachWhile(String indexNameType,
String rawQuery,
java.util.function.Predicate<RawDoc> consumer)
Find each processing raw documents stopping when the predicate returns false.
|
<T> List<T> |
findList(DocQueryRequest<T> request)
Execute the find list query.
|
<T> PagedList<T> |
findPagedList(DocQueryRequest<T> request)
Execute the query against the document store returning the paged list.
|
static IllegalStateException |
implementationNotInClassPath() |
void |
indexAll(Class<?> countryClass)
Update the document store for all beans of this type.
|
<T> void |
indexByQuery(Query<T> query)
Update the associated document store using the result of the query.
|
<T> void |
indexByQuery(Query<T> query,
int bulkBatchSize)
Update the associated document store index using the result of the query additionally specifying a
bulkBatchSize to use for sending the messages to ElasticSearch.
|
void |
indexSettings(String indexName,
Map<String,Object> settings)
Modify the settings on an index.
|
long |
process(List<DocStoreQueueEntry> queueEntries)
Process the queue entries sending updates to the document store or queuing them for later processing.
|
public NoneDocStore()
public static IllegalStateException implementationNotInClassPath()
public void indexSettings(String indexName, Map<String,Object> settings)
DocumentStoreFor example, this can be used be used to set elasticSearch refresh_interval on an index before a bulk update.
// refresh_interval -1 ... disable refresh while bulk loading
Map<String,Object> settings = new LinkedHashMap<>();
settings.put("refresh_interval", "-1");
documentStore.indexSettings("product", settings);
// refresh_interval 1s ... restore after bulk loading
Map<String,Object> settings = new LinkedHashMap<>();
settings.put("refresh_interval", "1s");
documentStore.indexSettings("product", settings);
indexSettings in interface DocumentStoreindexName - the name of the index to update settings onsettings - the settings to set on the indexpublic void dropIndex(String newIndex)
DocumentStore DocumentStore documentStore = server.docStore();
documentStore.dropIndex("product_copy");
dropIndex in interface DocumentStorepublic void createIndex(String indexName, String alias)
DocumentStore DocumentStore documentStore = server.docStore();
// uses product_copy.mapping.json resource
// ... to define mappings for the index
documentStore.createIndex("product_copy", null);
createIndex in interface DocumentStoreindexName - the name of the new indexalias - the alias of the indexpublic void indexAll(Class<?> countryClass)
DocumentStoreThis is the same as indexByQuery where the query has no predicates and so fetches all rows.
indexAll in interface DocumentStorepublic long copyIndex(Class<?> beanType, String newIndex)
DocumentStoreThis copy process does not use the database but instead will copy from the source index to a destination index.
long copyCount = documentStore.copyIndex(Product.class, "product_copy");
copyIndex in interface DocumentStorebeanType - The bean type of the source indexnewIndex - The name of the index to copy topublic long copyIndex(Class<?> beanType, String newIndex, long epochMillis)
DocumentStore
To support this the document needs to have a @WhenModified property.
long copyCount = documentStore.copyIndex(Product.class, "product_copy", sinceMillis);
copyIndex in interface DocumentStorebeanType - The bean type of the source indexnewIndex - The name of the index to copy topublic long copyIndex(Query<?> query, String newIndex, int bulkBatchSize)
DocumentStore // predicates to select the source documents to copy
Query<Product> query = server.find(Product.class)
.where()
.ge("whenModified", new Timestamp(since))
.ge("name", "A")
.lt("name", "D")
.query();
// copy from the source index to "product_copy" index
long copyCount = documentStore.copyIndex(query, "product_copy", 1000);
copyIndex in interface DocumentStorequery - The query to select the source documents to copynewIndex - The target index to copy the documents tobulkBatchSize - The ElasticSearch bulk batch size, if 0 uses the default.public <T> void indexByQuery(Query<T> query)
DocumentStoreThis will execute the query against the database creating a document for each bean graph and sending this to the document store.
Note that the select and fetch paths of the query is set for you to match the
document structure needed based on @DocStore and @DocStoreEmbedded
so what this query requires is the predicates only.
This query will be executed using findEach so it is safe to use a query that will fetch a lot of beans. The default bulkBatchSize is used.
indexByQuery in interface DocumentStorequery - The query that selects object to send to the document store.public <T> void indexByQuery(Query<T> query, int bulkBatchSize)
DocumentStoreindexByQuery in interface DocumentStorequery - The query that selects object to send to the document store.bulkBatchSize - The batch size to use when bulk sending to the document store.public <T> T find(DocQueryRequest<T> request)
DocumentStoreTypically this is called indirectly by findOne() on the query.
Customer customer =
server.find(Customer.class)
.setUseDocStore(true)
.setId(42)
.findOne();
find in interface DocumentStorepublic <T> PagedList<T> findPagedList(DocQueryRequest<T> request)
DocumentStore
The query should have firstRow or maxRows set prior to calling this method.
Typically this is called indirectly by findPagedList() on the query that has setUseDocStore(true).
PagedList<Customer> newCustomers =
server.find(Customer.class)
.setUseDocStore(true)
.where().eq("status, Customer.Status.NEW)
.setMaxRows(50)
.findPagedList();
findPagedList in interface DocumentStorepublic <T> List<T> findList(DocQueryRequest<T> request)
DocumentStoreTypically this is called indirectly by findList() on the query that has setUseDocStore(true).
List<Customer> newCustomers =
server.find(Customer.class)
.setUseDocStore(true)
.where().eq("status, Customer.Status.NEW)
.findList();
findList in interface DocumentStorepublic <T> void findEach(DocQueryRequest<T> query, java.util.function.Consumer<T> consumer)
DocumentStoreFor example, with the ElasticSearch doc store this uses SCROLL.
Typically this is called indirectly by findEach() on the query that has setUseDocStore(true).
server.find(Order.class)
.setUseDocStore(true)
.where()... // perhaps add predicates
.findEach((Order order) -> {
// process the bean ...
});
findEach in interface DocumentStorepublic <T> void findEachWhile(DocQueryRequest<T> query, java.util.function.Predicate<T> consumer)
DocumentStoreUnlike findEach() this provides the opportunity to stop iterating through the large query.
For example, with the ElasticSearch doc store this uses SCROLL.
Typically this is called indirectly by findEachWhile() on the query that has setUseDocStore(true).
server.find(Order.class)
.setUseDocStore(true)
.where()... // perhaps add predicates
.findEachWhile(new Predicate<Order>() {
@Override
public void accept(Order bean) {
// process the bean
// return true to continue, false to stop
// boolean shouldContinue = ...
return shouldContinue;
}
});
findEachWhile in interface DocumentStorepublic void findEach(String indexNameType, String rawQuery, java.util.function.Consumer<RawDoc> consumer)
DocumentStorefindEach in interface DocumentStoreindexNameType - The full index name and typerawQuery - The query to executeconsumer - Consumer to process each documentpublic void findEachWhile(String indexNameType, String rawQuery, java.util.function.Predicate<RawDoc> consumer)
DocumentStorefindEachWhile in interface DocumentStoreindexNameType - The full index name and typerawQuery - The query to executeconsumer - Consumer to process each document until false is returnedpublic long process(List<DocStoreQueueEntry> queueEntries) throws IOException
DocumentStoreprocess in interface DocumentStoreIOExceptionCopyright © 2019. All rights reserved.