KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  * Authors: S.Chassande-Barrioz.
25  *
26  */

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 JavaDoc;
51 import java.util.Iterator JavaDoc;
52
53 import junit.framework.Assert;
54
55 /**
56  *
57  */

58 public class PORemover extends SpeedoTestHelper {
59
60     public PORemover(String JavaDoc name) {
61         super(name);
62     }
63
64     protected String JavaDoc getLoggerName() {
65         return LOG_NAME + ".rt.query";
66     }
67
68     public void testRemovingOfPersistentObject() {
69         PersistenceManager pm = pmf.getPersistenceManager();
70         try {
71             Class JavaDoc[] cs = new Class JavaDoc[]{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 JavaDoc col = (Collection JavaDoc) query.execute();
88                 Iterator JavaDoc it = col.iterator();
89                 while(it.hasNext()) {
90                     Object JavaDoc 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 JavaDoc 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