|
1 | 1 | import org.hibernate.dialect.DialectFactory |
2 | 2 | import org.springframework.jdbc.datasource.DriverManagerDataSource |
3 | 3 | import org.springframework.jdbc.support.JdbcUtils |
4 | | -import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration |
5 | | - |
6 | 4 |
|
7 | 5 | includeTargets << grailsScript("_GrailsBootstrap") |
8 | 6 |
|
9 | 7 | def props = new Properties() |
10 | | -def filename = "${basedir}/ddl.sql" |
| 8 | +def filename = "${grailsSettings.projectTargetDir}/ddl.sql" |
11 | 9 | boolean export = false |
12 | 10 | boolean stdout = false |
| 11 | +String configClassName = 'org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration' |
13 | 12 |
|
14 | 13 | def configClasspath = { |
15 | 14 |
|
@@ -51,6 +50,16 @@ def populateProperties = { |
51 | 50 | props.'hibernate.connection.url' = dsConfig?.dataSource?.url ?: 'jdbc:hsqldb:mem:testDB' |
52 | 51 | props.'hibernate.connection.driver_class' = |
53 | 52 | dsConfig?.dataSource?.driverClassName ?: 'org.hsqldb.jdbcDriver' |
| 53 | + |
| 54 | + if (dsConfig?.dataSource?.configClass) { |
| 55 | + if (dsConfig.dataSource.configClass instanceof Class) { |
| 56 | + configClassName = dsConfig.dataSource.configClass.name |
| 57 | + } |
| 58 | + else { |
| 59 | + configClassName = dsConfig.dataSource.configClass |
| 60 | + } |
| 61 | + } |
| 62 | + |
54 | 63 | if (dsConfig?.dataSource?.dialect) { |
55 | 64 | def dialect = dsConfig.dataSource.dialect |
56 | 65 | if (dialect instanceof Class) { |
@@ -91,21 +100,25 @@ target(schemaExport: 'Run Hibernate SchemaExport') { |
91 | 100 |
|
92 | 101 | populateProperties() |
93 | 102 |
|
94 | | - def configuration = new GrailsAnnotationConfiguration( |
95 | | - grailsApplication: grailsApp, |
96 | | - properties: props) |
| 103 | + def configuration = classLoader.loadClass(configClassName).newInstance() |
| 104 | + configuration.setGrailsApplication(grailsApp) |
| 105 | + configuration.setProperties(props) |
97 | 106 | def hibernateCfgXml = eventsClassLoader.getResource('hibernate/hibernate.cfg.xml') |
98 | 107 | if (hibernateCfgXml) { |
99 | 108 | configuration.configure(hibernateCfgXml) |
100 | 109 | } |
101 | 110 |
|
102 | | - def schemaExport = classLoader.loadClass('org.hibernate.tool.hbm2ddl.SchemaExport').newInstance(configuration).setHaltOnError(true).setOutputFile(file.path).setDelimiter(';') |
| 111 | + def schemaExport = classLoader.loadClass('org.hibernate.tool.hbm2ddl.SchemaExport') |
| 112 | + .newInstance(configuration) |
| 113 | + .setHaltOnError(true) |
| 114 | + .setOutputFile(file.path) |
| 115 | + .setDelimiter(';') |
103 | 116 |
|
104 | 117 | def action = export ? "Exporting" : "Generating script to ${file.path}" |
105 | 118 | println "${action} in environment '${grailsEnv}' using properties ${props}" |
106 | 119 |
|
107 | 120 | if (export) { |
108 | | - // 11st drop, warning exceptions |
| 121 | + // 1st drop, warning exceptions |
109 | 122 | schemaExport.execute(stdout, true, true, false) |
110 | 123 | schemaExport.exceptions.clear() |
111 | 124 | // then create |
|
0 commit comments