Package org.odmg

Examples of org.odmg.OQLQuery


        tx.commit();

        // check if gatherer was stored
        tx.begin();
        tx.getBroker().clearCache();
        OQLQuery query = odmg.newOQLQuery();
        query.create(queryStr);
        Integer gatId = gat.getGatId();
        assertNotNull(gatId);
        query.bind(gatId);
        Collection result = (Collection) query.execute();
        tx.commit();

        assertEquals("Wrong number of objects found", 1, result.size());
        Gatherer fetchedGat = (Gatherer) result.iterator().next();
        assertNotNull(fetchedGat.getCollectiblesA());
        assertNotNull(fetchedGat.getCollectiblesB());
        assertEquals(3, fetchedGat.getCollectiblesA().size());
        assertEquals(3, fetchedGat.getCollectiblesB().size());
        assertNotNull(fetchedGat.getCollectiblesA().get(0));
        assertNotNull(fetchedGat.getCollectiblesB().get(0));

        tx.begin();
        tx.getBroker().clearCache();
        //*************************************
        tx.lock(fetchedGat, Transaction.WRITE);
        fetchedGat.getCollectiblesA().remove(0);
        fetchedGat.getCollectiblesB().remove(0);
        //*************************************
        tx.commit();

        tx.begin();
        tx.getBroker().clearCache();
        query = odmg.newOQLQuery();
        query.create(queryStr);
        gatId = gat.getGatId();
        assertNotNull(gatId);
        query.bind(gatId);
        result = (Collection) query.execute();
        tx.commit();
        assertEquals("Wrong number of objects found", 1, result.size());
        fetchedGat = (Gatherer) result.iterator().next();

        assertNotNull(fetchedGat.getCollectiblesA());
