public interface SearchSessionWritePlan
When a transaction is active, operations are queued internally, and are only applied on transaction commit.
process() and execute() allow to control explicitly
how operations are applied, without relying on transaction commits,
which can be useful when indexing large amounts of data in batches.
| Modifier and Type | Method and Description |
|---|---|
void |
addOrUpdate(Object entity)
Add or update a document in the index if the entity type is mapped to an index
(
Indexed),
and re-index documents that embed this entity
(through IndexedEmbedded for example). |
void |
delete(Object entity)
Delete the entity from the index if the entity type is mapped to an index
(
Indexed),
and re-index documents that embed this entity
(through IndexedEmbedded for example). |
void |
execute()
Write all pending changes to the index now,
without waiting for a Hibernate ORM flush event or transaction commit.
|
void |
process()
Extract all data from objects passed to the writer so far,
without writing to the indexes.
|
void |
purge(Class<?> entityClass,
Object providedId)
Delete the entity from the index.
|
void addOrUpdate(Object entity)
Indexed),
and re-index documents that embed this entity
(through IndexedEmbedded for example).entity - The entity to add or update in the index.SearchException - If the entity type is not indexed,
neither directly (Indexed)
nor through another indexed type that embeds it (IndexedEmbedded for example).void delete(Object entity)
Indexed),
and re-index documents that embed this entity
(through IndexedEmbedded for example).entity - The entity to delete from the index.SearchException - If the entity type is not indexed,
neither directly (Indexed)
nor through another indexed type that embeds it (IndexedEmbedded for example).void purge(Class<?> entityClass, Object providedId)
On contrary to delete(Object),
if documents embed this entity
(through IndexedEmbedded for example),
these documents will not be re-indexed,
leaving the indexes in an inconsistent state
until they are re-indexed manually.
entityClass - The class of the entity to delete from the index.providedId - A value to extract the document ID from.
Generally the expected value is the entity ID, but a different value may be expected depending on the mapping.SearchException - If the entity type is not indexed directly
(Indexed).void process()
Calling this method is optional: the execute() method
or the automatic write on transaction commit will perform the extraction as necessary.
However, calling this method can be useful before a session is cleared: it will make sure the data lost when clearing the session will no longer be necessary for indexing.
Caution: calling this method repeatedly without a call to execute()
will add more and more data to an internal write buffer,
which may lead to an OutOfMemoryError.
Use with caution in batch processes.
void execute()
If a transaction is active and is ultimately rolled back, the written changes will not be rolled back, causing indexes to become out of sync with the database. Thus, calling this method should generally be avoided, and relying on automatic write on transaction commit should be preferred.
Copyright © 2006-2019 Red Hat, Inc. and others. Licensed under the GNU Lesser General Public License (LGPL), version 2.1 or later.