one more doubt similar/related to previous one :
i want to fetch object(s) from datastore, cache it to Memcache and fetch it
from Memcache for further requests. and if any change happens to data i want
to update the object(s) to datastore straight away using cashed instance of
object instead of fetching it (again) form datastore and then updating it.
following is a code snippet:
Data data = cache.get("key");
data.setValue("new updated value");
pm.makePersistent(data);
cache.put("key", data);
thanks.
On Wed, Sep 16, 2009 at 5:49 PM, Prashant <[email protected]> wrote:
> hi,
>
>
> I tried the "Updating an Object" (using detachable property) example given
> here<http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Updating_an_Object>.
> Later I found that even if I do not add *detachable="true" *property to my
> JDO class it works without any problem. Is it ok to work without detachable
> property or it just worked with my case. Following is the code I tried :
>
>
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class Data{
> @SuppressWarnings("unused")
> @PrimaryKey
> @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> private Long id;
>
> @Persistent
> private String value;
>
> public Data(String value){
> this.value = value;
> }
>
> public void setValue(String value){
> this.value = value;
> }
>
> public String getValue(){
> return this.value;
> }
> }
>
>
>
>
> public class Main extends HttpServlet {
>
> public void doGet(HttpServletRequest req, HttpServletResponse resp)
> throws IOException{
> doReq(req, resp);
> }
>
> public void doPost(HttpServletRequest req, HttpServletResponse resp)
> throws IOException{
> doReq(req, resp);
> }
>
> private void doReq(HttpServletRequest req, HttpServletResponse resp)
> throws IOException{
> Data data = new Data("some value");
> PrintWriter out = resp.getWriter();
>
> PersistenceManager pm = PMF.get().getPersistenceManager();
> pm.makePersistent(data);
> pm.close();
>
> chageValue(data);
> out.close();
> }
>
> @SuppressWarnings("unchecked")
> private void chageValue(Data data){
> PersistenceManager pm = PMF.get().getPersistenceManager();
> data.setValue("some other value.");
> pm.makePersistent(data);
> 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 [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
-~----------~----~----~----~------~----~------~--~---