View Full Code Here


        db.makePersistent(coll_2);
        tx.commit();

        tx.begin();
        ((TransactionExt)tx).getBroker().clearCache();
        OQLQuery query = odmg.newOQLQuery();
        query.create(queryStr);
        query.bind(name);
        Collection result = (Collection) query.execute();
        assertNotNull(result);
        assertEquals(2, result.size());

        for (Iterator iterator = result.iterator(); iterator.hasNext();)
        {
            CollectibleA collectible = (CollectibleA) iterator.next();
            Gatherer gat = collectible.getGatherer();
            assertNotNull(gat);
            assertEquals("Gatherer_"+name, gat.getName());
            tx.lock(collectible, Transaction.WRITE);
            collectible.getGatherer().setName("New_"+name);
        }
        tx.commit();

        tx.begin();
        ((TransactionExt)tx).getBroker().clearCache();
        query = odmg.newOQLQuery();
        query.create(queryStr);
        query.bind(name);
        result = (Collection) query.execute();
        assertNotNull(result);
        assertEquals(2, result.size());

        for (Iterator iterator = result.iterator(); iterator.hasNext();)
        {
            CollectibleA collectible = (CollectibleA) iterator.next();
            Gatherer gat = collectible.getGatherer();
            assertNotNull(gat);
            assertEquals("New_"+name, gat.getName());
            tx.lock(collectible, Transaction.WRITE);
            collectible.setGatherer(null);
        }
        tx.commit();

        tx.begin();
        ((TransactionExt)tx).getBroker().clearCache();
        query = odmg.newOQLQuery();
        query.create(queryStr);
        query.bind(name);
        result = (Collection) query.execute();
        assertNotNull(result);
        assertEquals(2, result.size());

        for (Iterator iterator = result.iterator(); iterator.hasNext();)
        {
View Full Code Here

        tx.commit();

        tx.begin();
        tx.getBroker().clearCache();
        // check if gatherer was stored
        OQLQuery query = odmg.newOQLQuery();
        query.create(queryStr);
        assertNotNull(gat.getGatId());
        query.bind(gat.getGatId());
        Collection result = (Collection) query.execute();
        tx.commit();
        assertEquals("Wrong number of objects found", 1, result.size());
        Gatherer fetchedGat = (Gatherer) result.iterator().next();

        tx.begin();
        tx.lock(fetchedGat, Transaction.WRITE);
        List collsA = fetchedGat.getCollectiblesA();
        assertEquals(3, collsA.size());
        // now we change an object of the collection
        ((CollectibleA)collsA.get(0)).setName(modifiedName);
        tx.commit();

        tx.begin();
        tx.getBroker().clearCache();
        // now check if the modification was stored
        query = odmg.newOQLQuery();
        query.create(queryMod);
        query.bind(modifiedName);
        result = (Collection) query.execute();
        tx.commit();
        assertEquals("Wrong number of objects found", 1, result.size());
        CollectibleA collA = (CollectibleA) result.iterator().next();
        assertNotNull(collA);
        assertEquals(modifiedName, collA.getName());
View Full Code Here

        tx.commit();

        // query and check the result
        tx.begin();
        tx.getBroker().clearCache();
        OQLQuery query = odmg.newOQLQuery();
        query.create(queryStr);
        assertNotNull(gat.getGatId());
        query.bind(gat.getGatId());
        query.bind(gat2.getGatId());
        Collection result = (Collection) query.execute();
        tx.commit();
        assertEquals("Wrong number of objects found", 2, result.size());
        Iterator it = result.iterator();
        Gatherer fetchedGat = (Gatherer) it.next();
        Gatherer fetchedGat2 = (Gatherer) it.next();
        assertNotNull(fetchedGat);
        assertNotNull(fetchedGat2);
        assertNotNull(fetchedGat.collectiblesC);
        assertNotNull(fetchedGat2.collectiblesC);
        assertEquals(1, fetchedGat.getCollectiblesC().size());
        assertEquals(1, fetchedGat2.getCollectiblesC().size());

        collC_1 = (CollectibleC) fetchedGat.getCollectiblesC().get(0);
        collC_2 = (CollectibleC) fetchedGat2.getCollectiblesC().get(0);
        assertEquals(prefix + "NO_1", collC_1.getName());
        assertEquals(prefix + "NO_2", collC_2.getName());

        //*****************************************************
        List list1 = fetchedGat.getCollectiblesC();
        List list2 = fetchedGat2.getCollectiblesC();
        // now exchange the lists
        tx.begin();
        tx.lock(fetchedGat, Transaction.WRITE);
        tx.lock(fetchedGat2, Transaction.WRITE);
        fetchedGat.setCollectiblesC(list2);
        fetchedGat2.setCollectiblesC(list1);
        tx.commit();
        //*****************************************************

        // now we do same procedure to query and check
        tx.begin();
        tx.getBroker().clearCache();
        query = odmg.newOQLQuery();
        query.create(queryStr);
        assertNotNull(gat.getGatId());
        query.bind(gat.getGatId());
        query.bind(gat2.getGatId());
        result = (Collection) query.execute();
        tx.commit();
        assertEquals("Wrong number of objects found", 2, result.size());
        it = result.iterator();
        fetchedGat = (Gatherer) it.next();
        fetchedGat2 = (Gatherer) it.next();
View Full Code Here

        Transaction tx = odmg.newTransaction();
        tx.begin();
        database.makePersistent(movie);
        tx.commit();

        OQLQuery queryMovie = movieQuery(postfix);
        Collection resultMovie = (Collection) queryMovie.execute();
        assertEquals(1, resultMovie.size());
        Movie newMovie = (Movie) resultMovie.iterator().next();
        assertNotNull(newMovie.getActors());
        assertEquals(3, newMovie.getActors().size());

        OQLQuery queryActor = actorQuery(postfix);
        Collection resultActor = (Collection) queryActor.execute();
        assertEquals(3, resultActor.size());

        OQLQuery queryRole = roleQuery(null, movie);
        Collection resultRole = (Collection) queryRole.execute();
        assertEquals(3, resultRole.size());
    }
