diff --git a/db/src/main/java/org/hibernate/search/genericjpa/db/events/UpdateConsumer.java b/db/src/main/java/org/hibernate/search/genericjpa/db/events/UpdateConsumer.java index fd61038..bb67b65 100644 --- a/db/src/main/java/org/hibernate/search/genericjpa/db/events/UpdateConsumer.java +++ b/db/src/main/java/org/hibernate/search/genericjpa/db/events/UpdateConsumer.java @@ -31,28 +31,17 @@ class UpdateEventInfo { private final Object id; private final int eventType; private final Map hints; - private final EntityProvider entityProvider; public UpdateEventInfo(Class entityClass, Object id, int eventType) { this( entityClass, id, eventType, Collections.emptyMap() ); } public UpdateEventInfo(Class entityClass, Object id, int eventType, Map hints) { - this( entityClass, id, eventType, hints, null ); - } - - public UpdateEventInfo( - Class entityClass, - Object id, - int eventType, - Map hints, - EntityProvider entityProvider) { super(); this.entityClass = entityClass; this.id = id; this.eventType = eventType; this.hints = hints; - this.entityProvider = entityProvider; } /** @@ -80,16 +69,6 @@ public Map getHints() { return hints; } - /** - * the entity provider that should be used to handle this event. this is only needed for native event access - * and is null for the trigger event system - * - * @return - */ - public EntityProvider getEntityProvider() { - return entityProvider; - } - @Override public boolean equals(Object o) { if ( this == o ) { @@ -110,12 +89,7 @@ public boolean equals(Object o) { if ( id != null ? !id.equals( that.id ) : that.id != null ) { return false; } - if ( hints != null ? !hints.equals( that.hints ) : that.hints != null ) { - return false; - } - return !(entityProvider != null ? - !entityProvider.equals( that.entityProvider ) : - that.entityProvider != null); + return !(hints != null ? !hints.equals( that.hints ) : that.hints != null); } @@ -125,7 +99,6 @@ public int hashCode() { result = 31 * result + (id != null ? id.hashCode() : 0); result = 31 * result + eventType; result = 31 * result + (hints != null ? hints.hashCode() : 0); - result = 31 * result + (entityProvider != null ? entityProvider.hashCode() : 0); return result; } @@ -136,7 +109,6 @@ public String toString() { ", id=" + id + ", eventType=" + eventType + ", hints=" + hints + - ", entityProvider=" + entityProvider + '}'; } } diff --git a/db/src/main/java/org/hibernate/search/genericjpa/db/events/index/impl/IndexUpdater.java b/db/src/main/java/org/hibernate/search/genericjpa/db/events/index/impl/IndexUpdater.java index b71f91b..4961e69 100644 --- a/db/src/main/java/org/hibernate/search/genericjpa/db/events/index/impl/IndexUpdater.java +++ b/db/src/main/java/org/hibernate/search/genericjpa/db/events/index/impl/IndexUpdater.java @@ -7,9 +7,7 @@ package org.hibernate.search.genericjpa.db.events.index.impl; import java.io.Serializable; -import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; @@ -81,26 +79,10 @@ public IndexUpdater( } public void updateEvent(List updateInfos) { - Map> perEntityProvider = new HashMap<>(); - List infoWithoutEntityProvider = new ArrayList<>(); - for ( UpdateEventInfo info : updateInfos ) { - EntityProvider entityProvider = info.getEntityProvider(); - if ( entityProvider == null ) { - infoWithoutEntityProvider.add( info ); - } - else { - perEntityProvider.computeIfAbsent( entityProvider, _1 -> new ArrayList<>() ) - .add( - info - ); - } - } - for ( Map.Entry> entry : perEntityProvider.entrySet() ) { - this.updateEvent( entry.getValue(), entry.getKey() ); - } - if ( infoWithoutEntityProvider.size() > 0 ) { - this.updateEvent( infoWithoutEntityProvider, this.entityProvider ); + if(updateInfos.size() == 0) { + return; } + this.updateEvent( updateInfos, this.entityProvider ); } public void updateEvent(List updateInfos, EntityProvider provider) { @@ -204,7 +186,7 @@ public void delete( Object id, EntityProvider entityProvider, Transaction tx) { - this.indexWrapper.delete( entityClass, inIndexOf, id, entityProvider , tx ); + this.indexWrapper.delete( entityClass, inIndexOf, id, entityProvider, tx ); } public void update(Object entity, Transaction tx) { diff --git a/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkUpdateSource.java b/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkUpdateSource.java index ab3b466..603a356 100644 --- a/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkUpdateSource.java +++ b/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkUpdateSource.java @@ -7,11 +7,13 @@ package org.hibernate.search.genericjpa.db.events.eclipselink.impl; import java.io.IOException; -import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; import java.util.logging.Logger; import org.eclipse.persistence.descriptors.DescriptorEvent; @@ -24,21 +26,16 @@ import org.eclipse.persistence.sessions.UnitOfWork; import org.hibernate.annotations.common.reflection.XProperty; -import org.hibernate.search.backend.spi.SingularTermDeletionQuery; -import org.hibernate.search.bridge.FieldBridge; -import org.hibernate.search.bridge.StringBridge; -import org.hibernate.search.engine.ProjectionConstants; -import org.hibernate.search.engine.metadata.impl.DocumentFieldMetadata; -import org.hibernate.search.genericjpa.JPASearchFactoryController; +import org.hibernate.search.genericjpa.db.EventType; +import org.hibernate.search.genericjpa.db.events.UpdateConsumer; import org.hibernate.search.genericjpa.db.events.index.impl.IndexUpdater; import org.hibernate.search.genericjpa.entity.EntityProvider; import org.hibernate.search.genericjpa.events.impl.SynchronizedUpdateSource; import org.hibernate.search.genericjpa.exception.AssertionFailure; +import org.hibernate.search.genericjpa.exception.SearchException; import org.hibernate.search.genericjpa.factory.Transaction; import org.hibernate.search.genericjpa.factory.impl.SubClassSupportInstanceInitializer; import org.hibernate.search.genericjpa.metadata.impl.RehashedTypeMetadata; -import org.hibernate.search.jpa.FullTextEntityManager; -import org.hibernate.search.jpa.FullTextQuery; import org.hibernate.search.spi.InstanceInitializer; /** @@ -59,10 +56,13 @@ public class EclipseLinkUpdateSource implements SynchronizedUpdateSource { private final Map, RehashedTypeMetadata> rehashedTypeMetadataPerIndexRoot; private final Map, List>> containedInIndexOf; + private List updateConsumers = new ArrayList<>(); + final DescriptorEventAspect descriptorEventAspect; final SessionEventAspect sessionEventAspect; private final ConcurrentHashMap transactions = new ConcurrentHashMap<>(); + private final ConcurrentHashMap> updateEventInfos = new ConcurrentHashMap<>(); public EclipseLinkUpdateSource( IndexUpdater indexUpdater, @@ -77,12 +77,48 @@ public EclipseLinkUpdateSource( this.containedInIndexOf = containedInIndexOf; } + @Override + public void setUpdateConsumers(List updateConsumers) { + this.updateConsumers = updateConsumers; + } + + private void notify(List updateEventInfos) { + if ( updateEventInfos.size() > 0 ) { + for ( UpdateConsumer updateConsumer : EclipseLinkUpdateSource.this.updateConsumers ) { + try { + updateConsumer.updateEvent( updateEventInfos ); + } + catch (Exception e) { + LOGGER.log( Level.WARNING, "Exception while notifying updateConsumers", e ); + } + } + } + } + + private Object getId(Class entityClass, Object entity) { + List> inIndexOf = EclipseLinkUpdateSource.this.containedInIndexOf.get( entityClass ); + if ( inIndexOf.size() > 0 ) { + //hack, but works + RehashedTypeMetadata metadata = EclipseLinkUpdateSource.this.rehashedTypeMetadataPerIndexRoot.get( + inIndexOf.get( 0 ) + ); + XProperty idProperty = metadata.getIdPropertyAccessorForType().get( entityClass ); + Object id = idProperty.invoke( entity ); + return id; + } + return null; + } + private class DescriptorEventAspect extends DescriptorEventAdapter { @Override public void postInsert(DescriptorEvent event) { Object entity = event.getObject(); Class entityClass = INSTANCE_INITIALIZER.getClass( entity ); + Object id = EclipseLinkUpdateSource.this.getId( entityClass, entity ); + if ( id == null ) { + throw new SearchException( "id was null for " + entity ); + } if ( EclipseLinkUpdateSource.this.indexRelevantEntities.contains( entityClass ) ) { LOGGER.fine( "Insert Event for " + entity ); Session session = event.getSession(); @@ -90,16 +126,30 @@ public void postInsert(DescriptorEvent event) { session = ((UnitOfWork) session).getParent(); } Transaction tx = EclipseLinkUpdateSource.this.transactions.get( session ); - if(tx == null) { + if ( tx == null ) { tx = new Transaction(); try { EclipseLinkUpdateSource.this.indexUpdater.index( entity, tx ); tx.commit(); - } catch(Exception e) { + EclipseLinkUpdateSource.this.notify( + Collections.singletonList( + new UpdateConsumer.UpdateEventInfo( + entityClass, id, EventType.INSERT + ) + ) + ); + } + catch (Exception e) { tx.rollback(); } - } else { + } + else { EclipseLinkUpdateSource.this.indexUpdater.index( entity, tx ); + EclipseLinkUpdateSource.this.updateEventInfos.get( tx ).add( + new UpdateConsumer.UpdateEventInfo( + entityClass, id, EventType.INSERT + ) + ); } } } @@ -108,6 +158,10 @@ public void postInsert(DescriptorEvent event) { public void postUpdate(DescriptorEvent event) { Object entity = event.getObject(); Class entityClass = INSTANCE_INITIALIZER.getClass( entity ); + Object id = EclipseLinkUpdateSource.this.getId( entityClass, entity ); + if ( id == null ) { + throw new SearchException( "id was null for " + entity ); + } if ( EclipseLinkUpdateSource.this.indexRelevantEntities.contains( entityClass ) ) { LOGGER.fine( "Update Event for " + entity ); Session session = event.getSession(); @@ -115,16 +169,30 @@ public void postUpdate(DescriptorEvent event) { session = ((UnitOfWork) session).getParent(); } Transaction tx = EclipseLinkUpdateSource.this.transactions.get( session ); - if(tx == null) { + if ( tx == null ) { tx = new Transaction(); try { EclipseLinkUpdateSource.this.indexUpdater.update( entity, tx ); tx.commit(); - } catch(Exception e) { + EclipseLinkUpdateSource.this.notify( + Collections.singletonList( + new UpdateConsumer.UpdateEventInfo( + entityClass, id, EventType.UPDATE + ) + ) + ); + } + catch (Exception e) { tx.rollback(); } - } else { + } + else { EclipseLinkUpdateSource.this.indexUpdater.update( entity, tx ); + EclipseLinkUpdateSource.this.updateEventInfos.get( tx ).add( + new UpdateConsumer.UpdateEventInfo( + entityClass, id, EventType.UPDATE + ) + ); } } } @@ -148,7 +216,8 @@ public void postDelete(DescriptorEvent event) { final Session session = tmp; Transaction tx = EclipseLinkUpdateSource.this.transactions.get( session ); boolean createdOwnTx = false; - if(tx == null) { + UpdateConsumer.UpdateEventInfo updateEventInfo = null; + if ( tx == null ) { tx = new Transaction(); createdOwnTx = true; } @@ -156,11 +225,15 @@ public void postDelete(DescriptorEvent event) { List> inIndexOf = EclipseLinkUpdateSource.this.containedInIndexOf.get( entityClass ); if ( inIndexOf.size() > 0 ) { //hack, but works - RehashedTypeMetadata metadata = EclipseLinkUpdateSource.this.rehashedTypeMetadataPerIndexRoot.get( - inIndexOf.get( 0 ) - ); + RehashedTypeMetadata metadata = EclipseLinkUpdateSource.this.rehashedTypeMetadataPerIndexRoot + .get( + inIndexOf.get( 0 ) + ); XProperty idProperty = metadata.getIdPropertyAccessorForType().get( entityClass ); Object id = idProperty.invoke( entity ); + updateEventInfo = new UpdateConsumer.UpdateEventInfo( + entityClass, id, EventType.DELETE + ); EclipseLinkUpdateSource.this.indexUpdater.delete( entityClass, inIndexOf, id, new EntityProvider() { @@ -190,11 +263,22 @@ public void close() throws IOException { }, tx ); } - if(createdOwnTx) { + if ( createdOwnTx ) { tx.commit(); + if ( updateEventInfo != null ) { + EclipseLinkUpdateSource.this.notify( Collections.singletonList( updateEventInfo ) ); + } } - } catch(Exception e) { - if(createdOwnTx) { + else { + if ( updateEventInfo != null ) { + EclipseLinkUpdateSource.this.updateEventInfos.get( tx ).add( + updateEventInfo + ); + } + } + } + catch (Exception e) { + if ( createdOwnTx ) { tx.rollback(); } throw e; @@ -216,6 +300,7 @@ public void postBeginTransaction(SessionEvent event) { else { tx = new Transaction(); EclipseLinkUpdateSource.this.transactions.put( session, tx ); + EclipseLinkUpdateSource.this.updateEventInfos.put( tx, new ArrayList<>() ); } } @@ -225,6 +310,11 @@ public void postCommitTransaction(SessionEvent event) { Transaction tx = EclipseLinkUpdateSource.this.transactions.get( session ); if ( tx != null && tx.isTransactionInProgress() ) { tx.commit(); + List updateEventInfos = EclipseLinkUpdateSource.this.updateEventInfos + .remove( + tx + ); + EclipseLinkUpdateSource.this.notify( updateEventInfos ); EclipseLinkUpdateSource.this.transactions.remove( session ); } else { @@ -240,6 +330,7 @@ public void postRollbackTransaction(SessionEvent event) { Transaction tx = EclipseLinkUpdateSource.this.transactions.get( session ); if ( tx != null && tx.isTransactionInProgress() ) { tx.rollback(); + EclipseLinkUpdateSource.this.updateEventInfos.remove( tx ); EclipseLinkUpdateSource.this.transactions.remove( session ); } else { @@ -258,6 +349,7 @@ public void postLogout(SessionEvent event) { "rolling back transaction because session logged out..." ); tx.rollback(); + EclipseLinkUpdateSource.this.updateEventInfos.remove( tx ); EclipseLinkUpdateSource.this.transactions.remove( session ); } } diff --git a/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/hibernate/impl/HibernateUpdateSource.java b/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/hibernate/impl/HibernateUpdateSource.java index 79e460f..cb2ccdc 100644 --- a/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/hibernate/impl/HibernateUpdateSource.java +++ b/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/hibernate/impl/HibernateUpdateSource.java @@ -13,7 +13,11 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.Map; +import java.util.logging.Level; import java.util.logging.Logger; import org.hibernate.HibernateException; @@ -43,7 +47,12 @@ import org.hibernate.search.engine.integration.impl.ExtendedSearchIntegrator; import org.hibernate.search.engine.spi.AbstractDocumentBuilder; import org.hibernate.search.engine.spi.EntityIndexBinding; +import org.hibernate.search.genericjpa.db.EventType; +import org.hibernate.search.genericjpa.db.events.UpdateConsumer; import org.hibernate.search.genericjpa.events.impl.SynchronizedUpdateSource; +import org.hibernate.search.genericjpa.exception.AssertionFailure; +import org.hibernate.search.genericjpa.factory.impl.SubClassSupportInstanceInitializer; +import org.hibernate.search.spi.InstanceInitializer; import org.hibernate.search.util.impl.Maps; import org.hibernate.search.util.impl.ReflectionHelper; @@ -64,8 +73,30 @@ public class HibernateUpdateSource implements SynchronizedUpdateSource, PostDele PostCollectionUpdateEventListener, FlushEventListener, Serializable { + private static final InstanceInitializer INITIALIZER = SubClassSupportInstanceInitializer.INSTANCE; + private static final Logger LOGGER = Logger.getLogger( HibernateUpdateSource.class.getName() ); + private List updateConsumers = new ArrayList<>(); + + @Override + public void setUpdateConsumers(List updateConsumers) { + this.updateConsumers = updateConsumers; + } + + private void notify(List updateEventInfos) { + if ( updateEventInfos.size() > 0 ) { + for ( UpdateConsumer updateConsumer : HibernateUpdateSource.this.updateConsumers ) { + try { + updateConsumer.updateEvent( updateEventInfos ); + } + catch (Exception e) { + LOGGER.log( Level.WARNING, "Exception while notifying updateConsumers", e ); + } + } + } + } + //only used by the FullTextIndexEventListener instance playing in the FlushEventListener role. // transient because it's not serializable (and state doesn't need to live longer than a flush). // final because its initialization should be published to other threads. @@ -191,9 +222,45 @@ protected void processWork( boolean identifierRollbackEnabled) { Work work = new Work( entity, id, workType, identifierRollbackEnabled ); final EventSourceTransactionContext transactionContext = new EventSourceTransactionContext( event.getSession() ); + transactionContext.registerSynchronization( + new Synchronization() { + @Override + public void beforeCompletion() { + + } + + @Override + public void afterCompletion(int status) { + if ( Status.STATUS_COMMITTED == status ) { + HibernateUpdateSource.this.notify( + Collections.singletonList( + new UpdateConsumer.UpdateEventInfo( + INITIALIZER.getClass( entity ), id, workTypeToEventType( workType ) + ) + ) + ); + } + } + } + ); extendedIntegrator.getWorker().performWork( work, transactionContext ); } + private static int workTypeToEventType(WorkType workType) { + switch ( workType ) { + case ADD: + case INDEX: + return EventType.INSERT; + case COLLECTION: + case UPDATE: + return EventType.UPDATE; + case DELETE: + return EventType.DELETE; + default: + throw new AssertionFailure( "unexpected WorkType:" + workType); + } + } + protected void processCollectionEvent(AbstractCollectionEvent event) { if ( disabled ) { return; diff --git a/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/jpa/impl/JPAUpdateSource.java b/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/jpa/impl/JPAUpdateSource.java index ade0956..ebbe654 100644 --- a/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/jpa/impl/JPAUpdateSource.java +++ b/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/jpa/impl/JPAUpdateSource.java @@ -25,9 +25,9 @@ import java.util.logging.Logger; import org.hibernate.search.genericjpa.db.ColumnType; +import org.hibernate.search.genericjpa.db.events.UpdateConsumer; import org.hibernate.search.genericjpa.db.events.impl.AsyncUpdateSource; import org.hibernate.search.genericjpa.db.events.impl.EventModelInfo; -import org.hibernate.search.genericjpa.db.events.UpdateConsumer; import org.hibernate.search.genericjpa.db.events.UpdateConsumer.UpdateEventInfo; import org.hibernate.search.genericjpa.exception.SearchException; import org.hibernate.search.genericjpa.jpa.util.impl.JPATransactionWrapper; diff --git a/jpa/src/main/java/org/hibernate/search/genericjpa/events/impl/SynchronizedUpdateSource.java b/jpa/src/main/java/org/hibernate/search/genericjpa/events/impl/SynchronizedUpdateSource.java index bf7e83f..9242694 100644 --- a/jpa/src/main/java/org/hibernate/search/genericjpa/events/impl/SynchronizedUpdateSource.java +++ b/jpa/src/main/java/org/hibernate/search/genericjpa/events/impl/SynchronizedUpdateSource.java @@ -6,11 +6,17 @@ */ package org.hibernate.search.genericjpa.events.impl; +import java.util.List; + +import org.hibernate.search.genericjpa.db.events.UpdateConsumer; + /** * Created by Martin on 27.07.2015. */ public interface SynchronizedUpdateSource { + void setUpdateConsumers(List updateConsumers); + void close(); } diff --git a/jpa/src/main/java/org/hibernate/search/genericjpa/impl/JPASearchFactoryAdapter.java b/jpa/src/main/java/org/hibernate/search/genericjpa/impl/JPASearchFactoryAdapter.java index c874d84..8350094 100644 --- a/jpa/src/main/java/org/hibernate/search/genericjpa/impl/JPASearchFactoryAdapter.java +++ b/jpa/src/main/java/org/hibernate/search/genericjpa/impl/JPASearchFactoryAdapter.java @@ -19,7 +19,6 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -210,6 +209,7 @@ public final void init() { if ( this.asyncUpdateSource != null ) { LOGGER.warning( "using both async updating AND synchronized updating, updates will get handled twice!" ); } + this.synchronizedUpdateSource.setUpdateConsumers( Collections.singletonList( this ) ); } } diff --git a/jpa/src/test/java/org/hibernate/search/genericjpa/test/db/events/jpa/DatabaseIntegrationTest.java b/jpa/src/test/java/org/hibernate/search/genericjpa/test/db/events/jpa/DatabaseIntegrationTest.java index 7a0c0fa..2278342 100644 --- a/jpa/src/test/java/org/hibernate/search/genericjpa/test/db/events/jpa/DatabaseIntegrationTest.java +++ b/jpa/src/test/java/org/hibernate/search/genericjpa/test/db/events/jpa/DatabaseIntegrationTest.java @@ -23,11 +23,11 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Logger; +import org.hibernate.search.genericjpa.db.events.UpdateConsumer; import org.hibernate.search.genericjpa.db.events.impl.AnnotationEventModelParser; import org.hibernate.search.genericjpa.db.events.impl.EventModelInfo; import org.hibernate.search.genericjpa.db.events.impl.EventModelParser; import org.hibernate.search.genericjpa.db.EventType; -import org.hibernate.search.genericjpa.db.events.UpdateConsumer; import org.hibernate.search.genericjpa.db.events.jpa.impl.JPAUpdateSource; import org.hibernate.search.genericjpa.db.events.triggers.MySQLTriggerSQLStringSource; import org.hibernate.search.genericjpa.db.events.triggers.TriggerSQLStringSource; diff --git a/jpa/src/test/java/org/hibernate/search/genericjpa/test/db/events/jpa/JPAUpdateSourceTest.java b/jpa/src/test/java/org/hibernate/search/genericjpa/test/db/events/jpa/JPAUpdateSourceTest.java index 4fa3d32..73582d3 100644 --- a/jpa/src/test/java/org/hibernate/search/genericjpa/test/db/events/jpa/JPAUpdateSourceTest.java +++ b/jpa/src/test/java/org/hibernate/search/genericjpa/test/db/events/jpa/JPAUpdateSourceTest.java @@ -15,11 +15,11 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import org.hibernate.search.genericjpa.db.events.UpdateConsumer; import org.hibernate.search.genericjpa.db.events.impl.AnnotationEventModelParser; import org.hibernate.search.genericjpa.db.events.impl.EventModelInfo; import org.hibernate.search.genericjpa.db.events.impl.EventModelParser; import org.hibernate.search.genericjpa.db.EventType; -import org.hibernate.search.genericjpa.db.events.UpdateConsumer; import org.hibernate.search.genericjpa.db.events.jpa.impl.JPAUpdateSource; import org.hibernate.search.genericjpa.db.events.triggers.MySQLTriggerSQLStringSource; import org.hibernate.search.genericjpa.jpa.util.impl.MultiQueryAccess; diff --git a/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeEclipseLinkAutomaticUpdatesIntegrationTest.java b/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeEclipseLinkAutomaticUpdatesIntegrationTest.java index 03ad6ca..1b5fca7 100644 --- a/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeEclipseLinkAutomaticUpdatesIntegrationTest.java +++ b/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeEclipseLinkAutomaticUpdatesIntegrationTest.java @@ -8,12 +8,14 @@ import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Properties; import org.apache.lucene.search.MatchAllDocsQuery; import org.hibernate.search.genericjpa.Constants; import org.hibernate.search.genericjpa.Setup; +import org.hibernate.search.genericjpa.db.events.UpdateConsumer; import org.hibernate.search.genericjpa.db.events.triggers.MySQLTriggerSQLStringSource; import org.hibernate.search.genericjpa.impl.JPASearchFactoryAdapter; import org.hibernate.search.genericjpa.test.jpa.AutomaticUpdatesIntegrationTest; @@ -28,6 +30,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * Created by Martin on 27.07.2015. @@ -65,6 +68,17 @@ public void testNativeEvents() { this.emf, properties ); + + final boolean[] receivedEvent = {false}; + searchFactory.addUpdateConsumer( + new UpdateConsumer() { + @Override + public void updateEvent(List updateInfo) { + receivedEvent[0] = true; + } + } + ); + try { for ( int times = 0; times < 100; ++times ) { this.em.getTransaction().begin(); @@ -271,6 +285,8 @@ MultipleColumnsIdEntity.class, new ID( ).getResultSize() ); } + + assertTrue( receivedEvent[0] ); } finally { searchFactory.close(); diff --git a/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeHibernateAutomaticUpdatesIntegrationTest.java b/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeHibernateAutomaticUpdatesIntegrationTest.java index bf28efb..57a7acf 100644 --- a/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeHibernateAutomaticUpdatesIntegrationTest.java +++ b/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeHibernateAutomaticUpdatesIntegrationTest.java @@ -8,12 +8,14 @@ import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Properties; import org.apache.lucene.search.MatchAllDocsQuery; import org.hibernate.search.genericjpa.Constants; import org.hibernate.search.genericjpa.Setup; +import org.hibernate.search.genericjpa.db.events.UpdateConsumer; import org.hibernate.search.genericjpa.db.events.triggers.MySQLTriggerSQLStringSource; import org.hibernate.search.genericjpa.impl.JPASearchFactoryAdapter; import org.hibernate.search.genericjpa.test.jpa.AutomaticUpdatesIntegrationTest; @@ -28,6 +30,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * Created by Martin on 28.07.2015. @@ -66,6 +69,17 @@ public void testNativeEvents() { this.emf, properties ); + + final boolean[] receivedEvent = {false}; + searchFactory.addUpdateConsumer( + new UpdateConsumer() { + @Override + public void updateEvent(List updateInfo) { + receivedEvent[0] = true; + } + } + ); + try { for ( int times = 0; times < 100; ++times ) { this.em.getTransaction().begin(); @@ -272,9 +286,11 @@ MultipleColumnsIdEntity.class, new ID( ).getResultSize() ); } + assertTrue( receivedEvent[0] ); } finally { searchFactory.close(); } } + }