db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbeams <cbe...@gmail.com>
Subject Re: 2.1 Spec: detached-dirty parameters to makePersistent() when DetachAllOnCommit=true
Date Mon, 06 Aug 2007 05:09:40 GMT
My previous email on this topic was a bit verbose, and I later  
realized contained some inaccuracies.  Keeping things as succinct as  
possible, is there any reason the spec couldn't be amended to support  
the following code?


package com.xyz;

import org.apache.log4j.Logger;

import javax.jdo.*;
import static javax.jdo.JDOHelper.*;


public class Main {
     public static final Logger logger = Logger.getLogger(Main.class);

     public static void main(String... args) {
         PersistenceManagerFactory pmf =
             JDOHelper.getPersistenceManagerFactory("jpox.properties");
         PersistenceManager pm = pmf.getPersistenceManager();

         assert pm.getDetachAllOnCommit() == true;

         A parameter = new A();
         A returned;

         logger.info("making newly created parameter instance  
persistent");
         pm.currentTransaction().begin();
         returned = pm.makePersistent(parameter);
         pm.currentTransaction().commit();

         assert parameter == returned;
         assert isDetached(parameter) && !isDirty(parameter);

         logger.info("dirtying parameter instance");
         parameter.setName("mud");
         assert isDetached(parameter) && isDirty(parameter);

         logger.info("reattaching dirtied parameter instance");
         pm.currentTransaction().begin();
         returned = pm.makePersistent(parameter);
         pm.currentTransaction().commit();

         // these assertions currently fail
         assert parameter == returned;
         assert isDetached(parameter) && !isDirty(parameter);
     }
}


@javax.jdo.annotations.PersistenceCapable(detachable = "true")
class A {
     private String name;
     public void setName(String name) { this.name = name; }
}


Thanks,

- Chris Beams




Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message