Package org.apache.ojb.odmg.oql

Examples of org.apache.ojb.odmg.oql.EnhancedOQLQuery


    public void testOtmSession() throws Throwable
    {
        Transaction tx = null;
        Criteria crit;
        Query q;
        EnhancedOQLQuery oql;
        Iterator it;
        Article example;

        //perform transaction
        try
        {
            tx = _kit.getTransaction(_conn);
            tx.begin();

            example = (Article) _conn.getObjectByIdentity(
                    new Identity(Article.class, Article.class,
                                 new Object[] {new Integer(77777)}));
            if (example == null)
            {
                example = Article.createInstance();
                example.setArticleId(77777);
            }
            example.setProductGroupId(7);
            example.setStock(333);
            example.setArticleName("333");
            _conn.makePersistent(example);

            tx.commit();

            Identity oid = _conn.getIdentity(example);

            // get from the cache
            tx = _kit.getTransaction(_conn);
            tx.begin();
            example = (Article) _conn.getObjectByIdentity(oid);
            assertEquals("should be equal", 7, example.getProductGroupId());
            assertEquals("should be equal", 333, example.getStock());
            assertEquals("should be equal", "333", example.getArticleName());
            tx.commit();

            // get from the database
            tx = _kit.getTransaction(_conn);
            tx.begin();
            _conn.invalidate(oid);
            example = (Article) _conn.getObjectByIdentity(oid);
            assertEquals("should be equal", 7, example.getProductGroupId());
            assertEquals("should be equal", "333", example.getArticleName());
            example.setArticleName("334"); // test update
            tx.commit();

            // get from the database via Query
            tx = _kit.getTransaction(_conn);
            _conn.invalidate(oid);
            tx.begin();
            crit = new Criteria();
            crit.addEqualTo("articleId", new Integer(77777));
            crit.addEqualTo("articleName", "334");
            q = QueryFactory.newQuery(Article.class, crit);
            it = _conn.getIteratorByQuery(q);
            if (it.hasNext())
            {
                InterfaceArticle article = (InterfaceArticle) it.next();
                assertEquals("should be equal", 77777, article.getArticleId());
                assertEquals("should be equal", "334", article.getArticleName());
                article.setArticleName("335"); // test update
                if (it.hasNext())
                {
                    fail("Query returned more than 1 object");
                }
            }
            else
            {
                fail("Query returned empty result set");
            }
            tx.commit();

            // get from the database via OQLQuery Iterator
            tx = _kit.getTransaction(_conn);
            _conn.invalidate(oid);
            tx.begin();
            oql = _conn.newOQLQuery();
            oql.create("select a from " + Article.class.getName()
                + " where articleId=$1 and articleName=$2");
            oql.bind(new Integer(77777));
            oql.bind("335");
            it = _conn.getIteratorByOQLQuery(oql);
            if (it.hasNext())
            {
                InterfaceArticle article = (InterfaceArticle) it.next();
                assertEquals("should be equal", 77777, article.getArticleId());
                assertEquals("should be equal", "335", article.getArticleName());
                article.setArticleName("336"); // test update
                if (it.hasNext())
                {
                    fail("Query returned more than 1 object");
                }
            }
            else
            {
                fail("Query returned empty result set");
            }
            tx.commit();

            // get from the database via OQLQuery Collection
            tx = _kit.getTransaction(_conn);
            _conn.invalidate(oid);
            tx.begin();
            oql.bind(new Integer(77777));
            oql.bind("336");
            it = ((Collection) oql.execute()).iterator();
            if (it.hasNext())
            {
                InterfaceArticle article = (InterfaceArticle) it.next();
                assertEquals("should be equal", 77777, article.getArticleId());
                assertEquals("should be equal", "336", article.getArticleName());
View Full Code Here


            example.setProductGroupId(7);
            example.setStock(333);
            example.setArticleName("333");
            conn1.makePersistent(example);

            EnhancedOQLQuery query = conn2.newOQLQuery();
            query.create("select obj from " + Article.class.getName()
                         + " where " + "articleId = " + example.getArticleId());
            Article same = (Article) conn2.getIteratorByOQLQuery(query).next();
            Assert.assertNotNull("Didn't find object in context of transaction", same);

            tx.commit();
View Full Code Here

        // 2. Insert a bunch of articles objects into the database
        createData();
        // 3. Get a list of some articles
        Transaction tx = odmg.newTransaction();
        tx.begin();
        EnhancedOQLQuery query = odmg.newOQLQuery();
        String sql = "select somePersons from " + Person.class.getName();
        query.create(sql, start, end);
        Collection somePersons = (Collection) query.execute();

        // Iterator over the restricted articles objects
        Iterator it = somePersons.iterator();
        int count = 0;
        while(it.hasNext())
View Full Code Here

            // 3. Get a list of some articles
            Transaction tx = odmg.newTransaction();
            tx.begin();

            EnhancedOQLQuery query = odmg.newOQLQuery();
            String sql = "select somePersons from " + Person.class.getName();
            query.create(sql, start, end);
            Collection somePersons = (Collection) query.execute();
            // Iterator over the restricted articles objects
            Iterator it = somePersons.iterator();
            int count = 0;
            while(it.hasNext())
            {
View Full Code Here

        {
            tx.commit();
            return;
        }

        EnhancedOQLQuery query = odmg.newOQLQuery();
        String sql = "select somePersons from " + Person.class.getName();
        query.create(sql, start, end);
        Collection somePersons = (Collection) query.execute();
        // Iterator over the restricted articles objects
        Iterator it = somePersons.iterator();
        int count = 0;
        while(it.hasNext())
        {
View Full Code Here

        int end = 5;
        Transaction tx = odmg.newTransaction();
        try
        {
            tx.begin();
            EnhancedOQLQuery query = odmg.newOQLQuery();
            String sql = "select somePersons from " + Person.class.getName();
            query.create(sql, start, end);
            query.execute();
            fail("should have thrown QueryInvalidException");
        }
        catch(QueryInvalidException iqe)
        {
            // we wait for this exception
View Full Code Here

        Transaction tx = null;
        try
        {
            tx = odmg.newTransaction();
            tx.begin();
            EnhancedOQLQuery query = odmg.newOQLQuery();
            String sql = "select somePersons from " + Person.class.getName();
            query.create(sql, start, end);
            query.execute();
            fail("should have thrown QueryInvalidException");
        }
        catch(QueryInvalidException iqe)
        {
            // we expect that exception
View Full Code Here

            example.setProductGroupId(new Integer(7));
            example.setStock(333);
            example.setArticleName("333");
            conn1.makePersistent(example);

            EnhancedOQLQuery query = conn2.newOQLQuery();
            query.create("select obj from " + Article.class.getName()
                         + " where " + "articleId = " + example.getArticleId());
            Article same = (Article) conn2.getIteratorByOQLQuery(query).next();
            Assert.assertNotNull("Didn't find object in context of transaction", same);

            tx.commit();
View Full Code Here

            example.setProductGroupId(new Integer(7));
            example.setStock(333);
            example.setArticleName("333");
            conn1.makePersistent(example);

            EnhancedOQLQuery query = conn2.newOQLQuery();
            query.create("select obj from " + Article.class.getName()
                         + " where " + "articleId = " + example.getArticleId());
            Article same = (Article) conn2.getIteratorByOQLQuery(query).next();
            Assert.assertNotNull("Didn't find object in context of transaction", same);

            tx.commit();
View Full Code Here

    public void testOtmSession() throws Throwable
    {
        Transaction tx = null;
        Criteria crit;
        Query q;
        EnhancedOQLQuery oql;
        Iterator it;
        Article example;

        //perform transaction
        try
        {
            tx = _kit.getTransaction(_conn);
            tx.begin();

            example = (Article) _conn.getObjectByIdentity(
                    new Identity(Article.class, Article.class,
                                 new Object[] {new Integer(77777)}));
            if (example == null)
            {
                example = Article.createInstance();
                example.setArticleId(new Integer(77777));
            }
            example.setProductGroupId(new Integer(7));
            example.setStock(333);
            example.setArticleName("333");
            _conn.makePersistent(example);

            tx.commit();

            Identity oid = _conn.getIdentity(example);

            // get from the cache
            tx = _kit.getTransaction(_conn);
            tx.begin();
            example = (Article) _conn.getObjectByIdentity(oid);
            assertEquals("should be equal", 7, example.getProductGroupId().intValue());
            assertEquals("should be equal", 333, example.getStock());
            assertEquals("should be equal", "333", example.getArticleName());
            tx.commit();

            // get from the database
            tx = _kit.getTransaction(_conn);
            tx.begin();
            _conn.invalidate(oid);
            example = (Article) _conn.getObjectByIdentity(oid);
            assertEquals("should be equal", 7, example.getProductGroupId().intValue());
            assertEquals("should be equal", "333", example.getArticleName());
            example.setArticleName("334"); // test update
            tx.commit();

            // get from the database via Query
            tx = _kit.getTransaction(_conn);
            _conn.invalidate(oid);
            tx.begin();
            crit = new Criteria();
            crit.addEqualTo("articleId", new Integer(77777));
            crit.addEqualTo("articleName", "334");
            q = QueryFactory.newQuery(Article.class, crit);
            it = _conn.getIteratorByQuery(q);
            if (it.hasNext())
            {
                InterfaceArticle article = (InterfaceArticle) it.next();
                assertEquals("should be equal", 77777, article.getArticleId().intValue());
                assertEquals("should be equal", "334", article.getArticleName());
                article.setArticleName("335"); // test update
                if (it.hasNext())
                {
                    fail("Query returned more than 1 object");
                }
            }
            else
            {
                fail("Query returned empty result set");
            }
            tx.commit();

            // get from the database via OQLQuery Iterator
            tx = _kit.getTransaction(_conn);
            _conn.invalidate(oid);
            tx.begin();
            oql = _conn.newOQLQuery();
            oql.create("select a from " + Article.class.getName()
                + " where articleId=$1 and articleName=$2");
            oql.bind(new Integer(77777));
            oql.bind("335");
            it = _conn.getIteratorByOQLQuery(oql);
            if (it.hasNext())
            {
                InterfaceArticle article = (InterfaceArticle) it.next();
                assertEquals("should be equal", 77777, article.getArticleId().intValue());
                assertEquals("should be equal", "335", article.getArticleName());
                article.setArticleName("336"); // test update
                if (it.hasNext())
                {
                    fail("Query returned more than 1 object");
                }
            }
            else
            {
                fail("Query returned empty result set");
            }
            tx.commit();

            // get from the database via OQLQuery Collection
            tx = _kit.getTransaction(_conn);
            _conn.invalidate(oid);
            tx.begin();
            oql.bind(new Integer(77777));
            oql.bind("336");
            it = ((Collection) oql.execute()).iterator();
            if (it.hasNext())
            {
                InterfaceArticle article = (InterfaceArticle) it.next();
                assertEquals("should be equal", 77777, article.getArticleId().intValue());
                assertEquals("should be equal", "336", article.getArticleName());
View Full Code Here

TOP

Related Classes of org.apache.ojb.odmg.oql.EnhancedOQLQuery

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.