All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.search.scope.impl.V5MigrationOrmSearchScopeAdapter Maven / Gradle / Ivy

Go to download

Helper to migrate from Hibernate Search 5 to 6, providing partial support for Hibernate Search 5 ORM APIs on top of Hibernate Search 6

The newest version!
/*
 * SPDX-License-Identifier: Apache-2.0
 * Copyright Red Hat Inc. and Hibernate Authors
 */
package org.hibernate.search.scope.impl;

import java.util.Set;
import java.util.stream.Collectors;

import org.hibernate.search.engine.backend.index.IndexManager;
import org.hibernate.search.engine.common.EntityReference;
import org.hibernate.search.engine.search.aggregation.dsl.SearchAggregationFactory;
import org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory;
import org.hibernate.search.engine.search.projection.SearchProjection;
import org.hibernate.search.engine.search.projection.dsl.SearchProjectionFactory;
import org.hibernate.search.engine.search.sort.dsl.SearchSortFactory;
import org.hibernate.search.mapper.orm.entity.SearchIndexedEntity;
import org.hibernate.search.mapper.orm.scope.SearchScope;
import org.hibernate.search.scope.spi.V5MigrationSearchScope;

public class V5MigrationOrmSearchScopeAdapter implements V5MigrationSearchScope {

	private final SearchScope delegate;

	public V5MigrationOrmSearchScopeAdapter(SearchScope delegate) {
		this.delegate = delegate;
	}

	@Override
	public Set> targetTypes() {
		return delegate.includedTypes().stream().map( SearchIndexedEntity::javaClass ).collect( Collectors.toSet() );
	}

	@Override
	public Set indexManagers() {
		return delegate.includedTypes().stream().map( SearchIndexedEntity::indexManager ).collect( Collectors.toSet() );
	}

	@Override
	public SearchPredicateFactory predicate() {
		return delegate.predicate();
	}

	@Override
	public SearchSortFactory sort() {
		return delegate.sort();
	}

	@Override
	public SearchProjectionFactory projection() {
		return delegate.projection();
	}

	@Override
	public SearchProjection idProjection() {
		SearchProjectionFactory factory = delegate.projection();
		// Not using factory.id() because that one throws an exception if IDs have inconsistent types.
		return factory.composite().from( factory.entityReference() )
				.as( EntityReference::id ).toProjection();
	}

	@Override
	public SearchProjection> objectClassProjection() {
		SearchProjectionFactory factory = delegate.projection();
		return factory.composite().from( factory.entityReference() )
				.as( EntityReference::type ).toProjection();
	}

	@Override
	public SearchAggregationFactory aggregation() {
		return delegate.aggregation();
	}

	public SearchScope toSearchScope() {
		return delegate;
	}
}