Hi all.

In almost all of my Cayenne projects, I have a class that holds my 
ServerRuntime and creates ObjectContexts from that ServerRuntime; sort of a 
central station for my DB connectivity. Works fine, but it means my code is 
somewhat tied to that runtime and calls to MyCentralCayenneClass.newContext() 
are littered all over the place.

I’m currently writing a lot of unit tests and these use a separate 
ServerRuntime with a different configuration that connects to a test database. 
But since some of my code is directly creating contexts from the other 
ServerRuntime (which connects to the production DB) I end up with unintended 
consequences. Same thing for framework code that’s supposed to be reusable—how 
should it obtain ObjectContexts without knowing anything about the currently 
active ServerRuntime?

I see several solutions to the situtation but I wanted to start out by checking 
if there’s a canonical method of solving the problem? (I believe I’m actually 
asking if there’s a way to obtain something like a global currently active 
ServerRuntime, that can be used by reusable code and tests. But I didn’t want 
to frame the question in the wrong way creating an XY Problem)

Cheers,
- hugi

Reply via email to