代码之家  ›  专栏  ›  技术社区  ›  stefanglase

配置Grails以使用自己的数据源实现或代理标准数据源

  •  5
  • stefanglase  · 技术社区  · 15 年前

    javax.sql.DataSource 扩展了标准 org.apache.commons.dbcp.BasicDataSource 由Grails使用,并添加了基于Grails应用程序中当前登录的用户设置客户端标识符的功能。

    Grails应用程序中的实现?

    目前我看到两种可能性:

    • 更改Grails使用的数据源的实现
    • 代理Grails使用的数据源,并使用AOP添加功能

    关于如何处理这个要求有什么提示吗?

    2 回复  |  直到 15 年前
        1
  •  4
  •   Oleksandr    15 年前

    这是我的 资源.groovy

    import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH
    
    // Place your Spring DSL code here
    beans = {
    
        /**
         * c3P0 pooled data source that forces renewal of DB connections of certain age 
         * to prevent stale/closed DB connections and evicts excess idle connections
         * Still using the JDBC configuration settings from DataSource.groovy
         * to have easy environment specific setup available
         */
        dataSource(com.mchange.v2.c3p0.ComboPooledDataSource) { bean ->
            bean.destroyMethod = 'close'
            //use grails' datasource configuration for connection user, password, driver and JDBC url
            user = CH.config.dataSource.username 
            password = CH.config.dataSource.password
            driverClass = CH.config.dataSource.driverClassName
            jdbcUrl = CH.config.dataSource.url
            //force connections to renew after 2 hours
            maxConnectionAge = 2 * 60 * 60
            //get rid too many of idle connections after 30 minutes 
            maxIdleTimeExcessConnections = 30 * 60
        }
    
    }
    

    c3p0型 组合池数据源

        2
  •  3
  •   hvgotcodes    15 年前

    您尝试过在resources.groovy中配置自己的数据源吗?这里有一篇博客文章(不是我的)介绍了这个过程

    http://burtbeckwith.com/blog/?p=312

    你需要的东西就在最后。