use of org.hibernate.search.mapper.pojo.automaticindexing.ReindexOnUpdate in project hibernate-search by hibernate.
the class PojoIndexingDependencyCollectorMonomorphicDirectValueNode method doCollectDependency.
@Override
void doCollectDependency(PojoIndexingDependencyCollectorMonomorphicDirectValueNode<?, ?> initialNodeCollectingDependency) {
ReindexOnUpdate composedReindexOnUpdate = initialNodeCollectingDependency == null ? metadata.reindexOnUpdate : initialNodeCollectingDependency.composeReindexOnUpdate(lastEntityNode(), metadata.reindexOnUpdate);
if (ReindexOnUpdate.NO.equals(composedReindexOnUpdate)) {
// Updates are ignored
return;
}
if (initialNodeCollectingDependency != null) {
PojoRawTypeModel<?> initialType = initialNodeCollectingDependency.modelPathFromLastTypeNode.getRootType().rawType();
PojoModelPathValueNode initialValuePath = initialNodeCollectingDependency.unboundModelPathFromLastTypeNode;
PojoRawTypeModel<?> latestType = modelPathFromLastTypeNode.getRootType().rawType();
PojoModelPathValueNode latestValuePath = unboundModelPathFromLastTypeNode;
if (initialType.equals(latestType) && initialValuePath.equals(latestValuePath)) {
/*
* We found a cycle in the derived from dependencies.
* This can happen for example if:
* - property "foo" on type A is marked as derived from itself
* - property "foo" on type A is marked as derived from property "bar" on type B,
* which is marked as derived from property "foo" on type "A".
* Even if such a dependency might work in practice at runtime,
* for example because the link A => B never leads to a B that refers to the same A,
* even indirectly,
* we cannot support it here because we need to model dependencies as a static tree,
* which in such case would have an infinite depth.
*/
throw log.infiniteRecursionForDerivedFrom(latestType, latestValuePath);
}
} else {
initialNodeCollectingDependency = this;
}
if (metadata.derivedFrom.isEmpty()) {
parentNode.parentNode().collectDependency(this.modelPathFromLastEntityNode);
} else {
/*
* The value represented by this node is derived from other, base values.
* If we rely on the value represented by this node when indexing,
* then we indirectly rely on these base values.
*
* We don't just call lastEntityNode.collectDependency() for each path to the base values,
* because the paths may cross the entity boundaries, meaning they may have a prefix
* leading to a different entity, and a suffix leading to the value we rely on.
* This means we must go through the dependency collector tree to properly resolve
* the entities that should trigger reindexing of our root entity when they change.
*/
PojoIndexingDependencyCollectorTypeNode<?> lastTypeNode = parentNode.parentNode();
for (PojoModelPathValueNode path : metadata.derivedFrom) {
PojoModelPathBinder.bind(lastTypeNode, path, PojoIndexingDependencyCollectorNode.walker(initialNodeCollectingDependency));
}
}
}
use of org.hibernate.search.mapper.pojo.automaticindexing.ReindexOnUpdate in project hibernate-search by hibernate.
the class PojoImplicitReindexingResolverBuildingHelper method getMetadataReindexOnUpdateOrNull.
ReindexOnUpdate getMetadataReindexOnUpdateOrNull(PojoTypeModel<?> typeModel, String propertyName, ContainerExtractorPath extractorPath) {
PojoTypeAdditionalMetadata typeAdditionalMetadata = typeAdditionalMetadataProvider.get(typeModel.rawType());
Optional<ReindexOnUpdate> reindexOnUpdateOptional = typeAdditionalMetadata.getPropertyAdditionalMetadata(propertyName).getValueAdditionalMetadata(extractorPath).getReindexOnUpdate();
if (reindexOnUpdateOptional.isPresent()) {
return reindexOnUpdateOptional.get();
}
if (extractorBinder.isDefaultExtractorPath(typeModel.property(propertyName).typeModel(), extractorPath)) {
reindexOnUpdateOptional = typeAdditionalMetadata.getPropertyAdditionalMetadata(propertyName).getValueAdditionalMetadata(ContainerExtractorPath.defaultExtractors()).getReindexOnUpdate();
}
return reindexOnUpdateOptional.orElse(null);
}
use of org.hibernate.search.mapper.pojo.automaticindexing.ReindexOnUpdate in project hibernate-search by hibernate.
the class IndexingDependencyProcessor method process.
@Override
public void process(PropertyMappingStep mappingContext, IndexingDependency annotation, PropertyMappingAnnotationProcessorContext context) {
ContainerExtractorPath extractorPath = context.toContainerExtractorPath(annotation.extraction());
ReindexOnUpdate reindexOnUpdate = annotation.reindexOnUpdate();
IndexingDependencyOptionsStep indexingDependencyContext = mappingContext.indexingDependency().extractors(extractorPath);
indexingDependencyContext.reindexOnUpdate(reindexOnUpdate);
ObjectPath[] derivedFromAnnotations = annotation.derivedFrom();
if (derivedFromAnnotations.length > 0) {
for (ObjectPath objectPath : annotation.derivedFrom()) {
Optional<PojoModelPathValueNode> pojoModelPathOptional = context.toPojoModelPathValueNode(objectPath);
if (!pojoModelPathOptional.isPresent()) {
throw log.missingPathInIndexingDependencyDerivedFrom();
}
indexingDependencyContext.derivedFrom(pojoModelPathOptional.get());
}
}
}
Aggregations