1 27 28 package org.objectweb.speedo.runtime.query; 29 30 import org.objectweb.speedo.SpeedoTestHelper; 31 import org.objectweb.speedo.api.ExceptionHelper; 32 import org.objectweb.speedo.pobjects.ref.Employee; 33 import org.objectweb.speedo.pobjects.ref.Department; 34 import org.objectweb.speedo.pobjects.ref.GeoRef; 35 import org.objectweb.speedo.pobjects.collection.AMMB; 36 import org.objectweb.speedo.pobjects.collection.BMMB; 37 import org.objectweb.speedo.pobjects.collection.Group; 38 import org.objectweb.speedo.pobjects.collection.Ref2AMMB; 39 import org.objectweb.speedo.pobjects.collection.Ref2Ref2AMMB; 40 import org.objectweb.speedo.pobjects.collection.User; 41 import org.objectweb.speedo.pobjects.inheritance.query.GroupModerator; 42 import org.objectweb.speedo.pobjects.inheritance.query.GroupUser; 43 import org.objectweb.speedo.pobjects.inheritance.query.MailingList; 44 import org.objectweb.speedo.pobjects.inheritance.query.NewsGroup; 45 import org.objectweb.util.monolog.api.BasicLevel; 46 47 import javax.jdo.PersistenceManager; 48 import javax.jdo.Query; 49 import javax.jdo.JDOException; 50 import java.util.Collection ; 51 import java.util.Iterator ; 52 53 import junit.framework.Assert; 54 55 58 public class PORemover extends SpeedoTestHelper { 59 60 public PORemover(String name) { 61 super(name); 62 } 63 64 protected String getLoggerName() { 65 return LOG_NAME + ".rt.query"; 66 } 67 68 public void testRemovingOfPersistentObject() { 69 PersistenceManager pm = pmf.getPersistenceManager(); 70 try { 71 Class [] cs = new Class []{Employee.class, 72 Department.class, 73 Ref2AMMB.class, 74 Ref2Ref2AMMB.class, 75 AMMB.class, 76 BMMB.class, 77 User.class, 78 Group.class, 79 GeoRef.class, 80 NewsGroup.class, 81 GroupUser.class, 82 MailingList.class, 83 GroupModerator.class}; 84 pm.currentTransaction().begin(); 85 for(int i=0; i<cs.length; i++) { 86 Query query = pm.newQuery(cs[i]); 87 Collection col = (Collection ) query.execute(); 88 Iterator it = col.iterator(); 89 while(it.hasNext()) { 90 Object o = it.next(); 91 Assert.assertNotNull("null object in the query result" 92 + cs[i].getName(), o); 93 if (o instanceof AMMB) { 94 AMMB a = (AMMB) o; 95 a.getBs().clear(); 96 } 97 pm.deletePersistent(o); 98 99 } 100 query.close(col); 101 } 102 pm.currentTransaction().commit(); 103 } catch (JDOException e) { 104 Exception ie = ExceptionHelper.getNested(e); 105 logger.log(BasicLevel.ERROR, "", ie); 106 fail(ie.getMessage()); 107 } finally { 108 pm.close(); 109 } 110 } 111 } 112 | Popular Tags |