Package org.odmg

Examples of org.odmg.OQLQuery


    private void deleteData(Class target)
      throws Exception
  {
    Transaction tx = odmg.newTransaction();
    tx.begin();
    OQLQuery query = odmg.newOQLQuery();
    query.create("select allStuff from " + target.getName());
    Collection allTargets = (Collection) query.execute();
    Iterator it = allTargets.iterator();
    while (it.hasNext())
    {
      database.deletePersistent(it.next());
    }
View Full Code Here


    int fatherID = 13;
    PersonImpl jimmy = new PersonImpl();
    PersonImpl joe = new PersonImpl();
    PersonImpl father = new PersonImpl();
    PersonImpl mother = new PersonImpl();
        OQLQuery query;
        List persons;

    mother.setId(motherID);
    father.setId(fatherID);
    mother.setFirstname("mom");
    father.setFirstname("dad");

    jimmy.setMother(mother);
    jimmy.setFirstname("jimmy");
    jimmy.setId(jimmyID);

    joe.setFather(father);
    joe.setFirstname("joe");
    joe.setId(joeID);

    Transaction tx = odmg.newTransaction();
    tx.begin();
    database.makePersistent(father);
    database.makePersistent(mother);
    database.makePersistent(jimmy);
    database.makePersistent(joe);
    tx.commit();

        // read using id
    tx = odmg.newTransaction();
    tx.begin();
    query = odmg.newOQLQuery();
    query.create("select person from " + PersonImpl.class.getName() +
           " where (mother.id=$1 or father.id=$2)");
    query.bind(new Integer(motherID));
    query.bind(new Integer(fatherID));
    persons = (List) query.execute();
        assertEquals(2, persons.size());
    tx.commit();

        // read using firstname
        tx = odmg.newTransaction();
        tx.begin();
        query = odmg.newOQLQuery();
        query.create("select person from " + PersonImpl.class.getName() +
                     " where (mother.firstname=$1 or father.firstname=$2)");
        query.bind("mom");
        query.bind("dad");
        persons = (List) query.execute();
        assertEquals(2, persons.size());
        tx.commit();
  }
View Full Code Here

    database.makePersistent(b2);
    tx.commit();
    tx = odmg.newTransaction();
    tx.begin();
    // get the right values
    OQLQuery query = odmg.newOQLQuery();
    query.create("select a from " + TestClassA.class.getName());
    List As = (List) query.execute();
    Iterator asIterator = As.iterator();
    TestClassA temp = null;

    temp = (TestClassA) asIterator.next();
    String bID1 = temp.getB().getOid();
    temp = (TestClassA) asIterator.next();
    String bID2 = temp.getB().getOid();

    query = odmg.newOQLQuery();
    query.create("select a from " + TestClassA.class.getName() +
           " where (b.oid=$1 or b.oid=$2)");
    query.bind(bID1);
    query.bind(bID2);
    As = (List) query.execute();
    assertTrue(As.size() == 2);
    tx.commit();
  }
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();
        newCols.add(colC.get(1));
        newCols.add(colC.get(2));
        // lock object before do changes
        tx.lock(fetchedGat, Transaction.WRITE);
        fetchedGat.setCollectiblesA(newCols);
        // todo: we need to delete removed object explicit?
        db.deletePersistent(colC.get(0));
        //**********************************************************
        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

        // 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);
        // Now add a new collection object
        CollectibleC newC = new CollectibleC(prefix, null, "### new added ###");
        fetchedGat.getCollectiblesC().add(newC);
        newC.setGathererId(fetchedGat.getGatId());
        tx.lock(newC, Transaction.WRITE);
        //*************************************
        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", 4, 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", 4, colC.size());
        tx.commit();
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);


        tx.begin();
        // check if gatherer contains list of CollectibleBase
        List colB = fetchedGat.getCollectiblesB();
        assertEquals("Wrong number of CollectiblesB", 3, colB.size());

        //*************************************
        tx.lock(fetchedGat, Transaction.WRITE);
        // Now add a new collection object
        CollectibleB newB = new CollectibleB(prefix);
        newB.setGatherer(fetchedGat);
        fetchedGat.getCollectiblesB().add(newB);
        // lock the new object
        tx.lock(newB, Transaction.WRITE);
        //*************************************

        tx.commit();

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

        query = odmg.newOQLQuery();
        query.create("select colls from " + CollectibleB.class.getName() +
                " where name like $1");
        query.bind(prefix + "%");
        result = (Collection) query.execute();
        assertEquals("Wrong number of objects found", 4, 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();
        colB = fetchedGat.getCollectiblesB();
        assertEquals("Wrong number of CollectiblesA found in Gatherer", 4, colB.size());
        tx.commit();
View Full Code Here

            tx.commit();

            tx = odmg.newTransaction();
            tx.begin();
            ((HasBroker) tx).getBroker().clearCache();
            OQLQuery qry = odmg.newOQLQuery();
            qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
            qry.bind("Kevin");

            DList result = (DList) qry.execute();
            Person boy = (Person) result.get(0);
            assertEquals(boy.getFirstname(), kevin.getFirstname());
            assertEquals(boy.getFather().getFirstname(), dad.getFirstname());
            assertEquals(boy.getMother().getFirstname(), mum.getFirstname());
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.setCollectiblesB(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
        fetchedGat.getCollectiblesC().remove(0);
        //*************************************
        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?
        db.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

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.