surinder-insonix / datanucleus-appengine

Automatically exported from code.google.com/p/datanucleus-appengine
0 stars 0 forks source link

Can still retrieve a P_DELETED object via getObjectById when deleted non-transactional #227

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, 
I have this test (I am creating object, persist it and trying to 
remove it) and it is failing on "fail("not supposed to get here");" 
line. Is it bug in GAE JDO or JDO is supposed to work in this way? 

Lines from test:

private final LocalServiceTestHelper helper = new 
LocalServiceTestHelper( 
                        new LocalDatastoreServiceTestConfig()); 
@Before 
        public void setUp() { 
                helper.setUp(); 
        } 
        @After 
        public void tearDown() { 
                helper.tearDown(); 
        } 
@Test 
        public void testBasicDelete() { 
                Properties newProperties = new Properties(); 
                newProperties 
                                .put("javax.jdo.PersistenceManagerFactoryClass", 
                                                "org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory" ); 
                newProperties.put("javax.jdo.option.ConnectionURL", "appengine"); 
                newProperties.put("javax.jdo.option.NontransactionalRead", "true"); 
                newProperties.put("javax.jdo.option.NontransactionalWrite", "true"); 
                newProperties.put("javax.jdo.option.RetainValues", "true"); 
                newProperties.put("datanucleus.appengine.autoCreateDatastoreTxns", 
                                "true"); 
                newProperties.put("datanucleus.appengine.autoCreateDatastoreTxns", 
                                "true"); 
                PersistenceManagerFactory pmf = JDOHelper 
                                .getPersistenceManagerFactory(newProperties); 
                PersistenceManager pm = pmf.getPersistenceManager(); 
                JDOMockBasicObject m = new JDOMockBasicObject(); 
                pm.makePersistent(m); 
                long id = m.getId(); 
                assertTrue(id > 0); 
                JDOMockBasicObject k = (JDOMockBasicObject) pm.getObjectById( 
                                JDOMockBasicObject.class, id); 
                pm.deletePersistent(k); 
                Query query = pm.newQuery(JDOMockBasicObject.class); 
                query.setFilter("key == k"); 
                query.declareParameters("com.google.appengine.api.datastore.Key k"); 
                query.deletePersistentAll(k.getKey()); 
                try { 
                        JDOMockBasicObject l = (JDOMockBasicObject) pm.getObjectById( 
                                        JDOMockBasicObject.class, id); 
                        fail("not supposed to get here"); 
                } catch (JDOObjectNotFoundException e) { 
                } 
        } 
// Mock class: 
import javax.jdo.annotations.IdGeneratorStrategy; 
import javax.jdo.annotations.PersistenceCapable; 
import javax.jdo.annotations.Persistent; 
import javax.jdo.annotations.PrimaryKey; 
import com.google.appengine.api.datastore.Key; 
@PersistenceCapable 
public class JDOMockBasicObject { 
        @PrimaryKey 
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 
        private Key key; 
        public Long getId(){ 
                return key.getId(); 
        } 
        public Key getKey(){ 
                return key; 
        } 

Original issue reported on code.google.com by tadas.subonis@gmail.com on 28 Feb 2011 at 3:20

GoogleCodeExporter commented 8 years ago
And if you call pm.evictAll() after the deletePersistent() then it isn't in the 
L1 cache (in state P_DELETED), and consequently you don't find it. Ample 
workarounds

Original comment by googleco...@yahoo.co.uk on 15 Jul 2011 at 2:11

GoogleCodeExporter commented 8 years ago
Actually, when SVN trunk is run with current DataNucleus any nontx deleted 
objects are no longer in the L1 cache, so no object is found from getObjectById

Original comment by googleco...@yahoo.co.uk on 15 Jul 2011 at 3:26