View Full Code Here

            database.makePersistent(it.next());
        }
        database.makePersistent(movie);
        tx.commit();

        OQLQuery queryMovie = movieQuery(postfix);
        Collection resultMovie = (Collection) queryMovie.execute();
        assertEquals(1, resultMovie.size());
        Movie newMovie = (Movie) resultMovie.iterator().next();
        assertNotNull(newMovie.getActors());
        assertEquals(3, newMovie.getActors().size());

        OQLQuery queryActor = actorQuery(postfix);
        Collection resultActor = (Collection) queryActor.execute();
        assertEquals(3, resultActor.size());

        OQLQuery queryRole = roleQuery(null, movie);
        Collection resultRole = (Collection) queryRole.execute();
        assertEquals(3, resultRole.size());
    }
View Full Code Here

        Transaction tx = odmg.newTransaction();
        tx.begin();
        database.makePersistent(movie);
        tx.commit();

        OQLQuery queryMovie = movieQuery(postfix);
        Collection resultMovie = (Collection) queryMovie.execute();
        assertEquals(3, resultMovie.size());
        Iterator it = resultMovie.iterator();
        boolean matchActors  = false;
        while(it.hasNext())
        {
            Movie m = (Movie) it.next();
            if(m.getActors() != null)
            {
                boolean expectedSize = m.getActors().size() == 3;
                if(matchActors && expectedSize)
                {
                    fail("Expect only one movie with 3 actors, but found another one");
                }
                matchActors = expectedSize;
            }
        }
        assertTrue(matchActors);

        OQLQuery queryActor = actorQuery(postfix);
        Collection resultActor = (Collection) queryActor.execute();
        assertEquals(3, resultActor.size());
        it = resultActor.iterator();
        boolean matchMovies  = false;
        while(it.hasNext())
        {
            Actor a = (Actor) it.next();
            if(a.getMovies() != null)
            {
                boolean expectedSize = a.getMovies().size() == 3;
                if(matchMovies && expectedSize)
                {
                    fail("Expect only one actor with 3 movies, but found another one");
                }
                matchMovies = expectedSize;
            }
        }
        assertTrue(matchMovies);

        OQLQuery queryRole = roleQuery(null, movie);
        Collection resultRole = (Collection) queryRole.execute();
        assertEquals(5, resultRole.size());
    }
View Full Code Here

            database.makePersistent(it.next());
        }
        database.makePersistent(movie);
        tx.commit();

        OQLQuery queryMovie = movieQuery(postfix);
        Collection resultMovie = (Collection) queryMovie.execute();
        assertEquals(3, resultMovie.size());
        it = resultMovie.iterator();
        boolean matchActors  = false;
        while(it.hasNext())
        {
            Movie m = (Movie) it.next();
            if(m.getActors() != null)
            {
                boolean expectedSize = m.getActors().size() == 3;
                if(matchActors && expectedSize)
                {
                    fail("Expect only one movie with 3 actors, but found another one");
                }
                matchActors = expectedSize;
            }
        }
        assertTrue(matchActors);

        OQLQuery queryActor = actorQuery(postfix);
        Collection resultActor = (Collection) queryActor.execute();
        assertEquals(3, resultActor.size());
        it = resultActor.iterator();
        boolean matchMovies  = false;
        while(it.hasNext())
        {
            Actor a = (Actor) it.next();
            if(a.getMovies() != null)
            {
                boolean expectedSize = a.getMovies().size() == 3;
                if(matchMovies && expectedSize)
                {
                    fail("Expect only one actor with 3 movies, but found another one");
                }
                matchMovies = expectedSize;
            }
        }
        assertTrue(matchMovies);

        OQLQuery queryRole = roleQuery(null, movie);
        Collection resultRole = (Collection) queryRole.execute();
        assertEquals(5, resultRole.size());
    }
