Package org.odmg

Examples of org.odmg.OQLQuery


        prepareForQueryTests(name);

        TransactionExt tx = (TransactionExt) odmg.newTransaction();
        tx.begin();
        tx.getBroker().clearCache();
        OQLQuery query = odmg.newOQLQuery();
        query.create("select objects from " + Executive.class.getName()+" where name like $1 and address.street like $2");
        query.bind(name + "%");
        query.bind("snob allee");
        Collection result = (Collection) query.execute();
        tx.commit();

        assertEquals(1, result.size());
        Executive retManager = (Executive) result.iterator().next();
        assertNotNull(retManager);
View Full Code Here


        prepareForQueryTests(name);

        TransactionExt tx = (TransactionExt) odmg.newTransaction();
        tx.begin();
        tx.getBroker().clearCache();
        OQLQuery query = odmg.newOQLQuery();
        query.create("select objects from " + Employee.class.getName()+" where name like $1 and address.street like $2");
        query.bind(name + "%");
        query.bind("snob allee");
        Collection result = (Collection) query.execute();
        tx.commit();
        assertEquals(1, result.size());
        Employee emp = (Employee) result.iterator().next();
        assertNotNull(emp);
        assertEquals(name + "_manager_1", emp.getName());
View Full Code Here

        assertEquals(name, newEx1.getName());
        assertEquals(name, newM1.getName());

        assertEquals(2, newM1.getExecutives().size());

        OQLQuery queryEmployee = odmg.newOQLQuery();
        queryEmployee.create("select objects from " + Employee.class.getName()+" where name like $1");
        queryEmployee.bind(name);

        OQLQuery queryExecutive = odmg.newOQLQuery();
        queryExecutive.create("select objects from " + Executive.class.getName()+" where name like $1");
        queryExecutive.bind(name);

        OQLQuery queryManager = odmg.newOQLQuery();
        queryManager.create("select objects from " + Manager.class.getName()+" where name like $1");
        queryManager.bind(name);

        Collection result = (Collection) queryEmployee.execute();
        assertEquals(4, result.size());

        result = (Collection) queryExecutive.execute();
        assertEquals(3, result.size());

        result = (Collection) queryManager.execute();
        assertEquals(1, result.size());
    }
