diff --git a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/mapping/impl/PojoIndexedTypeManager.java b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/mapping/impl/PojoIndexedTypeManager.java index 5130bff6e5b..8dd52d36f84 100644 --- a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/mapping/impl/PojoIndexedTypeManager.java +++ b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/mapping/impl/PojoIndexedTypeManager.java @@ -147,7 +147,7 @@ public boolean requiresSelfReindexing(Set dirtyPaths) { @Override public void resolveEntitiesToReindex(PojoReindexingCollector collector, PojoWorkSessionContext sessionContext, - I identifier, Supplier entitySupplier, Set dirtyPaths) { + Object identifier, Supplier entitySupplier, Set dirtyPaths) { try { reindexingResolver.resolveEntitiesToReindex( collector, sessionContext.runtimeIntrospector(), entitySupplier.get(), dirtyPaths ); diff --git a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/AbstractPojoTypeIndexingPlan.java b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/AbstractPojoTypeIndexingPlan.java index c82f15811d7..22f0ce705b3 100644 --- a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/AbstractPojoTypeIndexingPlan.java +++ b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/AbstractPojoTypeIndexingPlan.java @@ -6,24 +6,165 @@ */ package org.hibernate.search.mapper.pojo.work.impl; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; +import java.util.function.Supplier; + +import org.hibernate.search.mapper.pojo.automaticindexing.impl.PojoReindexingCollector; import org.hibernate.search.mapper.pojo.work.spi.PojoWorkSessionContext; -abstract class AbstractPojoTypeIndexingPlan { +/** + * @param The type of identifiers of entities in this plan. + * @param The type of entities in this plan. + * @param The type of per-instance state. + */ +abstract class AbstractPojoTypeIndexingPlan.AbstractEntityState> { final PojoWorkSessionContext sessionContext; + // Use a LinkedHashMap for deterministic iteration + final Map statesPerId = new LinkedHashMap<>(); + AbstractPojoTypeIndexingPlan(PojoWorkSessionContext sessionContext) { this.sessionContext = sessionContext; } - abstract void add(Object providedId, String providedRoutingKey, Object entity); + void add(Object providedId, String providedRoutingKey, Object entity) { + Supplier entitySupplier = typeContext().toEntitySupplier( sessionContext, entity ); + I identifier = toIdentifier( providedId, entitySupplier ); + getState( identifier ).add( entitySupplier, providedRoutingKey ); + } - abstract void update(Object providedId, String providedRoutingKey, Object entity); + void update(Object providedId, String providedRoutingKey, Object entity) { + Supplier entitySupplier = typeContext().toEntitySupplier( sessionContext, entity ); + I identifier = toIdentifier( providedId, entitySupplier ); + getState( identifier ).update( entitySupplier, providedRoutingKey ); + } - abstract void update(Object providedId, String providedRoutingKey, Object entity, String... dirtyPaths); + void update(Object providedId, String providedRoutingKey, Object entity, String... dirtyPaths) { + Supplier entitySupplier = typeContext().toEntitySupplier( sessionContext, entity ); + I identifier = toIdentifier( providedId, entitySupplier ); + getState( identifier ).update( entitySupplier, providedRoutingKey, dirtyPaths ); + } - abstract void delete(Object providedId, String providedRoutingKey, Object entity); + void delete(Object providedId, String providedRoutingKey, Object entity) { + Supplier entitySupplier = typeContext().toEntitySupplier( sessionContext, entity ); + I identifier = toIdentifier( providedId, entitySupplier ); + getState( identifier ).delete( entitySupplier, providedRoutingKey ); + } abstract void purge(Object providedId, String providedRoutingKey); + void resolveDirty(PojoReindexingCollector containingEntityCollector) { + for ( S state : statesPerId.values() ) { + state.resolveDirty( containingEntityCollector ); + } + } + + abstract PojoWorkTypeContext typeContext(); + + abstract I toIdentifier(Object providedId, Supplier entitySupplier); + + final S getState(I identifier) { + S state = statesPerId.get( identifier ); + if ( state == null ) { + state = createState( identifier ); + statesPerId.put( identifier, state ); + } + return state; + } + + protected abstract S createState(I identifier); + + abstract class AbstractEntityState { + final I identifier; + Supplier entitySupplier; + + boolean delete; + boolean add; + + boolean shouldResolveToReindex; + boolean considerAllDirty; + Set dirtyPaths; + + AbstractEntityState(I identifier) { + this.identifier = identifier; + } + + void add(Supplier entitySupplier, String providedRoutingKey) { + this.entitySupplier = entitySupplier; + shouldResolveToReindex = true; + add = true; + } + + void update(Supplier entitySupplier, String providedRoutingKey) { + doUpdate( entitySupplier, providedRoutingKey ); + shouldResolveToReindex = true; + considerAllDirty = true; + dirtyPaths = null; + } + + void update(Supplier entitySupplier, String providedRoutingKey, String... dirtyPaths) { + doUpdate( entitySupplier, providedRoutingKey ); + shouldResolveToReindex = true; + if ( !considerAllDirty ) { + for ( String dirtyPath : dirtyPaths ) { + addDirtyPath( dirtyPath ); + } + } + } + + void doUpdate(Supplier entitySupplier, String providedRoutingKey) { + this.entitySupplier = entitySupplier; + if ( !add ) { + delete = true; + add = true; + } + // else: If add is true, either this is already an update (in which case update + update = update) + // or we called add() in the same plan (in which case add + update = add). + // In any case we don't need to change anything. + } + + void delete(Supplier entitySupplier, String providedRoutingKey) { + this.entitySupplier = entitySupplier; + if ( add && !delete ) { + // We called add() in the same plan, so the entity didn't exist. + // Don't delete, just cancel the addition. + add = false; + delete = false; + } + else { + // No add or update yet, or already deleted. + // Either way, delete. + add = false; + delete = true; + } + + // Reindexing does not make sense for a deleted entity + shouldResolveToReindex = false; + considerAllDirty = false; + dirtyPaths = null; + } + + void resolveDirty(PojoReindexingCollector containingEntityCollector) { + if ( shouldResolveToReindex ) { + shouldResolveToReindex = false; // Avoid infinite looping + typeContext().resolveEntitiesToReindex( + containingEntityCollector, sessionContext, identifier, entitySupplier, + considerAllDirty ? null : dirtyPaths + ); + } + } + + private void addDirtyPath(String dirtyPath) { + if ( dirtyPaths == null ) { + dirtyPaths = new HashSet<>(); + } + dirtyPaths.add( dirtyPath ); + } + } + + } diff --git a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoContainedTypeIndexingPlan.java b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoContainedTypeIndexingPlan.java index c4c072127fd..aa1c5a14a5f 100644 --- a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoContainedTypeIndexingPlan.java +++ b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoContainedTypeIndexingPlan.java @@ -7,13 +7,8 @@ package org.hibernate.search.mapper.pojo.work.impl; import java.lang.invoke.MethodHandles; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; import java.util.function.Supplier; -import org.hibernate.search.mapper.pojo.automaticindexing.impl.PojoReindexingCollector; import org.hibernate.search.mapper.pojo.logging.impl.Log; import org.hibernate.search.mapper.pojo.work.spi.PojoWorkSessionContext; import org.hibernate.search.util.common.logging.impl.LoggerFactory; @@ -21,15 +16,13 @@ /** * @param The contained entity type. */ -public class PojoContainedTypeIndexingPlan extends AbstractPojoTypeIndexingPlan { +public class PojoContainedTypeIndexingPlan + extends AbstractPojoTypeIndexingPlan.ContainedEntityState> { private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); private final PojoWorkContainedTypeContext typeContext; - // Use a LinkedHashMap for deterministic iteration - private final Map indexingPlansPerId = new LinkedHashMap<>(); - public PojoContainedTypeIndexingPlan(PojoWorkContainedTypeContext typeContext, PojoWorkSessionContext sessionContext) { super( sessionContext ); @@ -37,133 +30,29 @@ public PojoContainedTypeIndexingPlan(PojoWorkContainedTypeContext typeContext } @Override - void add(Object providedId, String providedRoutingKey, Object entity) { - Supplier entitySupplier = typeContext.toEntitySupplier( sessionContext, entity ); - getPlan( providedId ).add( entitySupplier ); - } - - @Override - void update(Object providedId, String providedRoutingKey, Object entity) { - Supplier entitySupplier = typeContext.toEntitySupplier( sessionContext, entity ); - getPlan( providedId ).update( entitySupplier ); + void purge(Object providedId, String providedRoutingKey) { + throw log.cannotPurgeNonIndexedContainedType( typeContext.typeIdentifier(), providedId ); } @Override - void update(Object providedId, String providedRoutingKey, Object entity, String... dirtyPaths) { - Supplier entitySupplier = typeContext.toEntitySupplier( sessionContext, entity ); - getPlan( providedId ).update( entitySupplier, dirtyPaths ); + PojoWorkContainedTypeContext typeContext() { + return typeContext; } @Override - void delete(Object providedId, String providedRoutingKey, Object entity) { - Supplier entitySupplier = typeContext.toEntitySupplier( sessionContext, entity ); - getPlan( providedId ).delete( entitySupplier ); + Object toIdentifier(Object providedId, Supplier entitySupplier) { + return providedId; } @Override - void purge(Object providedId, String providedRoutingKey) { - throw log.cannotPurgeNonIndexedContainedType( typeContext.typeIdentifier(), providedId ); + protected ContainedEntityState createState(Object identifier) { + return new ContainedEntityState( identifier ); } - void resolveDirty(PojoReindexingCollector containingEntityCollector) { - for ( ContainedEntityIndexingPlan plan : indexingPlansPerId.values() ) { - plan.resolveDirty( containingEntityCollector ); - } - } - - private ContainedEntityIndexingPlan getPlan(Object identifier) { - ContainedEntityIndexingPlan plan = indexingPlansPerId.get( identifier ); - if ( plan == null ) { - plan = new ContainedEntityIndexingPlan( identifier ); - indexingPlansPerId.put( identifier, plan ); - } - return plan; - } - - private class ContainedEntityIndexingPlan { - private final Object identifier; - private Supplier entitySupplier; - - private Boolean createdInThisPlan; - - private boolean shouldResolveToReindex; - private boolean considerAllDirty; - private Set dirtyPaths; - - private ContainedEntityIndexingPlan(Object identifier) { - this.identifier = identifier; - } - - void add(Supplier entitySupplier) { - this.entitySupplier = entitySupplier; - shouldResolveToReindex = true; - if ( createdInThisPlan == null ) { - // No update yet, so we actually did create the entity in this plan - createdInThisPlan = true; - } - } - - void update(Supplier entitySupplier) { - doUpdate( entitySupplier ); - shouldResolveToReindex = true; - considerAllDirty = true; - dirtyPaths = null; - } - - void update(Supplier entitySupplier, String... dirtyPaths) { - doUpdate( entitySupplier ); - shouldResolveToReindex = true; - if ( !considerAllDirty ) { - for ( String dirtyPath : dirtyPaths ) { - addDirtyPath( dirtyPath ); - } - } - } - - void delete(Supplier entitySupplier) { - this.entitySupplier = entitySupplier; - if ( createdInThisPlan == null ) { - // No add or update yet, and we're performing a delete, so we did not create the entity in this plan - createdInThisPlan = false; - } - else if ( createdInThisPlan ) { - /* - * We called the first add() in the same plan, so we don't expect the entity to be contained - * in existing documents. - * Cancel everything. - */ - createdInThisPlan = null; - } - - // Reindexing does not make sense for a deleted entity - shouldResolveToReindex = false; - considerAllDirty = false; - dirtyPaths = null; - } - - void resolveDirty(PojoReindexingCollector containingEntityCollector) { - if ( shouldResolveToReindex ) { - shouldResolveToReindex = false; // Avoid infinite looping - typeContext.resolveEntitiesToReindex( - containingEntityCollector, sessionContext, identifier, entitySupplier, - considerAllDirty ? null : dirtyPaths - ); - } - } - - private void doUpdate(Supplier entitySupplier) { - this.entitySupplier = entitySupplier; - if ( createdInThisPlan == null ) { - // No add yet, and we're performing an update, so we did not create the entity in this plan - createdInThisPlan = false; - } - } - - private void addDirtyPath(String dirtyPath) { - if ( dirtyPaths == null ) { - dirtyPaths = new HashSet<>(); - } - dirtyPaths.add( dirtyPath ); + class ContainedEntityState + extends AbstractPojoTypeIndexingPlan.AbstractEntityState { + private ContainedEntityState(Object identifier) { + super( identifier ); } } diff --git a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoIndexedTypeIndexingPlan.java b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoIndexedTypeIndexingPlan.java index a7b2ef1ec82..467e95cbdcf 100644 --- a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoIndexedTypeIndexingPlan.java +++ b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoIndexedTypeIndexingPlan.java @@ -7,11 +7,7 @@ package org.hibernate.search.mapper.pojo.work.impl; import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; @@ -27,14 +23,12 @@ * @param The entity type mapped to the index. * @param The type of entity references returned in the {@link #executeAndReport() failure report}. */ -public class PojoIndexedTypeIndexingPlan extends AbstractPojoTypeIndexingPlan { +public class PojoIndexedTypeIndexingPlan + extends AbstractPojoTypeIndexingPlan.IndexedEntityState> { private final PojoWorkIndexedTypeContext typeContext; private final IndexIndexingPlan delegate; - // Use a LinkedHashMap for deterministic iteration - private final Map indexingPlansPerId = new LinkedHashMap<>(); - public PojoIndexedTypeIndexingPlan(PojoWorkIndexedTypeContext typeContext, PojoWorkSessionContext sessionContext, IndexIndexingPlan delegate) { @@ -43,61 +37,41 @@ public PojoIndexedTypeIndexingPlan(PojoWorkIndexedTypeContext typeContext, this.delegate = delegate; } - @Override - void add(Object providedId, String providedRoutingKey, Object entity) { - Supplier entitySupplier = typeContext.toEntitySupplier( sessionContext, entity ); - I identifier = typeContext.identifierMapping().getIdentifier( providedId, entitySupplier ); - getPlan( identifier ).add( entitySupplier, providedRoutingKey ); - } - - @Override - void update(Object providedId, String providedRoutingKey, Object entity) { - Supplier entitySupplier = typeContext.toEntitySupplier( sessionContext, entity ); - I identifier = typeContext.identifierMapping().getIdentifier( providedId, entitySupplier ); - getPlan( identifier ).update( entitySupplier, providedRoutingKey ); - } - - @Override - void update(Object providedId, String providedRoutingKey, Object entity, String... dirtyPaths) { - Supplier entitySupplier = typeContext.toEntitySupplier( sessionContext, entity ); - I identifier = typeContext.identifierMapping().getIdentifier( providedId, entitySupplier ); - getPlan( identifier ).update( entitySupplier, providedRoutingKey, dirtyPaths ); - } - - @Override - void delete(Object providedId, String providedRoutingKey, Object entity) { - Supplier entitySupplier = typeContext.toEntitySupplier( sessionContext, entity ); - I identifier = typeContext.identifierMapping().getIdentifier( providedId, entitySupplier ); - getPlan( identifier ).delete( entitySupplier, providedRoutingKey ); - } - @Override void purge(Object providedId, String providedRoutingKey) { I identifier = typeContext.identifierMapping().getIdentifier( providedId ); - getPlan( identifier ).purge( providedRoutingKey ); + getState( identifier ).purge( providedRoutingKey ); } void updateBecauseOfContained(Object entity) { Supplier entitySupplier = typeContext.toEntitySupplier( sessionContext, entity ); I identifier = typeContext.identifierMapping().getIdentifier( null, entitySupplier ); - if ( !indexingPlansPerId.containsKey( identifier ) ) { - getPlan( identifier ).updateBecauseOfContained( entitySupplier ); + if ( !statesPerId.containsKey( identifier ) ) { + getState( identifier ).updateBecauseOfContained( entitySupplier ); } // If the entry is already there, no need for an additional update } + @Override void resolveDirty(PojoReindexingCollector containingEntityCollector) { - // We need to iterate on a "frozen snapshot" of the indexingPlansPerId values - // because of HSEARCH-3857 - List frozenIndexingPlansPerId = new ArrayList<>( indexingPlansPerId.values() ); - for ( IndexedEntityIndexingPlan plan : frozenIndexingPlansPerId ) { + // We need to iterate on a "frozen snapshot" of the states because of HSEARCH-3857 + List frozenIndexingPlansPerId = new ArrayList<>( statesPerId.values() ); + for ( IndexedEntityState plan : frozenIndexingPlansPerId ) { plan.resolveDirty( containingEntityCollector ); } } + void discard() { + delegate.discard(); + } + + void discardNotProcessed() { + this.statesPerId.clear(); + } + void process() { sendCommandsToDelegate(); - getDelegate().process(); + delegate.process(); } CompletableFuture> executeAndReport() { @@ -109,108 +83,68 @@ CompletableFuture> executeAndReport() { return delegate.executeAndReport(); } - void discard() { - delegate.discard(); - } - - void discardNotProcessed() { - this.indexingPlansPerId.clear(); + @Override + PojoWorkIndexedTypeContext typeContext() { + return typeContext; } - private IndexedEntityIndexingPlan getPlan(I identifier) { - IndexedEntityIndexingPlan plan = indexingPlansPerId.get( identifier ); - if ( plan == null ) { - plan = new IndexedEntityIndexingPlan( identifier ); - indexingPlansPerId.put( identifier, plan ); - } - return plan; + @Override + I toIdentifier(Object providedId, Supplier entitySupplier) { + return typeContext.identifierMapping().getIdentifier( providedId, entitySupplier ); } - private IndexIndexingPlan getDelegate() { - return delegate; + @Override + protected IndexedEntityState createState(I identifier) { + return new IndexedEntityState( identifier ); } private void sendCommandsToDelegate() { try { - indexingPlansPerId.values().forEach( IndexedEntityIndexingPlan::sendCommandsToDelegate ); + statesPerId.values().forEach( IndexedEntityState::sendCommandsToDelegate ); } finally { - indexingPlansPerId.clear(); + statesPerId.clear(); } } - private class IndexedEntityIndexingPlan { - private final I identifier; - private String providedRoutingKey; - private Supplier entitySupplier; + class IndexedEntityState + extends AbstractPojoTypeIndexingPlan.AbstractEntityState { - private boolean delete; - private boolean add; + private String providedRoutingKey; - private boolean shouldResolveToReindex; - private boolean considerAllDirty; private boolean updatedBecauseOfContained; - private Set dirtyPaths; - private IndexedEntityIndexingPlan(I identifier) { - this.identifier = identifier; + private IndexedEntityState(I identifier) { + super( identifier ); } + @Override void add(Supplier entitySupplier, String providedRoutingKey) { - this.entitySupplier = entitySupplier; + super.add( entitySupplier, providedRoutingKey ); this.providedRoutingKey = providedRoutingKey; - shouldResolveToReindex = true; - add = true; } - void update(Supplier entitySupplier, String providedRoutingKey) { - doUpdate( entitySupplier, providedRoutingKey ); - shouldResolveToReindex = true; - considerAllDirty = true; - dirtyPaths = null; - } - - void update(Supplier entitySupplier, String providedRoutingKey, String... dirtyPaths) { - doUpdate( entitySupplier, providedRoutingKey ); - shouldResolveToReindex = true; - if ( !considerAllDirty ) { - for ( String dirtyPropertyName : dirtyPaths ) { - addDirtyPath( dirtyPropertyName ); - } - } + @Override + void doUpdate(Supplier entitySupplier, String providedRoutingKey) { + super.doUpdate( entitySupplier, providedRoutingKey ); + this.providedRoutingKey = providedRoutingKey; } void updateBecauseOfContained(Supplier entitySupplier) { doUpdate( entitySupplier, null ); updatedBecauseOfContained = true; - /* - * We don't want contained entities that haven't been modified to trigger an update of their - * containing entities. - * Thus we don't set 'shouldResolveToReindex' to true here, but leave it as is. - */ + // We don't want contained entities that haven't been modified to trigger an update of their + // containing entities. + // Thus we don't set 'shouldResolveToReindex' to true here, but leave it as is. } + @Override void delete(Supplier entitySupplier, String providedRoutingKey) { - this.entitySupplier = entitySupplier; + super.delete( entitySupplier, providedRoutingKey ); this.providedRoutingKey = providedRoutingKey; - if ( add && !delete ) { - /* - * We called add() in the same plan, so we don't expect the document to be in the index. - * Don't delete, just cancel the addition. - */ - add = false; - delete = false; - } - else { - add = false; - delete = true; - } // Reindexing does not make sense for a deleted entity - shouldResolveToReindex = false; - considerAllDirty = false; updatedBecauseOfContained = false; - dirtyPaths = null; } void purge(String providedRoutingKey) { @@ -225,16 +159,6 @@ void purge(String providedRoutingKey) { delete = true; } - void resolveDirty(PojoReindexingCollector containingEntityCollector) { - if ( shouldResolveToReindex ) { - shouldResolveToReindex = false; // Avoid infinite looping - typeContext.resolveEntitiesToReindex( - containingEntityCollector, sessionContext, identifier, entitySupplier, - considerAllDirty ? null : dirtyPaths - ); - } - } - void sendCommandsToDelegate() { if ( add ) { if ( delete ) { @@ -252,26 +176,6 @@ else if ( delete ) { } } - private void doUpdate(Supplier entitySupplier, String providedRoutingKey) { - this.entitySupplier = entitySupplier; - this.providedRoutingKey = providedRoutingKey; - /* - * If add is true, either this is already an update (in which case we don't need to change the flags) - * or we called add() in the same plan (in which case we don't expect the document to be in the index). - */ - if ( !add ) { - delete = true; - add = true; - } - } - - private void addDirtyPath(String dirtyPath) { - if ( dirtyPaths == null ) { - dirtyPaths = new HashSet<>(); - } - dirtyPaths.add( dirtyPath ); - } - private void delegateAdd() { PojoWorkRouter router = typeContext.createRouter( sessionContext, identifier, entitySupplier ); DocumentRouteImpl currentRoute = router.currentRoute( providedRoutingKey ); diff --git a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoIndexingPlanImpl.java b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoIndexingPlanImpl.java index 942a2231fc5..a715bc10a24 100644 --- a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoIndexingPlanImpl.java +++ b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoIndexingPlanImpl.java @@ -57,31 +57,31 @@ public PojoIndexingPlanImpl(PojoWorkIndexedTypeContextProvider indexedTypeContex @Override public void add(PojoRawTypeIdentifier typeIdentifier, Object providedId, String providedRoutingKey, Object entity) { - AbstractPojoTypeIndexingPlan delegate = getDelegate( typeIdentifier ); + AbstractPojoTypeIndexingPlan delegate = getDelegate( typeIdentifier ); delegate.add( providedId, providedRoutingKey, entity ); } @Override public void addOrUpdate(PojoRawTypeIdentifier typeIdentifier, Object providedId, String providedRoutingKey, Object entity) { - AbstractPojoTypeIndexingPlan delegate = getDelegate( typeIdentifier ); + AbstractPojoTypeIndexingPlan delegate = getDelegate( typeIdentifier ); delegate.update( providedId, providedRoutingKey, entity ); } @Override public void addOrUpdate(PojoRawTypeIdentifier typeIdentifier, Object providedId, String providedRoutingKey, Object entity, String... dirtyPaths) { - AbstractPojoTypeIndexingPlan delegate = getDelegate( typeIdentifier ); + AbstractPojoTypeIndexingPlan delegate = getDelegate( typeIdentifier ); delegate.update( providedId, providedRoutingKey, entity, dirtyPaths ); } @Override public void delete(PojoRawTypeIdentifier typeIdentifier, Object providedId, String providedRoutingKey, Object entity) { - AbstractPojoTypeIndexingPlan delegate = getDelegate( typeIdentifier ); + AbstractPojoTypeIndexingPlan delegate = getDelegate( typeIdentifier ); delegate.delete( providedId, providedRoutingKey, entity ); } @Override public void purge(PojoRawTypeIdentifier typeIdentifier, Object providedId, String providedRoutingKey) { - AbstractPojoTypeIndexingPlan delegate = getDelegate( typeIdentifier ); + AbstractPojoTypeIndexingPlan delegate = getDelegate( typeIdentifier ); delegate.purge( providedId, providedRoutingKey ); } @@ -148,8 +148,8 @@ private PojoRuntimeIntrospector getIntrospector() { return introspector; } - private AbstractPojoTypeIndexingPlan getDelegate(PojoRawTypeIdentifier typeIdentifier) { - AbstractPojoTypeIndexingPlan delegate = indexedTypeDelegates.get( typeIdentifier ); + private AbstractPojoTypeIndexingPlan getDelegate(PojoRawTypeIdentifier typeIdentifier) { + AbstractPojoTypeIndexingPlan delegate = indexedTypeDelegates.get( typeIdentifier ); if ( delegate == null ) { delegate = containedTypeDelegates.get( typeIdentifier ); if ( delegate == null ) { @@ -159,7 +159,7 @@ private AbstractPojoTypeIndexingPlan getDelegate(PojoRawTypeIdentifier typeId return delegate; } - private AbstractPojoTypeIndexingPlan createDelegate(PojoRawTypeIdentifier typeIdentifier) { + private AbstractPojoTypeIndexingPlan createDelegate(PojoRawTypeIdentifier typeIdentifier) { Optional> indexedTypeContextOptional = indexedTypeContextProvider.getByExactType( typeIdentifier ); if ( indexedTypeContextOptional.isPresent() ) { diff --git a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoWorkContainedTypeContext.java b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoWorkContainedTypeContext.java index ec62169f958..00705b4928b 100644 --- a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoWorkContainedTypeContext.java +++ b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoWorkContainedTypeContext.java @@ -6,24 +6,12 @@ */ package org.hibernate.search.mapper.pojo.work.impl; -import java.util.Set; -import java.util.function.Supplier; - -import org.hibernate.search.mapper.pojo.automaticindexing.impl.PojoReindexingCollector; -import org.hibernate.search.mapper.pojo.model.spi.PojoRawTypeIdentifier; import org.hibernate.search.mapper.pojo.work.spi.PojoWorkSessionContext; /** * @param The contained entity type. */ -public interface PojoWorkContainedTypeContext { - - PojoRawTypeIdentifier typeIdentifier(); - - Supplier toEntitySupplier(PojoWorkSessionContext sessionContext, Object entity); - - void resolveEntitiesToReindex(PojoReindexingCollector collector, PojoWorkSessionContext sessionContext, - Object identifier, Supplier entitySupplier, Set dirtyPaths); +public interface PojoWorkContainedTypeContext extends PojoWorkTypeContext { PojoContainedTypeIndexingPlan createIndexingPlan(PojoWorkSessionContext sessionContext); diff --git a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoWorkIndexedTypeContext.java b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoWorkIndexedTypeContext.java index ede60c26801..1ecfc22f6ed 100644 --- a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoWorkIndexedTypeContext.java +++ b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoWorkIndexedTypeContext.java @@ -13,23 +13,17 @@ import org.hibernate.search.engine.backend.work.execution.DocumentCommitStrategy; import org.hibernate.search.engine.backend.work.execution.DocumentRefreshStrategy; import org.hibernate.search.engine.backend.work.execution.spi.IndexWorkspace; -import org.hibernate.search.mapper.pojo.automaticindexing.impl.PojoReindexingCollector; import org.hibernate.search.mapper.pojo.bridge.runtime.impl.IdentifierMappingImplementor; -import org.hibernate.search.mapper.pojo.model.spi.PojoRawTypeIdentifier; import org.hibernate.search.mapper.pojo.work.spi.PojoWorkSessionContext; /** * @param The identifier type for the mapped entity type. * @param The entity type mapped to the index. */ -public interface PojoWorkIndexedTypeContext { - - PojoRawTypeIdentifier typeIdentifier(); +public interface PojoWorkIndexedTypeContext extends PojoWorkTypeContext { IdentifierMappingImplementor identifierMapping(); - Supplier toEntitySupplier(PojoWorkSessionContext sessionContext, Object entity); - String toDocumentIdentifier(PojoWorkSessionContext sessionContext, I identifier); PojoWorkRouter createRouter(PojoWorkSessionContext sessionContext, I identifier, Supplier entitySupplier); @@ -39,9 +33,6 @@ PojoDocumentContributor toDocumentContributor(PojoWorkSessionContext sessi boolean requiresSelfReindexing(Set dirtyPaths); - void resolveEntitiesToReindex(PojoReindexingCollector collector, PojoWorkSessionContext sessionContext, - I identifier, Supplier entitySupplier, Set dirtyPaths); - PojoIndexedTypeIndexingPlan createIndexingPlan(PojoWorkSessionContext sessionContext, DocumentCommitStrategy commitStrategy, DocumentRefreshStrategy refreshStrategy); diff --git a/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoWorkTypeContext.java b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoWorkTypeContext.java new file mode 100644 index 00000000000..958e865efdf --- /dev/null +++ b/mapper/pojo-base/src/main/java/org/hibernate/search/mapper/pojo/work/impl/PojoWorkTypeContext.java @@ -0,0 +1,28 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.mapper.pojo.work.impl; + +import java.util.Set; +import java.util.function.Supplier; + +import org.hibernate.search.mapper.pojo.automaticindexing.impl.PojoReindexingCollector; +import org.hibernate.search.mapper.pojo.model.spi.PojoRawTypeIdentifier; +import org.hibernate.search.mapper.pojo.work.spi.PojoWorkSessionContext; + +/** + * @param The contained entity type. + */ +public interface PojoWorkTypeContext { + + PojoRawTypeIdentifier typeIdentifier(); + + Supplier toEntitySupplier(PojoWorkSessionContext sessionContext, Object entity); + + void resolveEntitiesToReindex(PojoReindexingCollector collector, PojoWorkSessionContext sessionContext, + Object identifier, Supplier entitySupplier, Set dirtyPaths); + +}