Package org.odmg

Examples of org.odmg.OQLQuery


        }
        tx.commit();

        tx.begin();
        // query test objects
        OQLQuery q = odmg.newOQLQuery();
        q.create("select all from "+DObject.class.getName()+" where name=$1");
        q.bind(name);
        Collection ret = (Collection) q.execute();
        // check result list size
        assertEquals(5, ret.size());
        // do read lock
        for (Iterator it = ret.iterator(); it.hasNext(); )
        {
View Full Code Here


        tx.commit();
        // check if gatherer was stored
        tx.begin();
        tx.getBroker().clearCache();
        assertNotNull(gat.getGatId());
        OQLQuery query = odmg.newOQLQuery();
        query.create(queryGat);
        query.bind(gat.getGatId());
        Collection result = (Collection) query.execute();
        tx.commit();
        assertEquals("Wrong number of objects found", 1, result.size());
        gat = (Gatherer) result.iterator().next();
        assertNotNull(gat);
        //**********************************************
        CollectibleC child = new CollectibleC(prefix, null, "a new CollectibleC");
        tx.begin();
        tx.lock(gat, Transaction.WRITE);
        tx.lock(child, Transaction.WRITE);
        List childs = new ArrayList();
        childs.add(child);
        gat.setCollectiblesC(childs);
        tx.commit();
        //**********************************************
        // check if gatherer was stored
        tx.begin();
        tx.getBroker().clearCache();
        assertNotNull(gat.getGatId());
        query = odmg.newOQLQuery();
        query.create(queryGat);
        query.bind(gat.getGatId());
        result = (Collection) query.execute();
        tx.commit();
        assertEquals("Wrong number of objects found", 1, result.size());
        gat = (Gatherer) result.iterator().next();
        assertNotNull(gat);
        assertNotNull(gat.getCollectiblesC());
View Full Code Here

        // check if gatherer was stored
        tx.begin();
        tx.getBroker().clearCache();
        assertNotNull(gat.getGatId());

        OQLQuery query = odmg.newOQLQuery();
        query.create(queryGat);
        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();
        assertNotNull(fetchedGat);

        // check if gatherer contains list of CollectibleBase
        List colC = fetchedGat.getCollectiblesC();
        assertEquals("Wrong number of CollectiblesC", 3, colC.size());

        tx.begin();
        //*************************************
        tx.lock(fetchedGat, Transaction.WRITE);
        // Remove collection object
        Object toDelete = fetchedGat.getCollectiblesC().remove(0);
        // explicit persistent delete call needed
        database.deletePersistent(toDelete);
        // alternative use TransactionExt#autoDeleteRemovedCollectionReferences
        //*************************************
        tx.commit();

        // check if the Collectibles were really deleted from DB
        tx.begin();
        tx.getBroker().clearCache();

        query = odmg.newOQLQuery();
        query.create("select colls from " + CollectibleC.class.getName() +
                " where name like $1");
        query.bind(prefix + "%");
        result = (Collection) query.execute();

        assertEquals("Wrong number of objects found", 2, result.size());
        tx.commit();

        // check if the gatherer now contains a CollectibleBase list
        // increased by the added
        tx.begin();
        tx.getBroker().clearCache();
        query = odmg.newOQLQuery();
        query.create(queryGat);
        query.bind(gat.getGatId());
        result = (Collection) query.execute();
        assertEquals("Wrong number of objects found", 1, result.size());
        fetchedGat = (Gatherer) result.iterator().next();
        colC = fetchedGat.getCollectiblesC();
        assertEquals("Wrong number of CollectiblesA found in Gatherer", 2, colC.size());
        tx.commit();
View Full Code Here

        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();

        List colsA = fetchedGat.getCollectiblesA();
        assertEquals("Wrong number of CollectiblesA", 3, colsA.size());
        // check if gatherer contains list of CollectibleBase
        tx.begin();
        //*************************************
        // delete one of the CollectibleBase
        // we have to set the new reduced list in the
        // gatherer object
        List newCols = new ArrayList();
        newCols.add(colsA.get(1));
        newCols.add(colsA.get(2));
        fetchedGat.setCollectiblesA(newCols);
        tx.lock(fetchedGat, Transaction.WRITE);
        // todo: do we need to delete removed reference explicit?
        database.deletePersistent(colsA.get(0));
        //*************************************
        tx.commit();

        // check if the CollectibleBase was really deleted from DB
        tx.begin();
        query = odmg.newOQLQuery();
        query.create("select allCollectibleA from " + CollectibleA.class.getName() +
                " where name like $1");
        query.bind(prefix + "%");
        result = (Collection) query.execute();
        assertEquals("Wrong number of objects found", 2, result.size());
        tx.commit();

        // check if the gatherer now contains a CollectibleBase list
        // reduced by the deleted
        tx.begin();
        query = odmg.newOQLQuery();
        query.create(queryStr);
        query.bind(gatId);
        result = (Collection) query.execute();
        assertEquals("Wrong number of objects found", 1, result.size());
        fetchedGat = (Gatherer) result.iterator().next();
        colsA = fetchedGat.getCollectiblesA();
        assertEquals("Wrong number of CollectiblesA found in Gatherer", 2, colsA.size());
        tx.commit();
View Full Code Here

        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();

        assertEquals("Wrong number of objects found", 1, result.size());
        Gatherer fetchedGat = (Gatherer) result.iterator().next();
        //*************************************
        tx.lock(fetchedGat, Transaction.WRITE);
        assertNotNull(fetchedGat.getCollectiblesA());
        assertNotNull(fetchedGat.getCollectiblesB());
        assertEquals(3, fetchedGat.getCollectiblesA().size());
        assertEquals(3, fetchedGat.getCollectiblesB().size());
        assertEquals(0, fetchedGat.getCollectiblesC().size());
        assertNotNull(fetchedGat.getCollectiblesA().get(0));
        assertNotNull(fetchedGat.getCollectiblesB().get(0));

        fetchedGat.getCollectiblesA().remove(0);
        fetchedGat.getCollectiblesB().remove(0);
        //*************************************
        //System.out.println("===> commit");
        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

//System.out.println();

        // 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());
        assertEquals(0, fetchedGat.getCollectiblesC().size());
        assertNotNull(fetchedGat.getCollectiblesA().get(0));
        assertNotNull(fetchedGat.getCollectiblesB().get(0));
//System.out.println("A: " + fetchedGat.getCollectiblesA());
//System.out.println("B: " + fetchedGat.getCollectiblesB());
//        for(int i = 0; i < fetchedGat.getCollectiblesB().size(); i++)
//        {
//            System.out.println("  b="+fetchedGat.getCollectiblesB().get(i));
//        }
//System.out.println();
//System.out.println();
//System.out.println("## New tx begin");
        tx.begin();
        tx.getBroker().clearCache();
        //*************************************
        tx.lock(fetchedGat, Transaction.WRITE);
        // we want automatic delete of removed collection objects
        //tx.autoDeleteRemovedCollectionReferences(true);
        // alternative do explicit call Database#deletePersistent for removed objects
        // fetchedGat.getCollectiblesA().remove(0)
        // fetchedGat.getCollectiblesB().remove(0);
tx.getBroker().serviceObjectCache().cache(tx.getBroker().serviceIdentity().buildIdentity(fetchedGat), fetchedGat);
//System.out.println("remove: " + tx.getBroker().serviceIdentity().buildIdentity(fetchedGat.getCollectiblesA().remove(0)));
//System.out.println("remove: " + tx.getBroker().serviceIdentity().buildIdentity(fetchedGat.getCollectiblesB().remove(0)));
//System.out.println("A: " + fetchedGat.getCollectiblesA());
//System.out.println("B: " + fetchedGat.getCollectiblesB());
//System.out.println("===> commit after remove");
//System.out.println("===> commit after remove");
        //*************************************
        tx.commit();
//System.out.println("after commit <==");
//System.out.println("after commit <==");
//System.out.println("");System.out.println();

        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

        database.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());

        // we don't want that Gatherer does some cascade delete
        tx.setCascadingDelete(Gatherer.class, false);
        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);
            gat.getCollectiblesA().remove(collectible);
        }
        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);
        assertEquals("Wrong gatherer returned: fetchedGat should be first Gatherer",
                gat1Name, fetchedGat.getName());
        assertEquals("Wrong gatherer returned: fetchedGat2 should be second Gatherer",
                gat2Name, fetchedGat2.getName());
        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);
        // System.out.println("#####===> start commit");
        tx.commit();
        //*****************************************************
        // System.out.println("#####===> end 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

        // check if gatherer was stored
        tx.begin();
        tx.getBroker().clearCache();
        assertNotNull(gat.getGatId());

        OQLQuery query = odmg.newOQLQuery();
        query.create(queryGat);
        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();
        assertNotNull(fetchedGat);

        List colC = fetchedGat.getCollectiblesC();
        assertEquals("Wrong number of CollectiblesC", 3, colC.size());
        // check if gatherer contains list of CollectibleBase
        tx.begin();
        //**********************************************************
        // we replace the collection of main object with a new collection
        // reduced by one element
        List newCols = new ArrayList(colC);
        Object toDelete = newCols.remove(2);
        // lock object before do changes
        tx.lock(fetchedGat, Transaction.WRITE);
        fetchedGat.setCollectiblesC(newCols);
        // todo: we need to delete removed object explicit?
        database.deletePersistent(toDelete);
        //**********************************************************
        tx.commit();

        // check if the Collectibles were really deleted from DB
        tx.begin();
        tx.getBroker().clearCache();

        query = odmg.newOQLQuery();
        query.create("select colls from " + CollectibleC.class.getName() +
                " where name like $1");
        query.bind(prefix + "%");
        result = (Collection) query.execute();
        assertEquals("Wrong number of objects found", 2, result.size());
        tx.commit();

        // check if the gatherer now contains a CollectibleBase list
        // reduced by the deleted
        tx.begin();
        query = odmg.newOQLQuery();
        query.create(queryGat);
        query.bind(gat.getGatId());
        result = (Collection) query.execute();
        assertEquals("Wrong number of objects found", 1, result.size());
        fetchedGat = (Gatherer) result.iterator().next();
        colC = fetchedGat.getCollectiblesC();
        assertEquals("Wrong number of CollectiblesA found in Gatherer", 2, colC.size());
        tx.commit();
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.