Interface PojoIndexingPlan
-
public interface PojoIndexingPlan
An interface for indexing entities in the context of a session in a POJO mapper.This class is stateful: it queues operations internally to apply them at a later time.
When
process()
is called, the entities will be processed and index documents will be built and stored in an internal buffer.When
executeAndReport(EntityReferenceFactory)
is called, the operations will be actually sent to the index.Note that
executeAndReport(EntityReferenceFactory)
will implicitly trigger processing of documents that weren't processed yet, if any, so callingprocess()
is not necessary if you callexecuteAndReport(EntityReferenceFactory)
just next.Implementations may not be thread-safe.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
add(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, DocumentRoutesDescriptor providedRoutes, Object entity)
Add an entity to the index, assuming that the entity is absent from the index.void
addOrUpdate(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, DocumentRoutesDescriptor providedRoutes, Object entity, boolean forceSelfDirty, boolean forceContainingDirty, BitSet dirtyPaths)
Consider an entity updated, and perform reindexing of this entity as well as containing entities as necessary, taking into accountdirtyPaths
,forceSelfDirty
andforceContainingDirty
.void
addOrUpdateOrDelete(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, DocumentRoutesDescriptor providedRoutes, boolean forceSelfDirty, boolean forceContainingDirty, BitSet dirtyPaths)
Consider an entity added, updated, or deleted, depending on the result of loading it by ID, and perform reindexing of this entity as well as containing entities as necessary, taking into accountdirtyPaths
,forceSelfDirty
andforceContainingDirty
.void
delete(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, DocumentRoutesDescriptor providedRoutes, Object entity)
Delete an entity from the index.void
discard()
Discard all plans of indexing.void
discardNotProcessed()
Discard all plans of indexing, except for parts that were alreadyprocessed
.<R> CompletableFuture<MultiEntityOperationExecutionReport<R>>
executeAndReport(EntityReferenceFactory<R> entityReferenceFactory)
Write all pending changes to the index now, without waiting for a Hibernate ORM flush event or transaction commit, and clear the plan so that it can be re-used.void
process()
Extract all data from objects passed to the indexing plan so far, create documents to be indexed and put them into an internal buffer, without writing them to the indexes.void
updateAssociationInverseSide(PojoRawTypeIdentifier<?> typeIdentifier, BitSet dirtyAssociationPaths, Object[] oldState, Object[] newState)
Consider an association updated with the given entities removed, and perform reindexing of the relevant entities on the inverse side of that association as necessary.
-
-
-
Method Detail
-
add
void add(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, DocumentRoutesDescriptor providedRoutes, Object entity)
Add an entity to the index, assuming that the entity is absent from the index.Note: depending on the backend, this may lead to errors or duplicate entries in the index if the entity was actually already present in the index before this call. When in doubt, you should rather use
addOrUpdate(PojoRawTypeIdentifier, Object, DocumentRoutesDescriptor, Object, boolean, boolean, BitSet)
.- Parameters:
typeIdentifier
- The identifier of the entity type.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. Ifnull
, Hibernate Search will attempt to extract the ID from the entity.providedRoutes
- The route to the current index shard. Only required if custom routing is enabled and theRoutingBridge
is missing. If aRoutingBridge
is assigned to the entity type, the routes will be computed using that bridge instead, and provided routes will be ignored.entity
- The entity to add to the index.
-
addOrUpdate
void addOrUpdate(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, DocumentRoutesDescriptor providedRoutes, Object entity, boolean forceSelfDirty, boolean forceContainingDirty, BitSet dirtyPaths)
Consider an entity updated, and perform reindexing of this entity as well as containing entities as necessary, taking into accountdirtyPaths
,forceSelfDirty
andforceContainingDirty
.- Parameters:
typeIdentifier
- The identifier of the entity type.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. Ifnull
, Hibernate Search will attempt to extract the ID from the entity.providedRoutes
- The routes to the current and previous index shards. Only required if custom routing is enabled and theRoutingBridge
is missing or unable to provide all the correct previous routes. If aRoutingBridge
is assigned to the entity type, the routes will be computed using that bridge instead, and provided routes (current and previous) will all be appended to the generated "previous routes".entity
- The entity to update in the index.forceSelfDirty
- Iftrue
, forces reindexing of this entity regardless of the dirty paths.forceContainingDirty
- Iftrue
, forces the resolution of containing entities as dirtydirtyPaths
- The paths to consider dirty, as aBitSet
. You can build such aBitSet
by obtaining thedirty filter
for the entity type and calling one of thefilter
methods.
-
delete
void delete(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, DocumentRoutesDescriptor providedRoutes, Object entity)
Delete an entity from the index.Entities to reindex as a result of this operation will not be resolved.
No effect on the index if the entity is not in the index.
- Parameters:
typeIdentifier
- The identifier of the entity type.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. If the provided ID isnull
, Hibernate Search will attempt to extract the ID from the entity (which must be non-null
in that case).providedRoutes
- The routes to the current and previous index shards. Only required if custom routing is enabled andentity
is null, or theRoutingBridge
is missing or unable to provide all the correct previous routes. If aRoutingBridge
is assigned to the entity type, andentity
is non-null, the routes will be computed using that bridge instead, and provided routes (current and previous) will all be appended to the generated "previous routes".entity
- The entity to delete from the index. May benull
ifprovidedId
is non-null
.- Throws:
IllegalArgumentException
- If bothprovidedId
andentity
arenull
.
-
addOrUpdateOrDelete
void addOrUpdateOrDelete(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, DocumentRoutesDescriptor providedRoutes, boolean forceSelfDirty, boolean forceContainingDirty, BitSet dirtyPaths)
Consider an entity added, updated, or deleted, depending on the result of loading it by ID, and perform reindexing of this entity as well as containing entities as necessary, taking into accountdirtyPaths
,forceSelfDirty
andforceContainingDirty
.- Parameters:
typeIdentifier
- The identifier of the entity type.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.providedRoutes
- The routes to the current and previous index shards. Only required if custom routing is enabled and theRoutingBridge
is missing or unable to provide all the correct previous routes. If aRoutingBridge
is assigned to the entity type, the routes will be computed using that bridge instead, and provided routes (current and previous) will all be appended to the generated "previous routes".forceSelfDirty
- Iftrue
, forces reindexing of this entity regardless of the dirty paths.forceContainingDirty
- Iftrue
, forces the resolution of containing entities as dirty.dirtyPaths
- The paths to consider dirty, as aBitSet
. You can build such aBitSet
by obtaining thedirty filter
for the entity type and calling one of thefilter
methods.
-
updateAssociationInverseSide
void updateAssociationInverseSide(PojoRawTypeIdentifier<?> typeIdentifier, BitSet dirtyAssociationPaths, Object[] oldState, Object[] newState)
Consider an association updated with the given entities removed, and perform reindexing of the relevant entities on the inverse side of that association as necessary.This is mostly useful for cases where callers do not receive update events for associations on both sides, to have Hibernate Search act "as if" the inverse side of the association had been updated.
WARNING: Getters returning the current state of the association on the removed entities are still expected to return the updated state of the association (for example through lazy-loading). Failing that, reindexing will index out-of-date information.
- Parameters:
typeIdentifier
- The identifier of the entity type on one side of the association.dirtyAssociationPaths
- The association paths to consider dirty, as aBitSet
. You can build such aBitSet
by obtaining thedirty association filter
for the entity type and calling one of thefilter
methods.oldState
- The old state of the entity whose associations are dirty. May benull
, in which case this state will not yield any reindexing.newState
- The new state of the entity whose associations are dirty. May benull
, in which case this state will not yield any reindexing.
-
process
void process()
Extract all data from objects passed to the indexing plan so far, create documents to be indexed and put them into an internal buffer, without writing them to the indexes.In particular, ensure that all data is extracted from the POJOs and converted to the backend-specific format.
Calling this method is optional: the
executeAndReport(EntityReferenceFactory)
method will perform the processing if necessary.
-
executeAndReport
<R> CompletableFuture<MultiEntityOperationExecutionReport<R>> executeAndReport(EntityReferenceFactory<R> entityReferenceFactory)
Write all pending changes to the index now, without waiting for a Hibernate ORM flush event or transaction commit, and clear the plan so that it can be re-used.- Type Parameters:
R
- The type of entity references in the returned execution report.- Parameters:
entityReferenceFactory
- A factory for entity references in the returned execution report.- Returns:
- A
CompletableFuture
that will be completed with an execution report when all the works are complete.
-
discard
void discard()
Discard all plans of indexing.
-
discardNotProcessed
void discardNotProcessed()
Discard all plans of indexing, except for parts that were alreadyprocessed
.
-
-