[appengine-java] Getting the client's timezone

2010-02-08 Thread hsjawanda
Hi,

Any ideas on how to get the user's timezone (i.e., the timezone the
client is working in)?

The closest I've come so far to an answer is:
http://j2eecookbook.blogspot.com/2007/06/formatting-date-to-client-timezone.html

Does anybody have a better way of accomplishing this?

I'd prefer to avoid asking the client to set their timezone as a
preference because:

* Sign-ups should be as fast as possible.

* What if the client is temporarily working from a different timezone?

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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Close PersistenceManager every time?

2010-02-08 Thread hsjawanda
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Close PersistenceManager every time?

2010-02-10 Thread hsjawanda
Nobody knows the answer to this?

On Feb 7, 2:34 pm, hsjawanda  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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Close PersistenceManager every time?

2010-02-11 Thread hsjawanda
On Feb 11, 11:42 am, Conor Power  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 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)  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  wrote:
>
> >> Nobody knows the answer to this?
>
> >> On Feb 7, 2:34 pm, hsjawanda  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
> >> google-appengine-j...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> google-appengine-java+unsubscr...@googlegroups.com
> >> .
> >> 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
> > google-appengine-j...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-appengine-java+unsubscr...@googlegroups.com
> > .
> > 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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Getting the client's timezone

2010-02-12 Thread hsjawanda
On Feb 9, 3:38 am, "Ikai L (Google)"  wrote:
> It's not an issue with Java but
> with HTTP in general. This doesn't solve the case of a traveling user if
> they don't set their clock correctly.

True. There's nothing we can do for the users if they won't even set
their clocks correctly :-). This is especially a problem if--as you
point out--a travelling user is working on a borrowed computer.

Thanks to some troll in the same IP range as me, my IP range is banned
by StackOverflow :-(... I can only read using Google's cached
version ;-).

Regards,
HSJ

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Detecting non existing entity

2010-04-17 Thread hsjawanda
What has worked for me was to change the file (e.g. add a space,
delete the space, save the file) containing the Entity definition—this
causes the enhancer to enhance the Entity in question. Let me know if
this works for you.

On Apr 15, 3:56 pm, Vik  wrote:
> Hie
>
> I have a Entity class Country.
>
> The very first time when i am running my app this is not created in
> datastore.
> So my code:
>   try{
>       String query = "select from " + BloodDonorCountryList.class.getName()
> +
>           " where  countryName == \"" + country.toLowerCase() + "\"";
>
>       log.info("Query is:" + query);
>
>           List countryList =
> (List) pm.newQuery(query).execute();
>           log.info("returning: :");
>           if(countryList.isEmpty())
>           return null;
>           return countryList;
>      }catch(Exception e){
>      log.severe("Method: addBloodDonorCountry");
>      log.severe(e.getClass().getName() + " " + e.getMessage());
>      throw new CommandExecuteException("Problem while querying country
> list.");
>      }
>
> throws exception saying:
> EVERE: javax.jdo.JDOUserException Persistent class "Class
> vik.sakshum.Country does not seem to have been enhanced.  You may want to
> rerun the enhancer and check for errors in the output." has no table in the
> database, but the operation requires it. Please check the specification of
> the MetaData for this class.
>
> So how to avoid this exception? Or in other words how to detect if this is
> the case.
>
> Thankx and Regards
>
> Vik
> Founderwww.sakshum.comwww.sakshum.blogspot.com

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Query for children of entity with JDO

2010-04-18 Thread hsjawanda
Even though Datanucleus' method seems better, I thought I'd list how I
would have done it. If anyone thinks that there would be problems
doing it my way, please let us all know.

Store a unique property of the parent (this would usually be the
PrimaryKey of the parent) in a data field of the child (somewhat
similar to having a foreign key in an RDDMS). Then you can simply
query for the child entities that have a particular value for this
field.

On Apr 18, 10:10 am, datanucleus  wrote:
> > Thanks a lot for the thoughts Hani, but I do only want the children,
>
> So do a JDOQL query for the elements
> pm.newQuery("SELECT FROM MyElement WHERE myParent == :parent");
> and pass in the parent object, and add on any other filter
> requirements.
>
> --
> 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 google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to 
> google-appengine-java+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Cannot persist a HashMap

2010-04-18 Thread hsjawanda
The following posting by Max Ross of the Google App Engine engineering
team is extremely useful for the case of all serialized fields (which
is the only way you can store HashMap-s in GAE (at least so far)):

JDO/JPA Snippets That Work - Serialized Fields
http://bit.ly/9fMbPs


On Apr 18, 5:11 pm, mscwd01  wrote:
> Thanks for your informative reply.
>
> So basically, the only solution you found was to create a copy of the
> whole object holding the HashMap, persist the new object and delete
> the old object?
> I sincerely hope I have misunderstood you as this is a terrible way to
> have to go about it.
>
> Is there any other way, you can update a HashMap rather than creating
> a whole new object to persist?
>
> Thanks again for your help with this.
>
> On Apr 18, 6:50 am, "sreenidhi b.s"  wrote:
>
>
>
> >http://groups.google.com/group/google-appengine-java/browse_thread/th...
>
> > the link above works only for persisting and retrieving hash maps ,but i did
> > not  find any "proper" solution for updating and persisting the updated
> > hashmaps.
>
> > "You have to provide a new reference to the updated hashmap ,since datastore
> > cannot identify between updated and stale hashmap."
> > But it did not work in my case and i urge you to try the same before you try
> > alternatives.
>
> > The Alternative i found was ,
> > 1) retrieve the persisted hashmap ,
> > 2) create a new hashmap reference to updated hashmap
> > 3) make the new reference persistent.
> > 4)delete the previous reference.
>
> > code: /* i have used some custom classes ,but the you should be able to
> > understand the logic i've employed to get the solution */
>
> > /*Retrieve the persisted HashMap*/
> > PersistenceManager pm0= PMF.get().getPersistenceManager();
> > Query query0 = pm0.newQuery(VocabHashMap.class);
> > List results1 = (List) query0.execute();
> >  /*if there are no hashmaps, create a new one */
> > if (results1.isEmpty())
> > {
>
> >         HashMap map = new HashMap();
> >         for (String a : linelist) {
> >          Double freq = map.get(a);
> >           map.put(a, (freq == null) ? 1 : freq + 1);
> >         }
> > VocabHashMap vhm =new VocabHashMap(map);
> > pm0.makePersistent(vhm);
> > pm0.close();
>
> > }
>
> > else{
>
> > for (VocabHashMap vhm : results1) {
>
> >         /*if you already have a hashmap,then update it */
>
> >  HashMap map1=vhm.getMap();  /* assign a new reference to
> > retrieved hashmap */
>
> >  for (String a : linelist) {
> >          Double freq = map1.get(a);
> >           map1.put(a, (freq == null) ? 1 : freq + 1);
>
> > }
>
> >     VocabHashMap vhm1=new VocabHashMap(map1);    /* create  a new hashmap*/
> >         pm0.makePersistent(vhm1); /*save the updated one */
> >     pm0.deletePersistent(vhm);  /*delete the old reference */
>
> >     }
>
> > pm0.close();
>
> > }
> > On Sun, Apr 18, 2010 at 10:41 AM, seleronm  wrote:
> > > Hi,
>
> > > I was useful referring to this thread.
> > > You might be also useful for it.
>
> > >http://groups.google.com/group/google-appengine-java/browse_thread/th...
>
> > > Hope some of this helps.
>
> > > thanks.
>
> > > > I am not able to persist a HashMap field. This is how I define it:
>
> > > > @Persistent(serialized = "true", defaultFetchGroup = "true")
> > > > private Map items;
>
> > > > When I create the Object which the Map is a field of, I instantiate
> > > > the Map as follows:
>
> > > > items = new HashMap();
>
> > > > When I update the "items" HashMap I try to persist the object by doing
> > > > the following:
>
> > > > PersistenceManager pm = PMF.get().getPersistenceManager();
> > > > // Query for Object (HashMap is a field of this Object)
> > > > // Update HashMap
> > > > pm.makePersistent(objectContainingHashMap);
>
> > > > However, when I attempt to retrieve the object after persisting it and
> > > > read the HashMap it is always empty, as though I never updated it.
>
> > > > Has anyone experienced this before?
>
> > > > Thanks

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.