I have built a few Web apps using Cayenne quite successfully but now I am building my first standalone app and have a few questions.

In a Web app, I have typically just setup my Tomcat configuration and in my code I execute something like ObjectContext context = BaseContext.getThreadObjectContext() and let the "magic" happen.

In my standalone application I don't think it will be quite that easy. I will have multiple short lived threads requesting database information simultaneously so I'm not quite sure how to manage the Cayenne components. At first I thought I could simple do a DataContext.createDataContext() and I'd be fine but "Creating a new DataContext for each request is not a recommended practice." So I understand the need for a single DataContext and so I think I found the answer in createChildContext() but,

1) Do I need to manually create a child context in each thread? But what should I do when the thread has completed its transactions and is ready to terminate? I don't see a corresponding "destroyChildContext"

            ObjectContext oc = getDataContext().createChildContext();

2) Or is it better to create a pool of ObjectContexts that I have to manually manage access to within the threads - or does Cayenne have something like this already built-in?

3) Is the maximum simultaneous createChildContext calls tied to the ConnectionPool limits in the Modeler? To me the "createChildContext" implies creation without limit so if they are somehow linked how will I know that the underlying ConnectionPool has run out of resources?

4) Or am I way off base and making things more complicated than they should be? ;-)

Sorry if I've missed the answers somewhere in the documentation but I haven't been able to Google successfully for something I've fully understood.

Thanks,

Andrew





Reply via email to