/** * Adds the needed LuceneWork to the queue for this entity instance * * @param tenantIdentifier the tenant identifier * @param typeIdentifier the type * @param indexingId identifier of the instance * @param entityBuilder the DocumentBuilder for this type * @param luceneQueue the queue collecting all changes */ public void enqueueLuceneWork(String tenantIdentifier, IndexedTypeIdentifier typeIdentifier, Serializable indexingId, AbstractDocumentBuilder entityBuilder, List<LuceneWork> luceneQueue, ConversionContext conversionContext) { if ( add || delete ) { entityBuilder.addWorkToQueue( tenantIdentifier, typeIdentifier, entity, indexingId, delete, add, luceneQueue, conversionContext ); } }
/** * If we have a work instance we have to check whether the instance to be indexed is contained in any other indexed entities. * * @see #appendContainedInWorkForInstance(Object, WorkPlan, ContainedInRecursionContext, String) * @param instance the instance to be indexed * @param workPlan the current work plan * @param currentRecursionContext the current {@link org.hibernate.search.engine.spi.ContainedInRecursionContext} object used to check the graph traversal */ public void appendContainedInWorkForInstance(Object instance, WorkPlan workPlan, ContainedInRecursionContext currentRecursionContext) { appendContainedInWorkForInstance( instance, workPlan, currentRecursionContext, null ); }
/** * We need to make a difference on which value is used as identifier * according to use case and mapping options * * @param work The work instance from which to extract the id * * @return the appropriate id to use for this work */ private Serializable extractProperId(Work work) { // see HSEARCH-662 if ( containedInOnly ) { return work.getId(); } Object entity = work.getEntity(); // 1) entity is null for purge operation, which requires to trust the work id // 2) types mapped as provided id require to use the work id // 3) when Hibernate identifier rollback is used && this identifier is our same id source, we need to get the value from work id if ( entity == null || documentBuilder.requiresProvidedId() || ( work.isIdentifierWasRolledBack() && documentBuilder.isIdMatchingJpaId() ) ) { return work.getId(); } else { return documentBuilder.getId( entity ); } }
Object unproxiedInstance = instanceInitializer.unproxy( instance ); ContainedInRecursionContext recursionContext = updateContainedInRecursionContext( unproxiedInstance, containedInMetadata, currentRecursionContext ); Object[] array = (Object[]) value; for ( Object arrayValue : array ) { processSingleContainedInInstance( workPlan, arrayValue, recursionContext, tenantIdentifier ); Collection<?> collection = null; try { collection = getActualCollection( member, value ); processSingleContainedInInstance( workPlan, collectionValue, recursionContext, tenantIdentifier ); processSingleContainedInInstance( workPlan, value, recursionContext, tenantIdentifier );
if ( documentBuilder.requiresProvidedId() ) { log.containedInPointsToProvidedId( instanceInitializer.getClass( value ) ); Serializable extractedId = documentBuilder.getId( value ); if ( extractedId != null ) { PerEntityWork entityWork = entityById.get( extractedId ); documentBuilder.appendContainedInWorkForInstance( value, WorkPlan.this, context ); documentBuilder.appendContainedInWorkForInstance( value, WorkPlan.this, context );
return true; // it appears some collection work has no oldState -> reindex if ( !stateInspectionOptimizationsEnabled() ) { return true;
protected void processCollectionEvent(AbstractCollectionEvent event) { if ( state.eventsDisabled() ) { return; } Object entity = event.getAffectedOwnerOrNull(); if ( entity == null ) { //Hibernate cannot determine every single time the owner especially in case detached objects are involved // or property-ref is used //Should log really but we don't know if we're interested in this collection for indexing return; } PersistentCollection persistentCollection = event.getCollection(); final String collectionRole; if ( persistentCollection != null ) { collectionRole = persistentCollection.getRole(); } else { collectionRole = null; } AbstractDocumentBuilder documentBuilder = getDocumentBuilder( entity ); if ( documentBuilder != null && documentBuilder.collectionChangeRequiresIndexUpdate( collectionRole ) ) { Serializable id = getId( entity, event ); if ( id == null ) { log.idCannotBeExtracted( event.getAffectedOwnerEntityName() ); return; } processWork( tenantIdentifier( event ), entity, id, WorkType.COLLECTION, event, false ); } }
/** * We need to make a difference on which value is used as identifier * according to use case and mapping options * * @param work The work instance from which to extract the id * * @return the appropriate id to use for this work */ private Serializable extractProperId(Work work) { // see HSEARCH-662 if ( containedInOnly ) { return work.getId(); } Object entity = work.getEntity(); // 1) entity is null for purge operation, which requires to trust the work id // 2) types mapped as provided id require to use the work id // 3) when Hibernate identifier rollback is used && this identifier is our same id source, we need to get the value from work id if ( entity == null || documentBuilder.requiresProvidedId() || ( work.isIdentifierWasRolledBack() && documentBuilder.isIdMatchingJpaId() ) ) { return work.getId(); } else { return documentBuilder.getId( entity ); } }
Object unproxiedInstance = instanceInitializer.unproxy( instance ); ContainedInRecursionContext recursionContext = updateContainedInRecursionContext( unproxiedInstance, containedInMetadata, currentRecursionContext ); Object[] array = (Object[]) value; for ( Object arrayValue : array ) { processSingleContainedInInstance( workPlan, arrayValue, recursionContext, tenantIdentifier ); Collection<?> collection = null; try { collection = getActualCollection( member, value ); processSingleContainedInInstance( workPlan, collectionValue, recursionContext, tenantIdentifier ); processSingleContainedInInstance( workPlan, value, recursionContext, tenantIdentifier );
if ( documentBuilder.requiresProvidedId() ) { log.containedInPointsToProvidedId( instanceInitializer.getClass( value ) ); Serializable extractedId = documentBuilder.getId( value ); if ( extractedId != null ) { PerEntityWork entityWork = entityById.get( extractedId ); documentBuilder.appendContainedInWorkForInstance( value, WorkPlan.this, context ); documentBuilder.appendContainedInWorkForInstance( value, WorkPlan.this, context );
return true; // it appears some collection work has no oldState -> reindex if ( !stateInspectionOptimizationsEnabled() ) { return true;
/** * If we have a work instance we have to check whether the instance to be indexed is contained in any other indexed entities. * * @see #appendContainedInWorkForInstance(Object, WorkPlan, ContainedInRecursionContext, String) * @param instance the instance to be indexed * @param workPlan the current work plan * @param currentRecursionContext the current {@link org.hibernate.search.engine.spi.ContainedInRecursionContext} object used to check the graph traversal */ public void appendContainedInWorkForInstance(Object instance, WorkPlan workPlan, ContainedInRecursionContext currentRecursionContext) { appendContainedInWorkForInstance( instance, workPlan, currentRecursionContext, null ); }
/** * Adds the needed LuceneWork to the queue for this entity instance * * @param tenantIdentifier the tenant identifier * @param typeIdentifier the type * @param indexingId identifier of the instance * @param entityBuilder the DocumentBuilder for this type * @param luceneQueue the queue collecting all changes */ public void enqueueLuceneWork(String tenantIdentifier, IndexedTypeIdentifier typeIdentifier, Serializable indexingId, AbstractDocumentBuilder entityBuilder, List<LuceneWork> luceneQueue, ConversionContext conversionContext) { if ( add || delete ) { entityBuilder.addWorkToQueue( tenantIdentifier, typeIdentifier, entity, indexingId, delete, add, luceneQueue, conversionContext ); } }
/** * Works via recursion passing the WorkPlan over, so that additional work can be planned * according to the needs of ContainedIn processing. * * @param entityBuilder the DocumentBuilder for this type * @param workplan the current WorkPlan, used for recursion * * @see org.hibernate.search.annotations.ContainedIn */ public void processContainedIn(AbstractDocumentBuilder entityBuilder, WorkPlan workplan) { if ( entity != null && !containedInProcessed ) { containedInProcessed = true; if ( add || delete ) { entityBuilder.appendContainedInWorkForInstance( entity, workplan, null, getTenantIdentifier() ); } } }
/** * Works via recursion passing the WorkPlan over, so that additional work can be planned * according to the needs of ContainedIn processing. * * @param entityBuilder the DocumentBuilder for this type * @param workplan the current WorkPlan, used for recursion * * @see org.hibernate.search.annotations.ContainedIn */ public void processContainedIn(AbstractDocumentBuilder entityBuilder, WorkPlan workplan) { if ( entity != null && !containedInProcessed ) { containedInProcessed = true; if ( add || delete ) { entityBuilder.appendContainedInWorkForInstance( entity, workplan, null, getTenantIdentifier() ); } } }