
org.hibernate.search.spi.impl.PolymorphicIndexHierarchy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-search-engine Show documentation
Show all versions of hibernate-search-engine Show documentation
Core of the Object/Lucene mapper, query engine and index management
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.search.spi.impl;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.hibernate.search.util.logging.impl.Log;
import org.hibernate.search.util.logging.impl.LoggerFactory;
/**
* Helper class which keeps track of all super classes and interfaces of the indexed entities.
*/
//FIXME make it immutable (builder pattern)
public class PolymorphicIndexHierarchy {
private static final Log log = LoggerFactory.make();
private Map, Set>> classToIndexedClass;
public PolymorphicIndexHierarchy() {
classToIndexedClass = new HashMap, Set>>();
}
public void addIndexedClass(Class> indexedClass) {
addClass( indexedClass, indexedClass );
Class> superClass = indexedClass.getSuperclass();
while ( superClass != null ) {
addClass( superClass, indexedClass );
superClass = superClass.getSuperclass();
}
for ( Class> clazz : indexedClass.getInterfaces() ) {
addClass( clazz, indexedClass );
}
}
private void addClass(Class> superclass, Class> indexedClass) {
Set> classesSet = classToIndexedClass.get( superclass );
if ( classesSet == null ) {
classesSet = new HashSet>();
classToIndexedClass.put( superclass, classesSet );
}
classesSet.add( indexedClass );
}
public Set> getIndexedClasses(Class>[] classes) {
if ( classes == null ) {
return Collections.>emptySet();
}
Set> indexedClasses = new HashSet>();
for ( Class> clazz : classes ) {
Set> set = classToIndexedClass.get( clazz );
if ( set != null ) {
// at this point we don't have to care about including indexed subclasses of a indexed class
// MultiClassesQueryLoader will take care of this later and optimise the queries
indexedClasses.addAll( set );
}
}
if ( log.isTraceEnabled() ) {
log.tracef( "Targeted indexed classes for %s: %s", Arrays.toString( classes ), indexedClasses );
}
return indexedClasses;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy