Re: [appengine-java] Re: JDO - I can't update an object with One-to-One Relationships
Thanks Stevko, but I still have the issue. I've add the annotation, without success. I've change the primary key of POJOUser from String to Key, without success. I've add a transaction for make the update, without success. I will make a bidirectionnal relationship this night, for testing. I hope this will works. Have a nice day. Yoann -- 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.
Re: [appengine-java] Re: JDO - I can't update an object with One-to-One Relationships
The update still don't works. I give up. I use the @Persistent(dependent = true) and add the delete instruction when I update the user location, in a transaction. Now it works, but I think it's not very clean/efficient. Have a nice day. public void updateUserLocation(String username, Location newLocation) { PersistenceManager pm = PMF.getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { // Get the user and update the location tx.begin(); POJOUser user = pm.getObjectById(POJOUser.class, username); pm.deletePersistent(user.getLastLocation()); user.setLastLocation(new POJOLocation(newLocation)); tx.commit(); } catch (JDOObjectNotFoundException ex) { } finally { if (tx.isActive()) { tx.rollback(); } pm.close(); } } @PersistenceCapable public class POJOUser { /** Primary key */ @PrimaryKey @Persistent private String key = null; /** Username */ @Persistent private String username = null; /** Password */ @Persistent private String password = null; /** The last location of the user */ @Persistent(dependent = true) private POJOLocation lastLocation = null; ... } @PersistenceCapable public class POJOLocation implements Location { /** Primary key */ @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key = null; /** X */ @Persistent private Double x = null; /** Y */ @Persistent private Double y = null; } -- 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.
Re: [appengine-java] Re: JDO - I can't update an object with One-to-One Relationships
I don't really have to do like that. Your solution is more clean and I will use it. Thanks. But for learning purpose, I've used some others methods. I don't know why i can't update a children reference per another. In fact, the new object is in the datastore. When I manually delete the first reference, the parent now refer his new children. Weird. 2011/1/4 Stephen Johnson onepagewo...@gmail.com Why do you have to delete the location entity? Why not just update the current location entity with the new coordinates? That would be much more efficient. On Tue, Jan 4, 2011 at 10:20 AM, yoyo yoyomo...@gmail.com wrote: The update still don't works. I give up. I use the @Persistent(dependent = true) and add the delete instruction when I update the user location, in a transaction. Now it works, but I think it's not very clean/efficient. Have a nice day. public void updateUserLocation(String username, Location newLocation) { PersistenceManager pm = PMF.getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { // Get the user and update the location tx.begin(); POJOUser user = pm.getObjectById(POJOUser.class, username); pm.deletePersistent(user.getLastLocation()); user.setLastLocation(new POJOLocation(newLocation)); tx.commit(); } catch (JDOObjectNotFoundException ex) { } finally { if (tx.isActive()) { tx.rollback(); } pm.close(); } } @PersistenceCapable public class POJOUser { /** Primary key */ @PrimaryKey @Persistent private String key = null; /** Username */ @Persistent private String username = null; /** Password */ @Persistent private String password = null; /** The last location of the user */ @Persistent(dependent = true) private POJOLocation lastLocation = null; ... } @PersistenceCapable public class POJOLocation implements Location { /** Primary key */ @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key = null; /** X */ @Persistent private Double x = null; /** Y */ @Persistent private Double y = null; } -- 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.comgoogle-appengine-java%2bunsubscr...@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.comgoogle-appengine-java%2bunsubscr...@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: JDO - I can't update an object with One-to-One Relationships
I answer to myself. Before to do the setXXX(), I must delete the previous object. Like this : POJOUser user = pm.getObjectById(POJOUser.class, username); pm.deletePersistent(user.getLastLocation()); user.setLastLocation(new POJOLocation(newLocation)); And now, it works. Moreover, old references are deleted of the store. I hope this tips will help someone. Yoann -- 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] JDO - I can't update an object with One-to-One Relationships
Hello everyone. I've an issue : I can't update a pojo object. I have two classes : A user and a location. A user HAS A location. My servlet do this : 1) create a user without a location, make it persist 2) retrieve a user, set the location (for the first time), make it persist 3) retrieve a user, set a new location, make it persist 4) retrieve a user, show if the position has been updated My issue : On step 4), I see the location initialized the first time. My new position is never saved. More strange, I can see pojo location objects in the DataStore Viewer ( http://localhost:/_ah/admin/datastore) If someone know how to fix it, I'll be grateful. ~Yoann~ Complete source code are in the attached files. A more simple source : Pojos: @PersistenceCapable public class POJOUser { /** Primary key */ @PrimaryKey @Persistent private String key = null; /** Username */ @Persistent private String username = null; /** Password */ @Persistent private String password = null; /** The last location of the user */ @Persistent private POJOLocation lastLocation = null; } @PersistenceCapable public class POJOLocation implements Location { /** Primary key */ @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key = null; /** X */ @Persistent private Double x = null; /** Y */ @Persistent private Double y = null; } PMF : public class DataAccessLayerForGoogleAppEngine implements DataAccessLayer { /** Persistence Manager */ private PersistenceManagerFactory PMF = JDOHelper .getPersistenceManagerFactory(transactions-optional); @Override public void updateUserLocation(String username, Location newLocation) { PersistenceManager pm = PMF.getPersistenceManager(); try { // Get the user POJOUser user = pm.getObjectById(POJOUser.class, username); if (user != null) { // Update the location user.setLastLocation(new POJOLocation(newLocation)); } } catch (JDOObjectNotFoundException ex) { } finally { pm.close(); } } ... } -- 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. package lan.polichouz.tracer.server.impl; import java.util.List; import javax.jdo.JDOHelper; import javax.jdo.JDOObjectNotFoundException; import javax.jdo.PersistenceManager; import javax.jdo.PersistenceManagerFactory; import javax.jdo.Query; import lan.polichouz.tracer.server.DataAccessLayer; import lan.polichouz.tracer.server.Location; import lan.polichouz.tracer.server.impl.pojo.POJOLocation; import lan.polichouz.tracer.server.impl.pojo.POJOUser; /** * Implementation of a Data Access Layer using Google AppEngine framework. * * @author yoyo */ public class DataAccessLayerForGoogleAppEngine implements DataAccessLayer { // TODO user and admin name MUST be unique (primary key). /** Persistence Manager */ private PersistenceManagerFactory PMF = JDOHelper .getPersistenceManagerFactory(transactions-optional); @Override public String getUsernamePassword(String username) { String realPassword = null; PersistenceManager pm = PMF.getPersistenceManager(); try { // Get the user POJOUser user = pm.getObjectById(POJOUser.class, username); if (user != null) { realPassword = user.getPassword(); } } catch (JDOObjectNotFoundException ex) { ex.printStackTrace(); } finally { pm.close(); } return realPassword; } @Override public String getAdminPassword(String adminName) { String realPassword = null; PersistenceManager pm = PMF.getPersistenceManager(); try { // Get the user POJOUser user = pm.getObjectById(POJOUser.class, adminName); if (user != null) { // Get the password realPassword = user.getPassword(); } } catch (JDOObjectNotFoundException ex) { } finally { pm.close(); } return realPassword; } @Override public void updateUserLocation(String username, Location newLocation) { PersistenceManager pm = PMF.getPersistenceManager(); try { // Get the user POJOUser user = pm.getObjectById(POJOUser.class, username); if (user != null) { // Update the location user.setLastLocation(new POJOLocation(newLocation)); //XXX not saved } } catch (JDOObjectNotFoundException ex) { } finally { pm.close(); } } @Override public Location getUserLocation(String username) { Location location = null; PersistenceManager pm = PMF.getPersistenceManager(); try { // Get the user POJOUser user = pm.getObjectById(POJOUser.class, username
Re: [appengine-java] Re: Memory based application, static field, data lost
Thanks for your advices. I'll use the datastore and the blobstore. When I first write my app, I supposed my static field will probably be drop by GAE, because of the non-use of API like memcache or datastore. I try it, for fun and curiosity. It was interesting to understand WHY it was a bad idea to do this. Thanks again for your answear, and have a nice day. 2010/10/27 Simon qila...@gmail.com Yoyo, you are aware that you only have to enable your account as billable and that it doesn't actually cost anything as long as you stay within the free quota? See the Quota page for more info (http:// code.google.com/appengine/docs/quotas.html#Blobstore) On Oct 27, 9:12 am, Ian Marshall ianmarshall...@gmail.com wrote: Indeed. Don't rely on the mem cache to keep your pictures for a long time, since they will eventually be removed from the cache. The datastore is GAE's sole persistent data store (except queued tasks in a non- databasey way), and GAE give us a free amount of storage. On Oct 26, 5:03 pm, nischalshetty nischalshett...@gmail.com wrote: GAE runs multiple instances which means your code would be run on multiple JVMs as well which means the static field will be multiple as well. A lot of as wells here but I hope you get the point. Use statics for constants that do not change. For everything else persist either in memcache or datastore. -N On Oct 26, 4:17 pm, yoyo yoyomo...@gmail.com wrote: Thanks for your answear. So, GOE discard instances in cases of low usage. I didn't know. My app is an image board, like 4chan.org. The blowstore api in only available for billing account. I can't use the blowstore because my app isn't commercial. I write it only for fun and i don't want to pay for it. I'll use the memcache service. It's not important if some of pictures are lost. There is no guarantee, but I hope keep most of pictures into it. Else... well I'll see. I've some refactoring to do. Thanks again for your answear. -- 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.comgoogle-appengine-java%2bunsubscr...@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] Memory based application, static field, data lost
Hello everyone. I've a issue when using my apps. All my logics application data are in memory. For exemple, I've a servlet like this : public class MyServlet { /** Logic application object, create when the class is loaded by the sandbox. */ private static Logics myLogic = new Logics(); /** Handle post request */ protected void doPost( [...]) { myLogic.doStuff([...]); } } The doPost method don't take 30 seconds to be execute. My issue is this : Few minutes after my servlet is loaded and works, I've got a new instance of Logics. I thing AppEngine reload my class. I haven't read about this kind of comportment. Maybe I haven't read the docs enough. Must I use appengine api, like memcache ? Thanks for reading this newbie appengine developer message. Have a nice day. -- 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: Memory based application, static field, data lost
Thanks for your answear. So, GOE discard instances in cases of low usage. I didn't know. My app is an image board, like 4chan.org. The blowstore api in only available for billing account. I can't use the blowstore because my app isn't commercial. I write it only for fun and i don't want to pay for it. I'll use the memcache service. It's not important if some of pictures are lost. There is no guarantee, but I hope keep most of pictures into it. Else... well I'll see. I've some refactoring to do. Thanks again for your answear. -- 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.