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

org.hibernate.search.cfg.EntityDescriptor Maven / Gradle / Ivy

There is a newer version: 9.1.7.Final
Show newest version
/*
 * 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.cfg;

import java.lang.annotation.ElementType;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import org.hibernate.search.exception.SearchException;
import org.hibernate.search.annotations.ClassBridge;
import org.hibernate.search.bridge.FieldBridge;

/**
 * @author Emmanuel Bernard
 */
public class EntityDescriptor {
	private Map indexed;
	private final Map properties = new HashMap();
	private Map boost;
	private Map analyzerDiscriminator;
	private final Set> fullTextFilterDefs = new HashSet>();
	private Map providedId;

	/**
	 * Configured class bridges. Each bridge is represented by a map with {@code @ClassBridge} annotation member values
	 * keyed by annotation member name.
	 */
	private final Set> classBridges = new HashSet>();

	/**
	 * Class bridge instances and their configuration
	 */
	private final Map> classBridgeInstanceDefs = new IdentityHashMap>();

	/**
	 * Class bridge instances and their configuration in form of a {@code ClassBridge} annotation
	 */
	private final Map classBridgeConfigurations = new IdentityHashMap();
	private final Set> spatials = new HashSet>();
	private Map dynamicBoost;
	private Map cacheInMemory;

	public Map getIndexed() {
		return indexed;
	}

	public void setIndexed(Map indexed) {
		this.indexed = indexed;
	}

	PropertyDescriptor getProperty(String name, ElementType type) {
		PropertyKey propertyKey = new PropertyKey( name, type );
		PropertyDescriptor descriptor = properties.get( propertyKey );
		if ( descriptor == null ) {
			descriptor = new PropertyDescriptor( name, type );
			properties.put( propertyKey, descriptor );
		}
		return descriptor;
	}

	public PropertyDescriptor getPropertyDescriptor(String name, ElementType type) {
		return properties.get( new PropertyKey( name, type ) );
	}

	public Map getCacheInMemory() {
		return cacheInMemory;
	}

	public void setCacheInMemory(Map cacheInMemory) {
		this.cacheInMemory = cacheInMemory;
	}

	public void setBoost(Map boost) {
		this.boost = boost;
	}

	public Map getBoost() {
		return boost;
	}

	public void setAnalyzerDiscriminator(Map analyzerDiscriminator) {
		this.analyzerDiscriminator = analyzerDiscriminator;
	}

	public Map getAnalyzerDiscriminator() {
		return analyzerDiscriminator;
	}

	public Set> getFullTextFilterDefs() {
		return fullTextFilterDefs;
	}

	public void addFulltextFilterDef(Map fullTextFilterDef) {
		fullTextFilterDefs.add( fullTextFilterDef );
	}

	public void addClassBridgeDef(Map classBridge) {
		classBridges.add( classBridge );
	}

	public void addClassBridgeInstanceDef(FieldBridge classBridge, Map properties) {
		Map previous = classBridgeInstanceDefs.put( classBridge, properties );

		if ( previous != null ) {
			throw new SearchException( "The same field bridge instance must not be passed more than once." );
		}
	}

	public Set> getClassBridgeDefs() {
		return classBridges;
	}

	public Map> getClassBridgeInstanceDefs() {
		return classBridgeInstanceDefs;
	}

	public void addClassBridgeInstanceConfiguration(FieldBridge classBridge, ClassBridge configuration) {
		classBridgeConfigurations.put( classBridge, configuration );
	}

	public Map getClassBridgeConfigurations() {
		return classBridgeConfigurations;
	}

	public void addSpatial(Map spatial) {
		spatials.add( spatial );
	}

	public Set> getSpatials() {
		return spatials;
	}

	public void setProvidedId(Map providedId) {
		this.providedId = providedId;
	}

	public Map getProvidedId() {
		return this.providedId;
	}

	public void setDynamicBoost(Map dynamicEntityBoost) {
		this.dynamicBoost = dynamicEntityBoost;
	}

	public Map getDynamicBoost() {
		return this.dynamicBoost;
	}

	private static class PropertyKey {
		private final String name;
		private final ElementType type;

		PropertyKey(String name, ElementType type) {
			this.name = name;
			this.type = type;
		}

		@Override
		public boolean equals(Object o) {
			if ( this == o ) {
				return true;
			}
			if ( o == null || getClass() != o.getClass() ) {
				return false;
			}

			PropertyKey property = (PropertyKey) o;

			if ( name != null ? !name.equals( property.name ) : property.name != null ) {
				return false;
			}
			if ( type != property.type ) {
				return false;
			}

			return true;
		}

		@Override
		public int hashCode() {
			int result = name != null ? name.hashCode() : 0;
			result = 31 * result + ( type != null ? type.hashCode() : 0 );
			return result;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy