On Feb 11, 11:42 am, Conor Power <[email protected]> wrote:
> Hi,
>   I have a question on detachment ... I have my PM in a DAO and I open and
> close pre / post query. The problem was that the objects returned are null
> once the PM was closed unless I set them to be detachable.

This is exactly the issue I have...

My DAO's methods do the querying & return a List<E> of results. JSP
page uses this list to construct and return the page.

Unless I close the PM in the JSP by making a second call to a Close()
method on the DAO (I don't like that idea), I either leave the PM as
it is (which, based on Ikai's reply, does not seem to be a problem) or
I detach (duplicate?) the result set.

Ikai clearly tells us that detaching is expensive (as expected), so
I'll avoid that.

Do repeated calls to PMF.get().getPersistenceManager() return the same
PM or is a new one created everytime? Even though the
getPersistenceManager() call is light, I'd rather avoid repeated calls
if it returns a new instance every time.

Thanks,
HSJ

> Is there an alternative instead of detach in this case? Should I:
>
> 1. make DTO of the returned objects (similar to what would happen in
> detachable anyway I guess?)
> 2. design the layers such that the PM is closed at the end of the request
> once the reponse has been formed using the data from the objects that were
> queried.
>
> thanks ...
>
> cowper
>
> On Wed, Feb 10, 2010 at 1:46 PM, Ikai L (Google) <[email protected]> wrote:
>
> > This is really up to you, though I would avoid detaching unless absolutely
> > necessary. Opening and closing a PersistenceManager should be extremely
> > cheap (it's instantiating a PersistenceManagerFactory that's expensive).
> > You've got a few options here, and what you do really just depends on what
> > makes sense for you:
>
> > - dependency inject the PersistenceManager into a DAO class that you
> > instantiate and pass that instance around, closing it when you are complete
> > - open and close each time in the DAO - the problem here is if you need a
> > PersistenceManager that spans DAO objects (either build that into a method
> > or a Service layer, though for the record I have an aversion to additional,
> > unnecessary layers that do a single thing)
>
> > From a performance perspective, we aren't doing anything. If you take a
> > look at the low-level API documentation, there's no concept of "close":
>
> >http://code.google.com/appengine/docs/java/javadoc/com/google/appengi...
>
> > On Wed, Feb 10, 2010 at 8:26 AM, hsjawanda <[email protected]> wrote:
>
> >> Nobody knows the answer to this?
>
> >> On Feb 7, 2:34 pm, hsjawanda <[email protected]> wrote:
> >> > Should the PersistenceManager be closed after every query?
>
> >> > I have a utility class that handles querying the datastore. This class
> >> > then returns results which are used by JSP pages to show output.
>
> >> > AFAIK, these are my options:
>
> >> > * Make all my data objects detachable (what is the extra cost of doing
> >> > this? Don't they have to be copied when detaching?
> >> > )
> >> > * Make a second call on the utility class to close the PM (defeats the
> >> > purpose of having the utility class)
>
> >> > * Leave my PM unclosed (what is/are the implications of this?)
>
> >> > I am referring to a case where I am only doing reads from the data
> >> > store.
>
> >> > Regards,
> >> > Harshdeep
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Google App Engine for Java" group.
> >> To post to this group, send email to
> >> [email protected].
> >> To unsubscribe from this group, send email to
> >> [email protected]<google-appengine-java%[email protected]>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/google-appengine-java?hl=en.
>
> > --
> > Ikai Lan
> > Developer Programs Engineer, Google App Engine
> >http://googleappengine.blogspot.com|http://twitter.com/app_engine
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google App Engine for Java" group.
> > To post to this group, send email to
> > [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<google-appengine-java%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-appengine-java?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to