Hibernate Filter Plugin
  1. Hibernate Filter Plugin
  2. GPHIBERNATEFILTER-1

Suggested improvement to make hibernate filter plugin more flexible

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • 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.

        Activity

        Hide
        Burt Beckwith added a comment -

        Note that the paramNames argument isn't needed - the code uses a regex to find the named parameters.

        Show
        Burt Beckwith added a comment - Note that the paramNames argument isn't needed - the code uses a regex to find the named parameters.

          People

          • Assignee:
            Burt Beckwith
            Reporter:
            Daryl Hurst
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: