Question

I'm trying to set up a server with Cayenne (Remote Object Persistence). In my case I have several databases using the same map. What is the best way to implement that as two nodes cannot point to the same map?

I found two ways to do that but that are not really satisfactory:

  • To have a domain for each database and so a servlet for each database. It works but it means that I'll have to change the web.xml and to reload the web application if I create a new database.

  • To have one domain containing several nodes and several maps all pointing to the same file. I had to overload EntityResolver so that it would construct the cache only on the first map and to overload SelectQuery so that it would point to the right map. Not sure it is a good way to do that...

Thanks for your answers and comments.

Was it helpful?

Solution

Assuming Cayenne 3.1 or newer, I'd create a separate ServerRuntime object for each DB. DataSources for each one of them can be created dynamically when you setup a new runtime.

To wire it for ROP you might need to create your own servlet that has a map of multiple HessianServlets, one per DB, and dispatches requests to appropriate instances based on some request parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top