Skip to content

Commit

Permalink
HSEARCH-4843 Remove generics from EntityReferenceFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed May 1, 2023
1 parent 896e56f commit db77c8e
Show file tree
Hide file tree
Showing 21 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ElasticsearchIndexIndexingPlan implements IndexIndexingPlan {
private final ElasticsearchWorkFactory workFactory;
private final ElasticsearchSerialWorkOrchestrator orchestrator;
private final WorkExecutionIndexManagerContext indexManagerContext;
private final EntityReferenceFactory<?> entityReferenceFactory;
private final EntityReferenceFactory entityReferenceFactory;
private final String tenantId;
private final DocumentRefreshStrategy refreshStrategy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
class ElasticsearchIndexIndexingPlanExecution {

private final ElasticsearchSerialWorkOrchestrator orchestrator;
private final EntityReferenceFactory<?> entityReferenceFactory;
private final EntityReferenceFactory entityReferenceFactory;

private final List<SingleDocumentIndexingWork> works;
private final CompletableFuture<Void>[] futures;

@SuppressWarnings("unchecked")
ElasticsearchIndexIndexingPlanExecution(ElasticsearchSerialWorkOrchestrator orchestrator,
EntityReferenceFactory<?> entityReferenceFactory,
EntityReferenceFactory entityReferenceFactory,
List<SingleDocumentIndexingWork> works) {
this.orchestrator = orchestrator;
this.entityReferenceFactory = entityReferenceFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ElasticsearchIndexIndexingPlanExecutionTest {
private ElasticsearchSerialWorkOrchestrator orchestratorMock;

@Mock(strictness = Mock.Strictness.LENIENT)
private EntityReferenceFactory<StubEntityReference> entityReferenceFactoryMock;
private EntityReferenceFactory entityReferenceFactoryMock;

private final List<SingleDocumentIndexingWork> workMocks = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class LuceneIndexIndexingPlan implements IndexIndexingPlan {
private final LuceneWorkFactory factory;
private final LuceneIndexEntryFactory indexEntryFactory;
private final WorkExecutionIndexManagerContext indexManagerContext;
private final EntityReferenceFactory<?> entityReferenceFactory;
private final EntityReferenceFactory entityReferenceFactory;
private final String tenantId;
private final DocumentCommitStrategy commitStrategy;
private final DocumentRefreshStrategy refreshStrategy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class LuceneIndexIndexingPlanExecution {

private final LuceneSerialWorkOrchestrator orchestrator;
private final EntityReferenceFactory<?> entityReferenceFactory;
private final EntityReferenceFactory entityReferenceFactory;
private final DocumentCommitStrategy commitStrategy;
private final DocumentRefreshStrategy refreshStrategy;

Expand All @@ -33,7 +33,7 @@ class LuceneIndexIndexingPlanExecution {

@SuppressWarnings("unchecked")
LuceneIndexIndexingPlanExecution(LuceneSerialWorkOrchestrator orchestrator,
EntityReferenceFactory<?> entityReferenceFactory,
EntityReferenceFactory entityReferenceFactory,
DocumentCommitStrategy commitStrategy,
DocumentRefreshStrategy refreshStrategy,
List<SingleDocumentIndexingWork> works) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static Object[][] params() {
private LuceneSerialWorkOrchestrator orchestratorMock;

@Mock(strictness = Mock.Strictness.LENIENT)
private EntityReferenceFactory<EntityReference> entityReferenceFactoryMock;
private EntityReferenceFactory entityReferenceFactoryMock;

private final List<SingleDocumentIndexingWork> workMocks = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

import org.hibernate.search.engine.common.EntityReference;

public interface EntityReferenceFactory<R extends EntityReference> {
public interface EntityReferenceFactory {

/**
* @param typeName The name of the entity type.
* @param identifier The identifier of the entity.
* @return A reference to the entity.
* @throws RuntimeException If something goes wrong (exception while rendering an identifier, ...)
*/
R createEntityReference(String typeName, Object identifier);
EntityReference createEntityReference(String typeName, Object identifier);

/**
* @param factory The factory for entity references.
Expand All @@ -28,9 +28,8 @@ public interface EntityReferenceFactory<R extends EntityReference> {
* Any exception thrown while creating the entity reference should be {@link Consumer#accept(Object) put into}
* that sink and should not be propagated.
* @return A reference to the entity, or null if an exception was thrown while creating the entity reference.
* @param <R> The type of entity reference.
*/
static <R extends EntityReference> R safeCreateEntityReference(EntityReferenceFactory<R> factory, String typeName, Object identifier,
static EntityReference safeCreateEntityReference(EntityReferenceFactory factory, String typeName, Object identifier,
Consumer<Exception> exceptionSink) {
try {
return factory.createEntityReference( typeName, identifier );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Builder failingEntityReference(EntityReference reference) {
return this;
}

public Builder failingEntityReference(EntityReferenceFactory<?> referenceFactory,
public Builder failingEntityReference(EntityReferenceFactory referenceFactory,
String typeName, Object entityIdentifier) {
EntityReference reference = EntityReferenceFactory.safeCreateEntityReference( referenceFactory,
typeName, entityIdentifier, this::throwable );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public interface BackendMappingContext {
/**
* @return A {@link EntityReferenceFactory}.
*/
EntityReferenceFactory<?> entityReferenceFactory();
EntityReferenceFactory entityReferenceFactory();

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class OutboxEventProcessingPlan {

private final AutomaticIndexingQueueEventProcessingPlan processingPlan;
private final FailureHandler failureHandler;
private final EntityReferenceFactory<?> entityReferenceFactory;
private final EntityReferenceFactory entityReferenceFactory;
private final List<OutboxEvent> failedEvents = new ArrayList<>();

private List<OutboxEvent> events = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public final class OutboxPollingOutboxEventSendingPlan implements AutomaticIndex
// otherwise existing indexes will no longer work correctly.
private static final RangeCompatibleHashFunction HASH_FUNCTION = ShardAssignment.HASH_FUNCTION;

private final EntityReferenceFactory<?> entityReferenceFactory;
private final EntityReferenceFactory entityReferenceFactory;
private final Session session;
private final List<OutboxEvent> events = new ArrayList<>();

public OutboxPollingOutboxEventSendingPlan(EntityReferenceFactory<?> entityReferenceFactory,
public OutboxPollingOutboxEventSendingPlan(EntityReferenceFactory entityReferenceFactory,
Session session) {
this.entityReferenceFactory = entityReferenceFactory;
this.session = session;
Expand Down Expand Up @@ -79,8 +79,8 @@ public CompletableFuture<MultiEntityOperationExecutionReport> sendAndReport(Oper
}
}

private <R> CompletableFuture<MultiEntityOperationExecutionReport> sendAndReportOnSession(
Session currentSession, EntityReferenceFactory<? extends R> entityReferenceFactory) {
private CompletableFuture<MultiEntityOperationExecutionReport> sendAndReportOnSession(
Session currentSession, EntityReferenceFactory entityReferenceFactory) {
try {
MultiEntityOperationExecutionReport.Builder builder = MultiEntityOperationExecutionReport.builder();
for ( OutboxEvent event : events ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public interface AutomaticIndexingEventSendingSessionContext {

EntityReferenceFactory<?> entityReferenceFactory();
EntityReferenceFactory entityReferenceFactory();

Session session();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public interface AutomaticIndexingMappingContext {
*/
AutomaticIndexingQueueEventProcessingPlan createIndexingQueueEventProcessingPlan(Session session);

EntityReferenceFactory<?> entityReferenceFactory();
EntityReferenceFactory entityReferenceFactory();

}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public SessionImplementor session() {
}

@Override
public EntityReferenceFactory<?> entityReferenceFactory() {
public EntityReferenceFactory entityReferenceFactory() {
return mappingContext.entityReferenceFactory();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public final void resolveEntitiesToReindex(PojoReindexingCollector collector, Po
reindexingResolver.resolveEntitiesToReindex( collector, entitySupplier.get(), context );
}
catch (RuntimeException e) {
EntityReferenceFactory<?> entityReferenceFactory = sessionContext.mappingContext().entityReferenceFactory();
EntityReferenceFactory entityReferenceFactory = sessionContext.mappingContext().entityReferenceFactory();
EntityReference entityReference = EntityReferenceFactory.safeCreateEntityReference(
entityReferenceFactory, entityName, identifier, e::addSuppressed );
throw log.errorResolvingEntitiesToReindex( entityReference, e.getMessage(), e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.hibernate.search.mapper.pojo.common.spi.PojoEntityReferenceFactoryDelegate;
import org.hibernate.search.mapper.pojo.work.impl.PojoWorkTypeContext;

final class PojoEntityReferenceFactory implements EntityReferenceFactory<EntityReference> {
final class PojoEntityReferenceFactory implements EntityReferenceFactory {

public final PojoEntityReferenceFactoryDelegate delegate;
private final PojoTypeManagerContainer typeManagers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class AbstractPojoMappingImplementor<M>
private boolean stopped = false;

private final PojoEntityReferenceFactoryDelegate entityReferenceFactoryDelegate;
private final EntityReferenceFactory<?> entityReferenceFactory;
private final EntityReferenceFactory entityReferenceFactory;
private final ToDocumentValueConvertContext toDocumentValueConvertContext;
private final IdentifierBridgeToDocumentIdentifierContext toDocumentIdentifierContext;
private final ValueBridgeToIndexedValueContext toIndexedValueContext;
Expand Down Expand Up @@ -115,7 +115,7 @@ public final PojoEntityReferenceFactoryDelegate entityReferenceFactoryDelegate()
}

@Override
public final EntityReferenceFactory<?> entityReferenceFactory() {
public final EntityReferenceFactory entityReferenceFactory() {
return entityReferenceFactory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface PojoMappingDelegate extends AutoCloseable {

ProjectionRegistry projectionRegistry();

EntityReferenceFactory<?> createEntityReferenceFactory(PojoEntityReferenceFactoryDelegate delegate);
EntityReferenceFactory createEntityReferenceFactory(PojoEntityReferenceFactoryDelegate delegate);

<R extends EntityReference, E, C> PojoScopeDelegate<R, E, C> createPojoScope(
PojoScopeMappingContext mappingContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void resolveDirty(PojoLoadingPlanProvider loadingPlanProvider, PojoReindexingCol
typeContext().reindexingResolver().resolveEntitiesToReindex( collector, entitySupplier.get(), this );
}
catch (RuntimeException e) {
EntityReferenceFactory<?> entityReferenceFactory = sessionContext.mappingContext().entityReferenceFactory();
EntityReferenceFactory entityReferenceFactory = sessionContext.mappingContext().entityReferenceFactory();
EntityReference entityReference = EntityReferenceFactory.safeCreateEntityReference(
entityReferenceFactory, typeContext().entityName(), identifier, e::addSuppressed );
throw log.errorResolvingEntitiesToReindex( entityReference, e.getMessage(), e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void contribute(DocumentElement state) {
processor.process( state, entitySupplier.get(), processorContext );
}
catch (RuntimeException e) {
EntityReferenceFactory<?> entityReferenceFactory = sessionContext.mappingContext().entityReferenceFactory();
EntityReferenceFactory entityReferenceFactory = sessionContext.mappingContext().entityReferenceFactory();
EntityReference entityReference = EntityReferenceFactory.safeCreateEntityReference(
entityReferenceFactory, entityName, identifier, e::addSuppressed );
throw log.errorBuildingDocument( entityReference, e.getMessage(), e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.hibernate.search.util.common.impl.Futures;

public class StubMappingImpl
implements StubMapping, MappingImplementor<StubMappingImpl>, EntityReferenceFactory<StubEntityReference> {
implements StubMapping, MappingImplementor<StubMappingImpl>, EntityReferenceFactory {

private final Map<String, StubMappedIndex> mappedIndexesByTypeIdentifier;
private final StubMappingSchemaManagementStrategy schemaManagementStrategy;
Expand Down Expand Up @@ -65,7 +65,7 @@ public ProjectionMappedTypeContext mappedTypeContext(String mappedTypeName) {
}

@Override
public EntityReferenceFactory<?> entityReferenceFactory() {
public EntityReferenceFactory entityReferenceFactory() {
return this;
}

Expand Down

0 comments on commit db77c8e

Please sign in to comment.