/
HibernateHijackerGrailsPlugin.groovy
75 lines (61 loc) · 3.1 KB
/
HibernateHijackerGrailsPlugin.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import grails.plugin.hibernatehijacker.hibernate.HibernateEventSubscriptionFactory
import grails.plugin.hibernatehijacker.hibernate.SessionFactoryProxyFactory
import grails.plugin.hibernatehijacker.hibernate.events.HibernateEventListener
import grails.plugin.hibernatehijacker.hibernate.events.HibernateEventPropertyUpdater
import grails.plugin.hibernatehijacker.indexdsl.IndexDslPostProcessor
import grails.plugin.hibernatehijacker.spring.SessionFactoryPostProcessor
import grails.plugin.hibernatehijacker.template.HibernateTemplates
class HibernateHijackerGrailsPlugin {
def version = "0.8.1"
def grailsVersion = "1.3.5 > *"
/* The webflow plugin replaces SpringSessionContext.
* By loading our plugin after webflow (if it's installed) we can detect this
* and create an instance of FlowAwareCurrentSessionContext instead of SpringSessionContext.
*/
def loadAfter = ['webflow']
def pluginExcludes = [
"**/demo/**"
]
def author = "Kim A. Betti"
def authorEmail = "kim.betti@gmail.com"
def title = "Hibernate Hijacker"
def documentation = "http://grails.org/plugin/hibernate-hijacker"
def description = '''\
This plugin is a part of the re-engineering efforts going into the Multi-Tenant plugin.
It is very difficult to intercept new Hibernate sessions in a non-intrusive way.
Multiple plugins trying to archive this are likely to step on each others feet.
This plugin publishes intercepted Session instances to a lightweight event broker.
'''
def license = "APACHE"
// def developers = [[name: "Joe Bloggs", email: "joe@bloggs.net"]]
def issueManagement = [system: 'GitHub', url: 'https://github.com/multi-tenant/grails-hibernate-hijacker/issues']
def scm = [url: 'https://github.com/multi-tenant/grails-hibernate-hijacker']
def doWithSpring = {
// Responsible for wrapping the real SessionFactory instance
// inside a JDK proxy so we can intercept new sessions.
sessionFactoryProxyFactory(SessionFactoryProxyFactory) {
eventBroker = ref("eventBroker")
}
// Register the Hibernate event listener responsible for proxying
// Hibernate events to more accessible Hawk events.
hibernateEventListener(HibernateEventSubscriptionFactory) {
eventListener = { HibernateEventListener listener ->
eventBroker = ref("eventBroker")
}
}
// Reads composite database indexes from domain
// classes with a static indexes property
indexDslConfigurator(IndexDslPostProcessor)
// Responsible replacing the sessionFactory
// with our WrappedSessionFactoryBean
sessionFactoryPostProcessor(SessionFactoryPostProcessor)
// Implements withTransaction and withNewSession
hibernateTemplates(HibernateTemplates) {
transactionManager = ref("transactionManager")
sessionFactory = ref("sessionFactory")
}
// Provides a convenient way of updating entity data
// before it's persisted to the database.
hibernateEventPropertyUpdater(HibernateEventPropertyUpdater)
}
}