Exemple #1
0
  public void testQueryComputers() throws Exception {
    String[] classNames = {
      "ctf.jdo.tc9x.Laptop", "ctf.jdo.tc9x.Laptop", "ctf.jdo.tc9x.Server", "ctf.jdo.tc9x.Server"
    };

    Database database = _category.getDatabase();

    database.begin();
    OQLQuery query =
        database.getOQLQuery(
            "select computer from "
                + Computer.class.getName()
                + " as computer order by computer.id");
    QueryResults results = query.execute();

    if (results.hasMore()) {
      int counter = 1;
      while (results.hasMore()) {
        Computer computer = (Computer) results.next();
        assertNotNull(computer);
        assertEquals(counter, computer.getId());
        assertEquals(classNames[counter - 1], computer.getClass().getName());

        counter += 1;
      }
    } else {
      fail("Query does not return any Computer instances.");
    }
    database.commit();

    database.close();
  }
Exemple #2
0
  public void testCreateAndLoadComputer() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    Order order = new Order();
    order.setId(12);
    order.setName("order 12");
    database.create(order);
    database.commit();

    database.begin();
    ProductDetail detail = new ProductDetail();
    detail.setId(12);
    detail.setCategory("category 12");
    detail.setLocation("location 12");
    database.create(detail);
    database.commit();

    database.begin();
    Laptop laptop = new Laptop();
    laptop.setId(12);
    laptop.setName("laptop 12");
    laptop.setCpu("centrino");
    laptop.setResolution("1600");
    laptop.setWeight(2450);
    laptop.setDetail((ProductDetail) database.load(ProductDetail.class, new Integer(12)));
    database.create(laptop);
    Collection orders = new LinkedList();
    orders.add(database.load(Order.class, new Integer(12)));
    laptop.setOrders(orders);
    database.commit();

    database.begin();
    Computer computer = (Computer) database.load(Computer.class, new Integer(12));
    database.commit();

    assertNotNull(computer);
    assertEquals("ctf.jdo.tc9x.Laptop", computer.getClass().getName());
    assertEquals(12, computer.getId());
    assertEquals("laptop 12", computer.getName());

    database.begin();
    computer = (Computer) database.load(Computer.class, new Integer(12));
    database.remove(computer);
    database.remove(database.load(ProductDetail.class, new Integer(12)));
    database.remove(database.load(Order.class, new Integer(12)));
    database.commit();

    database.close();
  }
Exemple #3
0
  public void testLoadComputer() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    Computer computer = (Computer) database.load(Computer.class, new Integer(2));
    database.commit();

    assertNotNull(computer);
    assertEquals("ctf.jdo.tc9x.Laptop", computer.getClass().getName());
    assertEquals(2, computer.getId());
    assertEquals("laptop 2", computer.getName());

    database.close();
  }