- multiple databases
- a database view
- Netezza, a database with no hibernate dialect
The following solution is a Groovy-style DAO query:
- define the second datasource in grails-app/conf/spring/resources.groovy:
import org.apache.commons.dbcp.BasicDataSource
beans = {
dataSourceNetezza(BasicDataSource) {
driverClassName = "org.netezza.Driver"
url = "jdbc:netezza://server:5480/database_name"
username = "xyz"
password = "abc"
}
} - Use the dataSourceNetezza defined above in a controller where the Spring application context is available. Note that the dataSourceNetezza is auto-wired by Spring and the names have to match.
import groovy.sql.Sql
class TablesController {
def dataSourceNetezza
def list = {
if (servletContext.dbList == null)
servletContext.dbList = new Sql(dataSourceNetezza).rows("SELECT distinct DATABASE_NAME FROM REPOSITORY")
print servletContext.dbList
}
...
}
This approach looks extremely simple with less than 15 lines of code. Keep in mind that, there is no ORM.
No comments:
Post a Comment