Package org.odmg

Examples of org.odmg.Transaction


  }

  private void createPersons()
      throws Exception
  {
    Transaction tx = odmg.newTransaction();
    tx.begin();
    for (int i = 0; i < COUNT; i++)
    {
      Person aPerson = new PersonImpl();
      aPerson.setId(i);
      aPerson.setFirstname("firstname" + i);
      aPerson.setLastname("lastname" + i);
      database.makePersistent(aPerson);
    }
    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());
    }
    tx.commit();
  }
View Full Code Here

  public void testGetWithLiteral() throws Exception
  {
        createPersons();

        // 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())
        {
            /**
             * just make sure it's a string.
             */
            Object result = it.next();
            Person value = (Person) result;
            if (value.getId() <= id_filter)
                fail("oql didn't filter, got id (" + value.getId() + " where it should have been over " + id_filter);
        }
        tx.commit();
  }
View Full Code Here

  public void testQueryIn() throws Exception
  {
    // 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

    tx.commit();
  }

  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

    tx.commit();
  }

  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

    tx.commit();
  }

  public void testQueryBetween() throws Exception
  {
    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

    //objects that are part of a 1:n relation, i.e. they have fk-fields
    Mammal elephant = new Mammal(4, "Minnie", 4);
    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

    String oql = "select allProductGroups from " + ProductGroup.class.getName()
                + " where groupId <= $1 order by groupId prefetch allArticlesInGroup";
    OQLQuery query = odmg.newOQLQuery();
    query.create(oql);
    query.bind(new Integer(5));
    Transaction tx = odmg.newTransaction();
    tx.begin();
    Collection results = (Collection) query.execute();
    tx.commit();
    assertNotNull(results);
    assertTrue(results.size() > 0);
  }
View Full Code Here

    Salad lolloverde = new Salad("Lollo verde", caloriesOther, "green");

    deleteData(InterfaceAnimal.class);
    deleteData(InterfaceFood.class);

    Transaction tx = odmg.newTransaction();
    tx.begin();
    database.makePersistent(elephant);
    database.makePersistent(cat);
    database.makePersistent(snake);
    database.makePersistent(tuna);
    database.makePersistent(trout);
    database.makePersistent(radiccio);
    database.makePersistent(lolloverde);
    tx.commit();

    tx = odmg.newTransaction();
    tx.begin();
    OQLQuery query = odmg.newOQLQuery();
    query.create("select animals from " + InterfaceAnimal.class.getName() +
           " where age=$1");
    query.bind(new Integer(age));
    List animals = (List) query.execute();
    tx.commit();
    Iterator it = animals.iterator();
    while (it.hasNext())
    {
      Object obj = it.next();
            // System.out.println(obj);
    }
    assertEquals(3, animals.size());

    //test independent objects
    query = odmg.newOQLQuery();
    tx.begin();
    query.create("select food from " + InterfaceFood.class.getName() +
           " where calories=$1");
    query.bind(new Integer(calories));
    List food = (List) query.execute();
    tx.commit();
    assertEquals(3, food.size());
  }
View Full Code Here

TOP

Related Classes of org.odmg.Transaction

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.