FileDocCategorySizeDatePackage
FilterImpl.javaAPI DocHibernate 3.2.54895Mon Dec 05 16:37:00 GMT 2005org.hibernate.impl

FilterImpl

public class FilterImpl extends Object implements Serializable, org.hibernate.Filter
Implementation of FilterImpl. FilterImpl implements the user's view into enabled dynamic filters, allowing them to set filter parameter values.
author
Steve Ebersole

Fields Summary
public static final String
MARKER
private transient org.hibernate.engine.FilterDefinition
definition
private String
filterName
private Map
parameters
Constructors Summary
public FilterImpl(org.hibernate.engine.FilterDefinition configuration)
Constructs a new FilterImpl.

param
configuration The filter's global configuration.

		this.definition = configuration;
		filterName = definition.getFilterName();
	
Methods Summary
voidafterDeserialize(SessionFactoryImpl factory)

	
	   
		definition = factory.getFilterDefinition(filterName);
	
public org.hibernate.engine.FilterDefinitiongetFilterDefinition()

		return definition;
	
public java.lang.StringgetName()
Get the name of this filter.

return
This filter's name.

		return definition.getFilterName();
	
public java.lang.ObjectgetParameter(java.lang.String name)
Get the value of the named parameter for the current filter.

param
name The name of the parameter for which to return the value.
return
The value of the named parameter.

		return parameters.get( name );
	
public java.util.MapgetParameters()

		return parameters;
	
public org.hibernate.FiltersetParameter(java.lang.String name, java.lang.Object value)
Set the named parameter's value for this filter.

param
name The parameter's name.
param
value The value to be applied.
return
This FilterImpl instance (for method chaining).
throws
IllegalArgumentException Indicates that either the parameter was undefined or that the type of the passed value did not match the configured type.

		// Make sure this is a defined parameter and check the incoming value type
		// TODO: what should be the actual exception type here?
		Type type = definition.getParameterType( name );
		if ( type == null ) {
			throw new IllegalArgumentException( "Undefined filter parameter [" + name + "]" );
		}
		if ( value != null && !type.getReturnedClass().isAssignableFrom( value.getClass() ) ) {
			throw new IllegalArgumentException( "Incorrect type for parameter [" + name + "]" );
		}
		parameters.put( name, value );
		return this;
	
public org.hibernate.FiltersetParameterList(java.lang.String name, java.util.Collection values)
Set the named parameter's value list for this filter. Used in conjunction with IN-style filter criteria.

param
name The parameter's name.
param
values The values to be expanded into an SQL IN list.
return
This FilterImpl instance (for method chaining).

		// Make sure this is a defined parameter and check the incoming value type
		if ( values == null ) {
			throw new IllegalArgumentException( "Collection must be not null!" );
		}
		Type type = definition.getParameterType( name );
		if ( type == null ) {
			throw new HibernateException( "Undefined filter parameter [" + name + "]" );
		}
		if ( values.size() > 0 ) {
			Class elementClass = values.iterator().next().getClass();
			if ( !type.getReturnedClass().isAssignableFrom( elementClass ) ) {
				throw new HibernateException( "Incorrect type for parameter [" + name + "]" );
			}
		}
		parameters.put( name, values );
		return this;
	
public org.hibernate.FiltersetParameterList(java.lang.String name, java.lang.Object[] values)
Set the named parameter's value list for this filter. Used in conjunction with IN-style filter criteria.

param
name The parameter's name.
param
values The values to be expanded into an SQL IN list.
return
This FilterImpl instance (for method chaining).

		return setParameterList( name, Arrays.asList( values ) );
	
public voidvalidate()
Perform validation of the filter state. This is used to verify the state of the filter after its enablement and before its use.

throws
HibernateException If the state is not currently valid.

		// for each of the defined parameters, make sure its value
		// has been set
		Iterator itr = definition.getParameterNames().iterator();
		while ( itr.hasNext() ) {
			final String parameterName = (String) itr.next();
			if ( parameters.get( parameterName ) == null ) {
				throw new HibernateException(
						"Filter [" + getName() + "] parameter [" + parameterName + "] value not set"
				);
			}
		}