开发者

State of the Grails datasources plugin

开发者 https://www.devze.com 2023-03-11 15:56 出处:网络
I am trying to get the multiple datasources plugin running for an application I\'m working on. It seems (to me) that one of the upgrades to grails has broken the plugin\'s functionality. I\'m working

I am trying to get the multiple datasources plugin running for an application I'm working on. It seems (to me) that one of the upgrades to grails has broken the plugin's functionality. I'm working with an up to date installation 1.3.7 and trying to use the example app that is posted . I've tried everything under the sun to get the functionality in the example app to work, but nothing does.

To do some further testing I downgraded my grails env to 1.0.3, the version that the demo application was written in. When run with t开发者_高级运维his version, everything works fine; I can connect to all three datasources without fail.

My question is: Is anyone out there able to use the plugin successfully under Grails 1.3.7, and, does anyone know if this is still an active project? Or, is the another way to approach connecting to multiple datasources?

Thanks in advance,

Donald


It appears the Datasources plugin is receiving some renewed attention.

From This Week in Grails (2011-22) - "Grails 1.4 development is going well. ... I’ve added support for multiple datasources to core (from the Datasources plugin) and am working on adding two-phase commit (XA/JTA) for JDBC and JMS."


I successfully integrated the Datasources plugin into a new Grails 1.3.7 project. I chose to combine the configuration with the primary datasource to make it easier to maintain. Here are the steps I followed:

Reference the plugin using plugin dependency resolution in conf/BuildConfig.groovy

grails.project.dependency.resolution = {
    plugins {
        runtime ':datasources:0.5'
    }
}

Create an additional datasource in conf/Datasources.groovy

import org.codehaus.groovy.grails.commons.ConfigurationHolder

datasources = {
    datasource(name: 'DS2') {
        domainClasses([domain.Object])
        if (ConfigurationHolder.config.DS2.dataSource.readOnly) readOnly(ConfigurationHolder.config.DS2.dataSource.readOnly)
        driverClassName(ConfigurationHolder.config.DS2.dataSource.driverClassName)
        url(ConfigurationHolder.config.DS2.dataSource.url)
        if (ConfigurationHolder.config.DS2.dataSource.username) username(ConfigurationHolder.config.DS2.dataSource.username)
        if (ConfigurationHolder.config.DS2.dataSource.password) password(ConfigurationHolder.config.DS2.dataSource.password) 
        if (ConfigurationHolder.config.DS2.dataSource.dbCreate) dbCreate(ConfigurationHolder.config.DS2.dataSource.dbCreate)
        dialect(ConfigurationHolder.config.DS2.dataSource.dialect)
        if (ConfigurationHolder.config.DS2.dataSource.jndiName) jndiName(ConfigurationHolder.config.DS2.dataSource.jndiName)
        if (ConfigurationHolder.config.DS2.dataSource.pooled) pooled(ConfigurationHolder.config.DS2.dataSource.pooled)
        if (ConfigurationHolder.config.DS2.dataSource.loggingSql) loggingSql(ConfigurationHolder.config.DS2.dataSource.loggingSql)
        if (ConfigurationHolder.config.DS2.dataSource.logSql) logSql(ConfigurationHolder.config.DS2.dataSource.logSql)

        hibernate {
            cache {
                if (ConfigurationHolder.config.DS2.hibernate.cache.use_second_level_cache) use_second_level_cache(ConfigurationHolder.config.DS2.hibernate.cache.use_second_level_cache)
                if (ConfigurationHolder.config.DS2.hibernate.cache.use_query_cache) use_query_cache(ConfigurationHolder.config.DS2.hibernate.cache.use_query_cache)
                if (ConfigurationHolder.config.DS2.hibernate.cache.provider_class) provider_class(ConfigurationHolder.config.DS2.hibernate.cache.provider_class)
            }
        }
    }
}

Configure the default datasource and environment specific settings in conf/Datasource.groovy

DS2 {
    dataSource {
        pooled=true
        readOnly=false
        driverClassName="org.hsqldb.jdbcDriver"
        username=""
        password=""
        dialect="org.hibernate.dialect.HSQLDialect"
    }
    hibernate {
        cache.use_second_level_cache=true
        cache.use_query_cache=true
        cache.provider_class="net.sf.ehcache.hibernate.EhCacheProvider"
    }
}

environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop','update'
            url = "jdbc:hsqldb:mem:devDB"
        }
        DS2 {
            dataSource {
                dbCreate="create-drop"
                url="jdbc:hsqldb:mem:devDB2"
            }
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:hsqldb:mem:testDb"
        }
        DS2 {
            dataSource {
                dbCreate="update"
                url="jdbc:hsqldb:mem:testDb2"
            }
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:hsqldb:file:prodDb;shutdown=true"
        }
        DS2 {
            dataSource {
                dbCreate="update"
                url = "jdbc:hsqldb:file:prodDb2;shutdown=true"
            }
        }
    }
}

You can also use an externalized configuration to configure your primary and additional datasources.

0

精彩评论

暂无评论...
验证码 换一张
取 消