001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2004 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: * Authors: S.Chassande-Barrioz.
025: *
026: */package org.objectweb.speedo.runtime.query;
027:
028: import org.objectweb.speedo.SpeedoTestHelper;
029: import org.objectweb.speedo.api.ExceptionHelper;
030: import org.objectweb.speedo.pobjects.ref.Employee;
031: import org.objectweb.speedo.pobjects.ref.Department;
032: import org.objectweb.speedo.pobjects.ref.GeoRef;
033: import org.objectweb.speedo.pobjects.collection.AMMB;
034: import org.objectweb.speedo.pobjects.collection.BMMB;
035: import org.objectweb.speedo.pobjects.collection.Group;
036: import org.objectweb.speedo.pobjects.collection.Ref2AMMB;
037: import org.objectweb.speedo.pobjects.collection.Ref2Ref2AMMB;
038: import org.objectweb.speedo.pobjects.collection.User;
039: import org.objectweb.speedo.pobjects.inheritance.query.GroupModerator;
040: import org.objectweb.speedo.pobjects.inheritance.query.GroupUser;
041: import org.objectweb.speedo.pobjects.inheritance.query.MailingList;
042: import org.objectweb.speedo.pobjects.inheritance.query.NewsGroup;
043: import org.objectweb.util.monolog.api.BasicLevel;
044:
045: import javax.jdo.PersistenceManager;
046: import javax.jdo.Query;
047: import javax.jdo.JDOException;
048: import java.util.Collection;
049: import java.util.Iterator;
050:
051: import junit.framework.Assert;
052:
053: /**
054: *
055: */
056: public class PORemover extends SpeedoTestHelper {
057:
058: public PORemover(String name) {
059: super (name);
060: }
061:
062: protected String getLoggerName() {
063: return LOG_NAME + ".rt.query";
064: }
065:
066: public void testRemovingOfPersistentObject() {
067: PersistenceManager pm = pmf.getPersistenceManager();
068: try {
069: Class[] cs = new Class[] { Employee.class,
070: Department.class, Ref2AMMB.class,
071: Ref2Ref2AMMB.class, AMMB.class, BMMB.class,
072: User.class, Group.class, GeoRef.class,
073: NewsGroup.class, GroupUser.class,
074: MailingList.class, GroupModerator.class };
075: pm.currentTransaction().begin();
076: for (int i = 0; i < cs.length; i++) {
077: Query query = pm.newQuery(cs[i]);
078: Collection col = (Collection) query.execute();
079: Iterator it = col.iterator();
080: while (it.hasNext()) {
081: Object o = it.next();
082: Assert.assertNotNull(
083: "null object in the query result"
084: + cs[i].getName(), o);
085: if (o instanceof AMMB) {
086: AMMB a = (AMMB) o;
087: a.getBs().clear();
088: }
089: pm.deletePersistent(o);
090:
091: }
092: query.close(col);
093: }
094: pm.currentTransaction().commit();
095: } catch (JDOException e) {
096: Exception ie = ExceptionHelper.getNested(e);
097: logger.log(BasicLevel.ERROR, "", ie);
098: fail(ie.getMessage());
099: } finally {
100: pm.close();
101: }
102: }
103: }
|