Package org.objectweb.speedo.runtime.query

Source Code of org.objectweb.speedo.runtime.query.PORemover

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

package org.objectweb.speedo.runtime.query;

import org.objectweb.speedo.SpeedoTestHelper;
import org.objectweb.speedo.api.ExceptionHelper;
import org.objectweb.speedo.pobjects.ref.Employee;
import org.objectweb.speedo.pobjects.ref.Department;
import org.objectweb.speedo.pobjects.ref.GeoRef;
import org.objectweb.speedo.pobjects.collection.AMMB;
import org.objectweb.speedo.pobjects.collection.BMMB;
import org.objectweb.speedo.pobjects.collection.Group;
import org.objectweb.speedo.pobjects.collection.Ref2AMMB;
import org.objectweb.speedo.pobjects.collection.Ref2Ref2AMMB;
import org.objectweb.speedo.pobjects.collection.User;
import org.objectweb.speedo.pobjects.inheritance.query.GroupModerator;
import org.objectweb.speedo.pobjects.inheritance.query.GroupUser;
import org.objectweb.speedo.pobjects.inheritance.query.MailingList;
import org.objectweb.speedo.pobjects.inheritance.query.NewsGroup;
import org.objectweb.util.monolog.api.BasicLevel;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.JDOException;
import java.util.Collection;
import java.util.Iterator;

import junit.framework.Assert;

/**
*
*/
public class PORemover extends SpeedoTestHelper {

    public PORemover(String name) {
        super(name);
    }

    protected String getLoggerName() {
        return LOG_NAME + ".rt.query";
    }

    public void testRemovingOfPersistentObject() {
        PersistenceManager pm = pmf.getPersistenceManager();
        try {
            Class[] cs = new Class[]{Employee.class,
                                     Department.class,
                                     Ref2AMMB.class,
                                     Ref2Ref2AMMB.class,
                                     AMMB.class,
                                     BMMB.class,
                                     User.class,
                                     Group.class,
                   GeoRef.class,
                   NewsGroup.class,
                   GroupUser.class,
                   MailingList.class,
                   GroupModerator.class};
          pm.currentTransaction().begin();
            for(int i=0; i<cs.length; i++) {
                Query query = pm.newQuery(cs[i]);
                Collection col = (Collection) query.execute();
                Iterator it = col.iterator();
                while(it.hasNext()) {
                    Object o = it.next();
                    Assert.assertNotNull("null object in the query result"
                        + cs[i].getName(), o);
                    if (o instanceof AMMB) {
                        AMMB a = (AMMB) o;
                        a.getBs().clear();
                    }
                    pm.deletePersistent(o);

                }
                query.close(col);
            }
          pm.currentTransaction().commit();
        } catch (JDOException e) {
            Exception ie = ExceptionHelper.getNested(e);
            logger.log(BasicLevel.ERROR, "", ie);
            fail(ie.getMessage());
        } finally {
            pm.close();
        }
    }
}
TOP

Related Classes of org.objectweb.speedo.runtime.query.PORemover

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.