Grails: changing dataSource url at runtime to achieve multi tenant database separation

白昼怎懂夜的黑 提交于 2019-12-02 05:13:43

You can configure multiple data source in your DataSource.groovy, have a look in the blog.

In your domains: add which data source your domain can interact, eg.,

static mapping = {
    datasources(['dataSource1', 'dataSource2'])
}

or "ALL" for all datasources, eg.,

static mapping = {
    datasource 'ALL'
}

and then you can make queries with data source name to which you want to get/set data, eg.,

def userClass = User.class
User user = userClass.dataSource1.findByName('username')

Ref:- multipleDatasources, Querying on multiple datasource in grails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!