Grails

Allow setting custom entityInterceptor for Hibernate sessionFactory to allow usage of dynamic schemas for all SQL statements

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.1, 1.1.1
  • Fix Version/s: 1.2-M1
  • Component/s: Persistence
  • Labels:
    None
  • Patch Submitted:
    Yes

Description

In order to qualify the table names used by GORM, when developing applications against a database environment which uses the same table layout but in different schemas, I would like to be able to define my own entityInterceptor for sessionFactory.
The entityInterceptor contains the method "onPrepareStatement(String sql) that can be used to modify the SQL statement before it is invoked against the database.

With 1.0.* this was possible by defining your own "eventTriggeringInterceptor" bean in resources.groovy, since this bean is set as entityInterceptor when sessionFactory is being created.

Since 1.1, the usage of "eventTriggeringInterceptor" has changed, and the implemented interceptor ClosureEventTriggeringInterceptor is now being set in property eventListeners insted.
This interface does not support the "onPrepareStatement" as far as we can read the Hibernate API documentation.

PATCH supplied will set entityInterceptor from bean "eventEntityInterceptor" (new bean). This bean is initialized to instance of org.hibernate.EmptyInterceptor and can be set to a custom implementation from resources.groovy like:

{{
beans = { eventEntityInterceptor(QualifiedNameInterceptor) } }}

eventListeners are still set, and we're now able to support schemas per session which is a common need when developing against for instance an IBM i database.

HibernatePluginSupport from Grails 1.1:
http://www.google.com/codesearch/p?hl=de#BExOlTNH8oU/grails/src/groovy/org/codehaus/groovy/grails/plugins/orm/hibernate/HibernatePluginSupport.groovy&q=HibernatePluginSupport%20package:grails

Activity

Hide
Henrik Fjorback added a comment -

New patch created with latest source code from GitHub.

Show
Henrik Fjorback added a comment - New patch created with latest source code from GitHub.
Hide
Henrik Fjorback added a comment -

The new patch uses bean name "entityInterceptor" instead of "eventEntityInterceptor".

In resources.groovy, define your own entityInterceptor using:

beans = {
entityInterceptor(QualifiedNameInterceptor)
}

Show
Henrik Fjorback added a comment - The new patch uses bean name "entityInterceptor" instead of "eventEntityInterceptor". In resources.groovy, define your own entityInterceptor using: beans = { entityInterceptor(QualifiedNameInterceptor) }
Hide
Graeme Rocher added a comment -

Thanks for the patch

Show
Graeme Rocher added a comment - Thanks for the patch

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: