You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Chris Murphy <ch...@strandz.org> on 2008/08/11 03:24:16 UTC

Call a service, but still with one DataContext

Hi Group,

I am trying to get my head round how Cayenne would work with Spring 
services. The great advantage of Cayenne is that it is designed for 
exposing the domain model. But applications will still always have 
functions best performed as a service. Having two DataContexts leads to 
confusion. So is the solution is to have Tomcat embedded in Cayenne's 
server-side software? The requirement is to have no more than one 
DataContext per user on the server. (There will be a proxy-DataContext 
on each client to enable domain exposure). I'm trying 
to get my head around achieving "one DataContext".

Would this embedded instance of Tomcat conflict with the server 
machine's already running Tomcat instance?

I haven't yet looked at how Cayenne's server-side software is invoked. 
Can it only be sparked off as a servlet? Or can a program I write be 
sparked off say from the command line - in which case it could create a 
DataContext that is handed as a global to an embedded instance of Tomcat 
and thereby somehow made easily available 
to Spring services that the client apps will call back to?

thanks - Chris

-- 
Seaweed Software Pty Ltd,
http://www.strandz.org


Re: Call a service, but still with one DataContext

Posted by Kevin Menard <ni...@gmail.com>.
Ahh . . . I misunderstood what you were trying to do.
It sounds like you are indeed looking to use the three tier (ROP)
architecture.  In this case, you will want to use Cayenne in its server
capacity.  It should have little bearing on the rest of your Web app,
however.  Cayenne comes with a servlet that you can set up in your web.xml
[1].  Multiple servlets can exist in the same Web app . . . just bind them
to different URLs.

Context management gets a little trickier, but you're probably most
concerned with the client level of things.  In that case, just create a
CayenneContext per user session in your Swing app.

Apologies also for the shorthand.  WS = Web Services.

[1] --
http://cayenne.apache.org/doc/remote-object-persistence-cws-deployment.html

-- 
Kevin


On Mon, Aug 11, 2008 at 9:16 PM, Chris Murphy <ch...@strandz.org> wrote:

>
> Hi Kevin,
>
> I'm coming from JDO which has PersistenceManager instead of a DataContext -
> but they should be conceptually the same thing. I am interested in using
> Cayenne over a client/server connection from a Swing front end. Hence
> there's a proxy-DataContext that the Swing client will be communicating
> with? I imagine the part that runs on the server that handles the client
> requests normally runs as a servlet? My issue is that as Spring also runs as
> a servlet, how can both servlets use the same DataContext?
>
> It has been a long time since I've done any servlet or Spring configuration
> - so do let me know if any of the assumptions I've just made are wrong.
>
> From what you say: "bind your DataContext to the user session" - is the
> answer to lazily load the DataContext from the Session enabling both the
> servlets to have access to the same DataContext - by always finding it
> through the Session object?
>
> thanks - Chris
> PS./ What's a WS server? Is that a 'web service'?
>
> Kevin Menard wrote:
>
>> Hi Chris,
>> I'm not really sure I understand your question.  I think you're slightly
>> confused by our nomenclature.  Cayenne server really is just a plain Java
>> package.  The server part comes from a three-tier role, where we have a
>> separate client package.  In this case, you'd run some sort of WS server
>> to
>> handle the client requests.  Otherwise, you can use the "server" package
>> in
>> any app.
>>
>> Viewed that way, you're best bet is probably to use the servlet filter and
>> bind your DataContext to the user session.  This should ensure that you
>> only
>> have one DC per user.  From there, you just need to apply basic principles
>> for using a single DC.  In particular, don't get messy with uncommitted
>> state.
>>
>>
>>
>
> --
> Seaweed Software Pty Ltd,
> http://www.strandz.org
>
>

Re: Call a service, but still with one DataContext

Posted by Chris Murphy <ch...@strandz.org>.
Hi Kevin,

I'm coming from JDO which has PersistenceManager instead of a 
DataContext - but they should be conceptually the same thing. I am 
interested in using Cayenne over a client/server connection from a Swing 
front end. Hence there's a proxy-DataContext that the Swing client will 
be communicating with? I imagine the part that runs on the server that 
handles the client requests normally runs as a servlet? My issue is that 
as Spring also runs as a servlet, how can both servlets use the same 
DataContext?

It has been a long time since I've done any servlet or Spring 
configuration - so do let me know if any of the assumptions I've just 
made are wrong.

 From what you say: "bind your DataContext to the user session" - is the 
answer to lazily load the DataContext from the Session enabling both the 
servlets to have access to the same DataContext - by always finding it 
through the Session object?

thanks - Chris  

PS./ What's a WS server? Is that a 'web service'?

Kevin Menard wrote:
> Hi Chris,
> I'm not really sure I understand your question.  I think you're slightly
> confused by our nomenclature.  Cayenne server really is just a plain Java
> package.  The server part comes from a three-tier role, where we have a
> separate client package.  In this case, you'd run some sort of WS server to
> handle the client requests.  Otherwise, you can use the "server" package in
> any app.
>
> Viewed that way, you're best bet is probably to use the servlet filter and
> bind your DataContext to the user session.  This should ensure that you only
> have one DC per user.  From there, you just need to apply basic principles
> for using a single DC.  In particular, don't get messy with uncommitted
> state.
>
>   

-- 
Seaweed Software Pty Ltd,
http://www.strandz.org


Re: Call a service, but still with one DataContext

Posted by Kevin Menard <ni...@gmail.com>.
Hi Chris,
I'm not really sure I understand your question.  I think you're slightly
confused by our nomenclature.  Cayenne server really is just a plain Java
package.  The server part comes from a three-tier role, where we have a
separate client package.  In this case, you'd run some sort of WS server to
handle the client requests.  Otherwise, you can use the "server" package in
any app.

Viewed that way, you're best bet is probably to use the servlet filter and
bind your DataContext to the user session.  This should ensure that you only
have one DC per user.  From there, you just need to apply basic principles
for using a single DC.  In particular, don't get messy with uncommitted
state.

-- 
Kevin


On Sun, Aug 10, 2008 at 9:24 PM, Chris Murphy <ch...@strandz.org> wrote:

> Hi Group,
>
> I am trying to get my head round how Cayenne would work with Spring
> services. The great advantage of Cayenne is that it is designed for exposing
> the domain model. But applications will still always have functions best
> performed as a service. Having two DataContexts leads to confusion. So is
> the solution is to have Tomcat embedded in Cayenne's server-side software?
> The requirement is to have no more than one DataContext per user on the
> server. (There will be a proxy-DataContext on each client to enable domain
> exposure). I'm trying to get my head around achieving "one DataContext".
>
> Would this embedded instance of Tomcat conflict with the server machine's
> already running Tomcat instance?
>
> I haven't yet looked at how Cayenne's server-side software is invoked. Can
> it only be sparked off as a servlet? Or can a program I write be sparked off
> say from the command line - in which case it could create a DataContext that
> is handed as a global to an embedded instance of Tomcat and thereby somehow
> made easily available to Spring services that the client apps will call back
> to?
>
> thanks - Chris
>
> --
> Seaweed Software Pty Ltd,
> http://www.strandz.org
>
>