View Full Code Here

        //perform transaction
        try
        {
            tx.begin();

            OQLQuery query = odmg.newOQLQuery();
            query.create("select anArticle from " + Article.class.getName() + " where articleId = $678");
            query.bind(new Integer(30));

            List results = (List) query.execute();

            Article a = (Article) results.get(0);

            //crosscheck with PersistenceBroker lookup
            // 1. get OID
View Full Code Here

        //perform transaction
        try
        {
            tx.begin();
            OQLQuery query = odmg.newOQLQuery();
            query.create("select aLotOfArticles from " + Article.class.getName() + " where productGroupId = 4");

            DCollection results = (DCollection) query.execute();
            results = results.query("price > 35");

            // now perform control query
            query = odmg.newOQLQuery();
            query.create(
                    "select aLotOfArticles from "
                    + Article.class.getName()
                    + " where productGroupId = 4 and price  > 35");

            DCollection check = (DCollection) query.execute();

            assertEquals(results, check);

            tx.commit();
        }
View Full Code Here

        {
            Transaction tx = odmg.newTransaction();
            tx.begin();

            // retrieve an Article
            OQLQuery query = odmg.newOQLQuery();
            query.create("select anArticle from " + Article.class.getName() + " where articleId = $678");
            query.bind(new Integer(30));
            List results = (List) query.execute();
            Article a = (Article) results.get(0);

            // manipulate metadata
            broker = ((TransactionImpl) tx).getBroker();
            cld = broker.getClassDescriptor(Article.class);
View Full Code Here

        father.setFirstname(null);

        tx.begin();
        // make sure all objects are retrieved freshly in subsequent transactions
        ((TransactionImpl) tx).getBroker().clearCache();
        OQLQuery qry = odmg.newOQLQuery();
        qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
        qry.bind(firstnameFather);
        Collection result = (Collection) qry.execute();

        assertEquals("Exactly one element in result set", 1, result.size());
        Person returnedFather = (Person) result.iterator().next();
        // should retrieve new instance
        assertTrue("not same", returnedFather != father);
        Person[] returnedChildren = returnedFather.getChildren();
        assertNotNull(returnedChildren);
        assertEquals(2, returnedChildren.length);
        Person child = returnedChildren[0];
        Person lookupFather = child.getFather();
        assertNotNull(lookupFather);
        assertEquals(returnedFather.getFirstname(), lookupFather.getFirstname());
        // unfortunately, PersonImpl does not have a suitable equals method.
        assertEquals(
                "children's names are equal",
                Arrays.asList(getFirstNames(returnedChildren)),
                Arrays.asList(getFirstNames(children)));
        // System.out.println(Arrays.asList(getFirstNames(returnedChildren)));
        tx.commit();

        /*
         delete father then children
         fk-constraints?
         */
        tx.begin();
        database.deletePersistent(returnedFather);
        database.deletePersistent(returnedFather.getChildren()[0]);
        database.deletePersistent(returnedFather.getChildren()[1]);

        tx.commit();

        qry = odmg.newOQLQuery();
        qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
        qry.bind(firstnameFather);
        result = (Collection) qry.execute();
        assertEquals("Exactly one element in result set", 0, result.size());

        qry = odmg.newOQLQuery();
        qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
        qry.bind(firstnameChild_1);
        result = (Collection) qry.execute();
        // System.out.println("child: "+result.iterator().next());
        assertEquals("Exactly one element in result set", 0, result.size());
    }
View Full Code Here

        father.setFirstname(null);

        tx.begin();
        // make sure all objects are retrieved freshly in subsequent transactions
        ((TransactionImpl) tx).getBroker().clearCache();
        OQLQuery qry = odmg.newOQLQuery();
        qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
        qry.bind(firstnameFather);
        Collection result = (Collection) qry.execute();

        assertEquals("Exactly one element in result set", 1, result.size());
        Person returnedFather = (Person) result.iterator().next();
        // should retrieve new instance
        assertTrue("not same", returnedFather != father);
        Person[] returnedChildren = returnedFather.getChildren();
        assertNotNull(returnedChildren);
        assertEquals(2, returnedChildren.length);
        Person child = returnedChildren[0];
        Person lookupFather = child.getFather();
        assertNotNull(lookupFather);
        assertEquals(returnedFather.getFirstname(), lookupFather.getFirstname());
        // unfortunately, PersonImpl does not have a suitable equals method.
        assertEquals(
                "children's names are equal",
                Arrays.asList(getFirstNames(returnedChildren)),
                Arrays.asList(getFirstNames(children)));
        // System.out.println(Arrays.asList(getFirstNames(returnedChildren)));
        tx.commit();

        /*
         delete children then father
         fk-constraints?
         */
        tx.begin();
        database.deletePersistent(returnedFather.getChildren()[0]);
        database.deletePersistent(returnedFather.getChildren()[1]);
        database.deletePersistent(returnedFather);
        tx.commit();

        qry = odmg.newOQLQuery();
        qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
        qry.bind(firstnameFather);
        result = (Collection) qry.execute();
        assertEquals("Exactly one element in result set", 0, result.size());

        qry = odmg.newOQLQuery();
        qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
        qry.bind(firstnameChild_1);
        result = (Collection) qry.execute();
        // System.out.println("child: "+result.iterator().next());
        assertEquals("Exactly one element in result set", 0, result.size());
    }
View Full Code Here

    protected int getDBObjectCountViaOqlQueryUseNewTransaction(Implementation odmg, Class target) throws Exception
    {
        Transaction tx = odmg.newTransaction();
        tx.begin();
        OQLQuery query = odmg.newOQLQuery();
        query.create("select allProjects from " + target.getName());
        List list = (List) query.execute();
        tx.commit();
        return list.size();
    }
View Full Code Here

    protected int getDBObjectCountViaOqlQueryUseNewTransaction(Implementation ojb, Class target) throws Exception
    {
        Transaction tx = ojb.newTransaction();
        tx.begin();
        OQLQuery query = ojb.newOQLQuery();
        query.create("select allProjects from " + target.getName());
        List list = (List) query.execute();
        tx.commit();
        return list.size();
    }
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.