Package org.apache.ojb.jdo

Source Code of org.apache.ojb.jdo.TestQueries

package org.apache.ojb.jdo;

import java.util.Collection;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import junit.framework.TestCase;

import org.apache.ojb.otm.Person;

/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


public class TestQueries extends TestCase
{
    private PersistenceManagerFactoryImpl factory = new PersistenceManagerFactoryImpl();

    private PersistenceManager pm;

    public void setUp()
    {
        this.pm = factory.getPersistenceManager();
    }

    public void tearDown()
    {
        if (!this.pm.isClosed()) this.pm.close();
    }

    public void testEmptyFilter()
    {
        Person p = new Person("George", "Harrison");
        pm.currentTransaction().begin();
        pm.makePersistent(p);
        pm.currentTransaction().commit();

        pm.evictAll();

        pm.currentTransaction().begin();
        Query q = pm.newQuery(Person.class);
        Collection results = (Collection) q.execute();
        assertTrue(results.size() > 0);
        assertTrue(results.iterator().next() instanceof Person);
        pm.currentTransaction().commit();
    }

    public void testEmptyFilterSettingExtent()
    {
        Person p = new Person("George", "Harrison");
        pm.currentTransaction().begin();
        pm.makePersistent(p);
        pm.currentTransaction().commit();

        pm.evictAll();

        pm.currentTransaction().begin();
        Query q = pm.newQuery();
        q.setCandidates(pm.getExtent(Person.class, true));
        Collection results = (Collection) q.execute();
        assertTrue(results.size() > 0);
        assertTrue(results.iterator().next() instanceof Person);
        pm.currentTransaction().commit();
    }

    public void testClonedQuery()
    {
        Person p = new Person("George", "Harrison");
        pm.currentTransaction().begin();
        pm.makePersistent(p);
        pm.currentTransaction().commit();

        pm.evictAll();

        pm.currentTransaction().begin();
        Query q = pm.newQuery(Person.class);
        q.compile();
        Query q2 = pm.newQuery(q);
        Collection r = (Collection) q2.execute();
        assertTrue(r.size() > 0);
        assertTrue(r.iterator().next() instanceof Person);
        pm.currentTransaction().commit();
    }
}
TOP

Related Classes of org.apache.ojb.jdo.TestQueries

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.