Package org.odmg

Examples of org.odmg.OQLQuery


        // 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

        Implementation impl = OJB.getInstance();
        Transaction    tx   = impl.newTransaction();

        tx.begin();

        OQLQuery query = impl.newOQLQuery();

        query.create("select products from " + Product.class.getName() + " where name = $1");
        query.bind(name);

        DList   results = (DList)query.execute();
        Product product = (Product)results.iterator().next();

        tx.commit();
        return product;
    }
View Full Code Here

        try
        {
            conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
            tx   = kit.getTransaction(conn);

            OQLQuery oql = conn.newOQLQuery();

            oql.create(query);

            if (queryParams != null)
            {
                for (int idx = 0; idx < queryParams.length; ++idx)
                {
                    oql.bind(queryParams[idx]);
                }
            }

            tx.begin();
View Full Code Here

            Transaction tx = odmg.newTransaction();

            tx.begin();

            // 2. get an OQLQuery object from the ODMG facade
            OQLQuery query = odmg.newOQLQuery();

            // 3. set the OQL select statement
            query.create("select allproducts from " + Product.class.getName());

            // 4. perform the query and store the result in a persistent Collection
            DList allProducts = (DList) query.execute();

            tx.commit();

            // 5. now iterate over the result to print each product
            for (Iterator iter = allProducts.iterator(); iter.hasNext();)
View Full Code Here

            database.makePersistent(master_1);
            database.makePersistent(master_2);
            tx.commit();

            // Check stored objects
            OQLQuery query = odmg.newOQLQuery();
            query.create("select masters from " + Master.class.getName() + " where masterText like $1");
            query.bind("%" + timestamp);
            DList allMasters = (DList) query.execute();
            assertEquals("We should found master objects", 2, allMasters.size());
            Master lookup_1 = (Master) allMasters.get(0);

            Collection col_in = lookup_1.getCollDetailFKinPK();
            Collection col_no = lookup_1.getCollDetailFKnoPK();
View Full Code Here

            database.makePersistent(master_1);
            database.makePersistent(master_2);
            tx.commit();

            // Check stored objects
            OQLQuery query = odmg.newOQLQuery();
            query.create("select masters from " + Master.class.getName() + " where masterText like $1");
            query.bind("%" + timestamp);
            DList allMasters = (DList) query.execute();
            assertEquals("We should found master objects", 2, allMasters.size());
            Master lookup_1 = (Master) allMasters.get(0);
            Collection col_in = lookup_1.getCollDetailFKinPK();
            Collection col_no = lookup_1.getCollDetailFKnoPK();
            assertEquals("Should found none " + DetailFKnoPK.class.getName() + " objects", 0, col_no.size());
View Full Code Here

            tx.lock(master_3, Transaction.WRITE);
            tx.lock(master_4, Transaction.WRITE);
            tx.commit();

            tx.begin();
            OQLQuery query = odmg.newOQLQuery();
            query.create("select masters from " + Master.class.getName() + " where masterText like $1");
            query.bind("%" + timestamp);
            DList allMasters = (DList) query.execute();

            // Iterator over all Master objects
            Iterator it = allMasters.iterator();
            int counter = 0;
            while (it.hasNext())
            {
                ++counter;
                Master aMaster = (Master) it.next();
                Iterator it2 = aMaster.collDetailFKinPK.iterator();
                while (it2.hasNext())
                    database.deletePersistent(it2.next());
                it2 = aMaster.collDetailFKnoPK.iterator();
                while (it2.hasNext())
                    database.deletePersistent(it2.next());
                database.deletePersistent(aMaster);
            }
            tx.commit();
            assertEquals("Wrong count of Master objects found", 4, counter);

            query = odmg.newOQLQuery();
            query.create("select masters from " + Master.class.getName() + " where masterText like $1");
            query.bind("%" + timestamp);
            allMasters = (DList) query.execute();
            assertEquals("Delete of Master objects failed", 0, allMasters.size());

            database.close();
        }
        finally
View Full Code Here

    }

    private Collection getContract(String pk, Implementation odmg)
            throws Exception
    {
        OQLQuery query = odmg.newOQLQuery();
        query.create("select c from " + Contract.class.getName() + " where pk like $1");
        query.bind(pk);
        return (Collection) query.execute();
    }
View Full Code Here

    {
        if(log.isDebugEnabled()) log.debug("getObjectCount was called");
        DList list;
        try
        {
            OQLQuery query = ojb.newOQLQuery();
            query.create("select allObjects from " + target.getName());
            list = (DList) query.execute();
            return list.size();
        }
        catch (QueryException e)
        {
            throw new EJBException("Query objects failed", e);
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.