Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: Grails-Hibernate-Filter 0.3
-
Labels:None
-
Environment:hibernate-filter-0.2
-
Patch Submitted:Yes
-
Patch attached:Yes
Description
Attached is a suggested improvement/patch to the hibernate-filter-0.2 to allow filter parameter names and filter parameter types to be passed as separate comma separated strings. Additionally the method used to locate parameters within the condition is improved rather than assuming all parameters have the syntax ':parameter=' which doesn't permit parameters to be specified where there is no equals sign e.g. 'fieldname in (:parameter)'.
The previous code (in addFilter) simply used StringUtils.substringsBetween(condition,':','=') which limited the usage of the parameters.
An example filter would be:
class TestDomain {
...
static hibernateFilters = {
securityFilter(condition: '(organisation_id = :oragnisationId or organisation_id in (:organisationIds))', paramNames: 'organisationId,organisationIds', paramTypes: 'long,long', default: false)
}
}
And subsequently e.g. in a grails filter or domain controller:
def filter = TestDomain.enableHibernateFilter('securityFilter')
def organisationIds = [2,3,4]
filter.setParameter('organisationId, 1)
filter.setParameterList('organisationIds', organisationIds)
Attached is a suggested improvement to the addFilter method within hibernate-filter-0.2/src/groovy/org/grails/plugin/hibernate/filter/HibernateFilterBuilder.groovy.
Note that the paramNames argument isn't needed - the code uses a regex to find the named parameters.