View Full Code Here

            database.makePersistent(it.next());
        }
        database.makePersistent(movie);
        tx.commit();

        OQLQuery queryMovie = movieQuery(postfix);
        Collection resultMovie = (Collection) queryMovie.execute();
        assertEquals(1, resultMovie.size());
        Movie newMovie = (Movie) resultMovie.iterator().next();
        assertNotNull(newMovie.getActors());
        assertEquals(3, newMovie.getActors().size());

        OQLQuery queryActor = actorQuery(postfix);
        Collection resultActor = (Collection) queryActor.execute();
        assertEquals(3, resultActor.size());

        OQLQuery queryRole = roleQuery(null, movie);
        Collection resultRole = (Collection) queryRole.execute();
        assertEquals(3, resultRole.size());

        tx.begin();
        queryMovie = movieQuery(postfix);
        resultMovie = (Collection) queryMovie.execute();
        Movie m = (Movie) resultMovie.iterator().next();
        assertNotNull(m);
        //**********************************************
        tx.lock(m, Transaction.WRITE);
        it = m.getActors().iterator();
        /*
        we expect that the entry in indirection table was removed
        AND the Actor object itself will be deleted
        */
        database.deletePersistent(it.next());
        //*********************************************
        tx.commit();

        tx.begin();
        tx.getBroker().clearCache();
        //tx.commit();

        queryMovie = movieQuery(postfix);
        resultMovie = (Collection) queryMovie.execute();
        assertEquals(1, resultMovie.size());
        newMovie = (Movie) resultMovie.iterator().next();
        assertNotNull(newMovie.getActors());
        assertEquals(2, newMovie.getActors().size());

        queryActor = actorQuery(postfix);
        resultActor = (Collection) queryActor.execute();
        assertEquals(2, resultActor.size());

        queryRole = roleQuery(null, movie);
        resultRole = (Collection) queryRole.execute();
        assertEquals(2, resultRole.size());

        tx.commit();
    }
View Full Code Here

            database.makePersistent(it.next());
        }
        database.makePersistent(movie);
        tx.commit();

        OQLQuery queryMovie = movieQuery(postfix);
        Collection resultMovie = (Collection) queryMovie.execute();
        assertEquals(1, resultMovie.size());
        Movie newMovie = (Movie) resultMovie.iterator().next();
        assertNotNull(newMovie.getActors());
        assertEquals(3, newMovie.getActors().size());

        OQLQuery queryActor = actorQuery(postfix);
        Collection resultActor = (Collection) queryActor.execute();
        assertEquals(3, resultActor.size());

        OQLQuery queryRole = roleQuery(null, movie);
        Collection resultRole = (Collection) queryRole.execute();
        assertEquals(3, resultRole.size());

        tx.begin();
        tx.getBroker().clearCache();

        queryMovie = movieQuery(postfix);
        resultMovie = (Collection) queryMovie.execute();
        assertEquals(1, resultMovie.size());
        Movie m = (Movie) resultMovie.iterator().next();
        assertNotNull(m);
        Collection actors = m.getActors();
        assertEquals(3, actors.size());
        //***************************************
        tx.lock(m, Transaction.WRITE);
        /*
        now remove an association between Movie ans Actor
        we expect that the entry in indirection class will be removed,
        but the Actor entry should be still there
        */
        Iterator iter = actors.iterator();
        iter.next();
        iter.remove();
        //***************************************
        tx.commit();

        tx.begin();
        tx.getBroker().clearCache();
        //tx.commit();

        queryMovie = movieQuery(postfix);
        resultMovie = (Collection) queryMovie.execute();
        assertEquals(1, resultMovie.size());
        newMovie = (Movie) resultMovie.iterator().next();
        assertNotNull(newMovie.getActors());
        assertEquals(2, newMovie.getActors().size());

        queryRole = roleQuery(null, movie);
        resultRole = (Collection) queryRole.execute();
        assertEquals(2, resultRole.size());

        // we only remove the association
        queryActor = actorQuery(postfix);
        resultActor = (Collection) queryActor.execute();
View Full Code Here

TOP

Related Classes of org.odmg.OQLQuery

Copyright © 2018 www.massapicom. 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.