Search code examples
grailssharding

Grails: Use new Multiple Datasources for sharding?


I want to be able to put an object into one of several shards based on a value of a field. In milestone 2.0 I see examples like

def zipCode = ZipCode.auditing.get(42)
zipCode.auditing.save()

But how would I dynamically choose the data source. I want something more like

ZipCode.datasource(1).get(42) // where 1 is calculated based on some other value.

Is there anyway to do that?


Solution

  • See http://grails.org/plugin/sharding which uses the Datasources plugin. The new multiple-datasources support in Grails is the result of moving the Datasources plugin into core, so it should be straightforward to either update the plugin or borrow its code and adapt it.