KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > collection > PORemover


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

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 JavaDoc;
33 import java.util.Iterator JavaDoc;
34
35 import junit.framework.Assert;
36
37 /**
38  *
39  * @author S.Chassande-Barrioz
40  */

41 public class PORemover extends SpeedoTestHelper {
42
43     public PORemover(String JavaDoc name) {
44         super(name);
45     }
46
47     protected String JavaDoc getLoggerName() {
48         return LOG_NAME + ".rt.query";
49     }
50
51     public void testRemovingOfPersistentObject() {
52         PersistenceManager pm = pmf.getPersistenceManager();
53         try {
54             Class JavaDoc[] cs = new Class JavaDoc[]{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 JavaDoc it = col.iterator();
63                 while(it.hasNext()) {
64                     Object JavaDoc 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 JavaDoc 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