Skip to content

Commit

Permalink
HSEARCH-3891 Expose routing key from indexingPlan#delete
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever authored and yrodiere committed Jul 20, 2020
1 parent 966b595 commit f402a08
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
Expand Up @@ -65,7 +65,8 @@ public void delete(Object entity) {

@Override
public void delete(Object providedId, Object entity) {
delegate.delete( getTypeIdentifier( entity ), providedId, entity );
// TODO HSEARCH-3891 expose the providedRoutingKey
delegate.delete( getTypeIdentifier( entity ), providedId, null, entity );
}

@Override
Expand Down
Expand Up @@ -78,7 +78,7 @@ public void onPostDelete(PostDeleteEvent event) {
// TODO Check whether deletes work with hibernate.use_identifier_rollback enabled (see HSEARCH-650)
// I think they should, but better safe than sorry
getCurrentIndexingPlan( contextProvider, event.getSession() )
.delete( typeContext.typeIdentifier(), providedId, entity );
.delete( typeContext.typeIdentifier(), providedId, null, entity );
}
}

Expand Down
Expand Up @@ -31,7 +31,7 @@ public void addOrUpdate(Object entity) {
@Override
public void delete(Object entity) {
sessionContext.currentIndexingPlan( true )
.delete( getTypeIdentifier( entity ), null, entity );
.delete( getTypeIdentifier( entity ), null, null, entity );
}

@Override
Expand Down
Expand Up @@ -22,7 +22,7 @@ abstract class AbstractPojoTypeIndexingPlan {

abstract void update(Object providedId, String providedRoutingKey, Object entity, String... dirtyPaths);

abstract void delete(Object providedId, Object entity);
abstract void delete(Object providedId, String providedRoutingKey, Object entity);

abstract void purge(Object providedId, String providedRoutingKey);

Expand Down
Expand Up @@ -55,7 +55,7 @@ void update(Object providedId, String providedRoutingKey, Object entity, String.
}

@Override
void delete(Object providedId, Object entity) {
void delete(Object providedId, String providedRoutingKey, Object entity) {
Supplier<E> entitySupplier = typeContext.toEntitySupplier( sessionContext, entity );
getPlan( providedId ).delete( entitySupplier );
}
Expand Down
Expand Up @@ -64,10 +64,10 @@ void update(Object providedId, String providedRoutingKey, Object entity, String.
}

@Override
void delete(Object providedId, Object entity) {
void delete(Object providedId, String providedRoutingKey, Object entity) {
Supplier<E> entitySupplier = typeContext.toEntitySupplier( sessionContext, entity );
I identifier = typeContext.getIdentifierMapping().getIdentifier( providedId, entitySupplier );
getPlan( identifier ).delete( entitySupplier );
getPlan( identifier ).delete( entitySupplier, providedRoutingKey );
}

@Override
Expand Down Expand Up @@ -189,9 +189,9 @@ void updateBecauseOfContained(Supplier<E> entitySupplier) {
*/
}

void delete(Supplier<E> entitySupplier) {
void delete(Supplier<E> entitySupplier, String providedRoutingKey) {
this.entitySupplier = entitySupplier;
providedRoutingKey = null;
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.
Expand Down
Expand Up @@ -74,9 +74,9 @@ public void addOrUpdate(PojoRawTypeIdentifier<?> typeIdentifier, Object provided
}

@Override
public void delete(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, Object entity) {
public void delete(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, String providedRoutingKey, Object entity) {
AbstractPojoTypeIndexingPlan delegate = getDelegate( typeIdentifier );
delegate.delete( providedId, entity );
delegate.delete( providedId, providedRoutingKey, entity );
}

@Override
Expand Down
Expand Up @@ -89,9 +89,12 @@ public interface PojoIndexingPlan<R> {
* @param 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 {@code null}, Hibernate Search will attempt to extract the ID from the entity.
* @param providedRoutingKey The routing key to route the delete request to the appropriate index shard.
* Leave {@code null} if sharding is disabled
* or to have Hibernate Search compute the value through the assigned {@link org.hibernate.search.mapper.pojo.bridge.RoutingKeyBridge}.
* @param entity The entity to delete from the index.
*/
void delete(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, Object entity);
void delete(PojoRawTypeIdentifier<?> typeIdentifier, Object providedId, String providedRoutingKey, Object entity);

/**
* Purge an entity from the index.
Expand Down

0 comments on commit f402a08

Please sign in to comment.