1 18 package org.objectweb.speedo.runtime.collection; 19 20 import org.objectweb.speedo.SpeedoTestHelper; 21 import org.objectweb.speedo.api.ExceptionHelper; 22 import org.objectweb.speedo.pobjects.collection.Ref2AMMB; 23 import org.objectweb.speedo.pobjects.collection.Ref2Ref2AMMB; 24 import org.objectweb.speedo.pobjects.collection.AMMB; 25 import org.objectweb.speedo.pobjects.collection.BMMB; 26 import org.objectweb.speedo.pobjects.collection.AllCollection; 27 import org.objectweb.util.monolog.api.BasicLevel; 28 29 import javax.jdo.PersistenceManager; 30 import javax.jdo.Query; 31 import javax.jdo.JDOException; 32 import java.util.Collection ; 33 import java.util.Iterator ; 34 35 import junit.framework.Assert; 36 37 41 public class PORemover extends SpeedoTestHelper { 42 43 public PORemover(String name) { 44 super(name); 45 } 46 47 protected String getLoggerName() { 48 return LOG_NAME + ".rt.query"; 49 } 50 51 public void testRemovingOfPersistentObject() { 52 PersistenceManager pm = pmf.getPersistenceManager(); 53 try { 54 Class [] cs = new Class []{AllCollection.class, 55 Ref2AMMB.class, 56 Ref2Ref2AMMB.class, 57 AMMB.class, 58 BMMB.class}; 59 for(int i=0; i<cs.length; i++) { 60 Query query = pm.newQuery(cs[i]); 61 Collection col = (Collection) query.execute(); 62 Iterator it = col.iterator(); 63 while(it.hasNext()) { 64 Object o = it.next(); 65 Assert.assertNotNull("null object in the query result" 66 + cs[i].getName(), o); 67 if (o instanceof AMMB) { 68 AMMB a = (AMMB) o; 69 a.getBs().clear(); 70 } 71 pm.currentTransaction().begin(); 72 pm.deletePersistent(o); 73 pm.currentTransaction().commit(); 74 } 75 76 query.close(col); 77 78 } 79 } catch (JDOException e) { 80 Exception ie = ExceptionHelper.getNested(e); 81 logger.log(BasicLevel.ERROR, "", ie); 82 fail(ie.getMessage()); 83 } finally { 84 pm.close(); 85 } 86 } 87 } 88 | Popular Tags |