Created
October 12, 2010 16:41
-
-
Save kimukou/622497 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g100pon #71 ConfigSlurper | |
// | |
import groovy.lang.* | |
import org.codehaus.groovy.control.* | |
def parseConfig={mode,name-> | |
ClassLoader parent = this.class.getClassLoader() | |
CompilerConfiguration config = new CompilerConfiguration(sourceEncoding:'UTF-8') //equals -Dgroovy.source.encoding=UTF-8 | |
loader = new GroovyClassLoader(parent,config,false) | |
File fn = new File("${name}.groovy") | |
def source = new GroovyCodeSource(fn,"UTF-8") //equals -Dfile.encoding=UTF-8 | |
dataSourceClass = loader.parseClass(source) | |
return new ConfigSlurper(mode).parse(dataSourceClass) | |
//def dataSourceClass = this.class.classLoader.loadClass(name) | |
//return new ConfigSlurper().parse(dataSourceClass) | |
} | |
def config = parseConfig('development','DataSource') | |
println "url=${config.dataSource.url}" | |
println "username=${config.dataSource.username}" | |
println "password=${config.dataSource.password}" | |
println "driverClassName=${config.dataSource.driverClassName}" | |
println "" | |
println "" | |
println "${config.dump()}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dataSource { | |
pooled = false | |
driverClassName = "org.hsqldb.jdbcDriver" | |
username = "sa" | |
password = "" | |
tokenizeddl = false // set this to true if using MySQL or any other | |
// RDBMS that requires execution of DDL statements | |
// on separate calls | |
} | |
pool { | |
maxWait = 60000 | |
maxIdle = 5 | |
maxActive = 8 | |
} | |
environments { | |
development { | |
dataSource { | |
//dbCreate = "create" // one of ['create', 'skip'] | |
url = "jdbc:hsqldb:mem:devDB" | |
} | |
} | |
test { | |
dataSource { | |
//dbCreate = "create" | |
url = "jdbc:hsqldb:mem:testDb" | |
} | |
} | |
production { | |
dataSource { | |
//dbCreate = "skip" | |
url = "jdbc:hsqldb:file:prodDb;shutdown=true" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment