private static void bindFilterDef(FilterDef defAnn, ExtendedMappings mappings) { Map<String, org.hibernate.type.Type> params = new HashMap<String, org.hibernate.type.Type>(); for ( ParamDef param : defAnn.parameters() ) { params.put( param.name(), TypeFactory.heuristicType( param.type() ) ); } FilterDefinition def = new FilterDefinition( defAnn.name(), defAnn.defaultCondition(), params ); log.info( "Binding filter definition: {}", def.getFilterName() ); mappings.addFilterDefinition( def ); }
private String getCondition(String cond, String name) { if ( BinderHelper.isDefault( cond ) ) { cond = mappings.getFilterDefinition( name ).getDefaultFilterCondition(); if ( StringHelper.isEmpty( cond ) ) { throw new AnnotationException( "no filter condition found for filter " + name + " in " + StringHelper.qualify( propertyHolder.getPath(), propertyName ) ); } } return cond; }
public Map getParameterTypes() { return definition.getParameterTypes(); }
@Override public void afterPropertiesSet() { this.filterDefinition = new FilterDefinition(this.filterName, this.defaultFilterCondition, this.parameterTypeMap); }
/** * Get the name of this filter. * * @return This filter's name. */ public String getName() { return definition.getFilterName(); }
private static void parseFilterDef(Element element, Mappings mappings) { String name = element.attributeValue( "name" ); log.debug( "Parsing filter-def [" + name + "]" ); FilterDefinition def = new FilterDefinition( name ); Iterator params = element.elementIterator( "filter-param" ); while ( params.hasNext() ) { final Element param = (Element) params.next(); final String paramName = param.attributeValue( "name" ); final String paramType = param.attributeValue( "type" ); log.debug( "adding filter parameter : " + paramName + " -> " + paramType ); final Type heuristicType = TypeFactory.heuristicType( paramType ); log.debug( "parameter heuristic type : " + heuristicType ); def.addParameterType( paramName, heuristicType ); } String condition = element.getTextTrim(); if ( StringHelper.isEmpty(condition) ) condition = element.attributeValue( "condition" ); def.setDefaultFilterCondition(condition); log.debug( "Parsed filter-def [" + name + "]" ); mappings.addFilterDefinition( def ); }
/** * 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. */ public Filter setParameter(String name, Object value) throws IllegalArgumentException { // 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; }
/** * 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. */ public void validate() throws HibernateException { // 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 IllegalArgumentException("Filter [" + getName() + "] defined parameter [" + parameterName + "] whose value was not set"); } } } }
private static void parseFilterDef(Element element, Mappings mappings) { String name = element.attributeValue( "name" ); log.debug( "Parsing filter-def [" + name + "]" ); String defaultCondition = element.getTextTrim(); if ( StringHelper.isEmpty( defaultCondition ) ) { defaultCondition = element.attributeValue( "condition" ); } HashMap paramMappings = new HashMap(); Iterator params = element.elementIterator( "filter-param" ); while ( params.hasNext() ) { final Element param = (Element) params.next(); final String paramName = param.attributeValue( "name" ); final String paramType = param.attributeValue( "type" ); log.debug( "adding filter parameter : " + paramName + " -> " + paramType ); final Type heuristicType = TypeFactory.heuristicType( paramType ); log.debug( "parameter heuristic type : " + heuristicType ); paramMappings.put( paramName, heuristicType ); } log.debug( "Parsed filter-def [" + name + "]" ); FilterDefinition def = new FilterDefinition( name, defaultCondition, paramMappings ); mappings.addFilterDefinition( def ); }
/** * {@inheritDoc} */ public String getName() { return this.filterDefinition.getFilterName(); }
public Type getFilterParameterType(String filterParameterName) { String[] parsed = parseFilterParameterName(filterParameterName); FilterDefinition filterDef = factory.getFilterDefinition( parsed[0] ); if (filterDef == null) { throw new IllegalArgumentException("Filter [" + parsed[0] + "] not defined"); } Type type = filterDef.getParameterType( parsed[1] ); if (type == null) { // this is an internal error of some sort... throw new InternalError("Unable to locate type for filter parameter"); } return type; }
/** * 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. */ public void validate() throws HibernateException { // 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" ); } } } }
private static void bindFilterDef(FilterDef defAnn, ExtendedMappings mappings) { Map<String, org.hibernate.type.Type> params = new HashMap<String, org.hibernate.type.Type>(); for ( ParamDef param : defAnn.parameters() ) { params.put( param.name(), TypeFactory.heuristicType( param.type() ) ); } FilterDefinition def = new FilterDefinition( defAnn.name(), defAnn.defaultCondition(), params ); if ( log.isInfoEnabled() ) log.info( "Binding filter definition: " + def.getFilterName() ); mappings.addFilterDefinition( def ); }
@Override public SessionFactory buildSessionFactory() throws HibernateException { // set the class loader to load Groovy classes if (grailsApplication != null) { if (LOG.isDebugEnabled()) { LOG.debug("[GrailsAnnotationConfiguration] Setting context class loader to Grails GroovyClassLoader"); } Thread.currentThread().setContextClassLoader(grailsApplication.getClassLoader()); } // work around for HHH-2624 addFilterDefinition(new FilterDefinition("dynamicFilterEnabler", "1=1", Collections.emptyMap())); SessionFactory sessionFactory = super.buildSessionFactory(); if (grailsApplication != null) { GrailsHibernateUtil.configureHibernateDomainClasses( sessionFactory, sessionFactoryBeanName, grailsApplication); } return sessionFactory; }
/** * Get the name of this filter. * * @return This filter's name. */ public String getName() { return definition.getFilterName(); }
if ( BinderHelper.isDefault( cond ) ) { FilterDefinition definition = mappings.getFilterDefinition( filterName ); cond = definition == null ? null : definition.getDefaultFilterCondition(); if ( StringHelper.isEmpty( cond ) ) { throw new AnnotationException(
/** * 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. */ public Filter setParameter(String name, Object value) throws IllegalArgumentException { // 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 static Set createFilterKeys(Map enabledFilters, EntityMode entityMode) { if ( enabledFilters.size()==0 ) return null; Set result = new HashSet(); Iterator iter = enabledFilters.values().iterator(); while ( iter.hasNext() ) { FilterImpl filter = (FilterImpl) iter.next(); FilterKey key = new FilterKey( filter.getName(), filter.getParameters(), filter.getFilterDefinition().getParameterTypes(), entityMode ); result.add(key); } return result; } }
this.filterDefinition = new FilterDefinition(Integer.toString(filterName.hashCode()), filterDefCondition .toString(), new HashMap());
/** * Constructs a new FilterImpl. * * @param configuration The filter's global configuration. */ public FilterImpl(FilterDefinition configuration) { this.definition = configuration; filterName = definition.getFilterName(); }