Imagine two Grails applications which share a domain class. Maybe a Book domain class.
One application is identified as the owner of the data, one will have to access the domain data. Something like amazon and the amazon web services.
I guess it is trivial that the owning application will use a normal domain class and will expose the data through web services – no problem in grails.
But what would be best practice to implement the domain in the other application?
- use a service to access the remote domain and not implement a local domain class at all?
- implement a local domain class, overwrite the get()-method in order to fetch the remote data and use the local database as cache?
- what other solution comes to your mind?
Ryan Geyer has a very interesting article Modularizing your Grails application domain classes which lists 3 solutions to this problem:
As a RESTful JSON Service – easy to get this setup in Grails but then you lose the automatic GORM functionality.
Separate out the domain classes into a library JAR file and reference that library in both of my other applications. This is not as easy as it first sounds
Create a Grails plugin. Put the domain object in the plugin. Each of your applications can then import this plugin. You can then create different controllers with different functionality as required. The sample code for this is available at:
git clone git://ec2.nslms.com/grails/blog_example_modularTed Naleid gives a great tip later in the post and recommends…
Using memcache should enable both applications to have a consistent view of the data and would avoid each individual application having it’s own inconsistent cache.