Package org.odmg

Examples of org.odmg.OQLQuery


        TransactionImpl tx2 = (TransactionImpl) odmg2.newTransaction();
        tx2.begin();
        success = lm.writeLock(tx2, arr[(loops - 2)]);
        assertTrue("lock should succeed", success);

        OQLQuery query = odmg2.newOQLQuery();
        String sql = "select allArticles from " + Article.class.getName() +
                " where articleName = \"" + PRE + "testLockLoop" + "\"";
        query.create(sql);
        int result = ((List) query.execute()).size();
        tx2.commit();
        assertEquals("Wrong number of objects wrote to DB", loops, result);

        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        broker.clearCache();
View Full Code Here


        Transaction tx = odmg.newTransaction();
        tx.begin();
        tx.lock(site, Transaction.WRITE);
        tx.commit();

        OQLQuery query = odmg.newOQLQuery();
        query.create("select sites from " + Site.class.getName() + " where name=$1");
        query.bind(name);
        tx.begin();
        List result = (List) query.execute();
        if (result.size() == 0)
        {
            fail("Stored object not found");
        }
        tx.commit();

        tx.begin();
        db.deletePersistent(site);
        tx.commit();

        query = odmg.newOQLQuery();
        query.create("select sites from " + Site.class.getName() + " where name=$1");
        query.bind(name);
        tx.begin();
        List result2 = (List) query.execute();
        if (result2.size() > 0)
        {
            fail("We should not found deleted objects");
        }
        tx.commit();
View Full Code Here

            tx.begin();
            tx.lock(site, Transaction.WRITE);
            tx.commit();

            /* Retrieve from the object created, and set the year*/
            OQLQuery query = odmg.newOQLQuery();
            query.create(queryString);
            query.bind(name);

            tx.begin();
            List result = (List) query.execute();
            assertEquals(1, result.size());
            site = (Site) result.get(0);
            assertNotNull(site);
            assertNull(site.getYear());
            tx.lock(site, Transaction.UPGRADE);
            site.setYear(new Integer(2003));

            tx.commit();

            /* Flush the cache, and retrieve the object again */
            query = odmg.newOQLQuery();
            query.create(queryString);
            query.bind(name);
            tx.begin();
            ((HasBroker) tx).getBroker().clearCache();
            result = (List) query.execute();
            assertEquals(1, result.size());
            site = (Site) result.get(0);
            assertNotNull(site);
            assertNotNull("year should not be null", site.getYear());
            tx.commit();
View Full Code Here

  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

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

        OQLQuery query = odmg.newOQLQuery();
        String sql = "select allPersons from " + Person.class.getName() + " where id != 5 and id > $1";
        query.create(sql);
        query.bind(new Integer(id_filter));

        Collection allPersons = (Collection) query.execute();

        // Iterator over the restricted articles objects
        java.util.Iterator it = allPersons.iterator();

        while (it.hasNext())
View Full Code Here

    // deleteData(database, odmg, Article.class);

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

    OQLQuery query1 = odmg.newOQLQuery();
    query1.create("select anArticle from " + Article.class.getName() + " where articleId in(30, 31, 32) order by articleId");
    List result1 = (List) query1.execute();

    Collection ids = new ArrayList();
    ids.add(new Integer(30));
    ids.add(new Integer(31));
    ids.add(new Integer(32));
    OQLQuery query2 = odmg.newOQLQuery();
    query2.create("select anArticle from " + Article.class.getName() + " where articleId in($1) order by articleId");
    query2.bind(ids);
    List result2 = (List) query2.execute();

    assertEquals(result1.size(), result2.size());
    tx.commit();
  }
View Full Code Here

  public void testQueryNull() throws Exception
  {
    Transaction tx = odmg.newTransaction();
    tx.begin();

    OQLQuery query1 = odmg.newOQLQuery();
    query1.create("select anArticle from " + Article.class.getName() + " where is_undefined(articleName)");
    List result1 = (List) query1.execute();

    OQLQuery query2 = odmg.newOQLQuery();
    query2.create("select anArticle from " + Article.class.getName() + " where articleName = nil");
    List result2 = (List) query2.execute();

    assertEquals(result1.size(), result2.size());
    tx.commit();
  }
View Full Code Here

  public void testQueryNotNull() throws Exception
  {
    Transaction tx = odmg.newTransaction();
    tx.begin();

    OQLQuery query1 = odmg.newOQLQuery();
    query1.create("select anArticle from " + Article.class.getName() + " where is_defined(articleName)");
    List result1 = (List) query1.execute();

    OQLQuery query2 = odmg.newOQLQuery();
    query2.create("select anArticle from " + Article.class.getName() + " where articleName <> nil");
    List result2 = (List) query2.execute();

    assertEquals(result1.size(), result2.size());
    tx.commit();
  }
View Full Code Here

  {
    Transaction tx = odmg.newTransaction();

    tx.begin();

    OQLQuery query1 = odmg.newOQLQuery();
    query1.create("select anArticle from " + Article.class.getName() + " where articleId between 30 and 32 order by articleId desc");
    List result1 = (List) query1.execute();

    OQLQuery query2 = odmg.newOQLQuery();
    query2.create("select anArticle from " + Article.class.getName() + " where articleId between $1 and $2 order by articleId asc");
    query2.bind(new Integer(30));
    query2.bind(new Integer(32));
    List result2 = (List) query2.execute();

    assertEquals(result1.size(), result2.size());
    tx.commit();
  }
View Full Code Here

    Mammal cat = new Mammal(4, "Winston", 4);
    Reptile snake = new Reptile(4, "Skuzzlebutt", "green");

        Transaction tx = odmg.newTransaction();
    tx.begin();
    OQLQuery query = odmg.newOQLQuery();
    query.create("select animals from " + InterfaceAnimal.class.getName() +
           " where name in list (\"Minnie\", \"Winston\", \"Skuzzlebutt\")");
    int before = ((Collection) query.execute()).size();
    tx.commit();


    tx = odmg.newTransaction();
    tx.begin();
    database.makePersistent(elephant);
    database.makePersistent(cat);
    database.makePersistent(snake);
    tx.commit();

    tx = odmg.newTransaction();
    tx.begin();
    List animals = (List) query.execute();
    tx.commit();
    assertEquals(before + 3, animals.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.