Вопрос

I have an app, with its own datasource, that needs to get "Item" objects from a different datasource, a readonly one, and use this Items and add them some attributes and collections of "Part" and "Process" objects, so I'm considering three options:

  1. Creating an object with 2 datasources that somehow reads from the readonly database but updates in my database
  2. Creating a trigger in the readonly database that creates an object in my database when someone inserts, updates or deletes something there.
  3. Create two objects one pointing to the readonly database and other pointing to my database and use the decorator pattern to be able to get info from the other database and functionality with my object

I think the easiest one is the trigger in the readonly database cause I don't see how to implement an observer with a factory to create my own objects, to implement options one or three, and I'm not sure if there's a better way, so, what would be the best way of implementing this? how could options 1 or 3 could be implemented? is there something like a "findAllFromHereThatIsntThere" Gorm method that I could call?

Thanks

Это было полезно?

Решение

Since you are using database trigger on the external database, the logic in your application is very straightforward. On your application you can have domains mapping the readonly database and domains for your local db. This will help to separating the concern for each domain. The logic for manipulating the data and storing them in your application database can be inside a transactional service.

Grails provides great features for multiple databases that can be utilized here.

Hope it helps

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top