Package commonj.sdo

Examples of commonj.sdo.DataObject


    //Read list of companies
    public void testReadCompanies() throws Exception {

        CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(getConfig("CompanyConfig.xml"));
        Command read = commandGroup.getCommand("all companies");
        DataObject root = read.executeQuery();
        assertEquals(3, root.getList("COMPANY").size());

    }
View Full Code Here


    //Read list of companies
    public void testReadCompaniesWithDepartments() throws Exception {

        CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(getConfig("CompanyConfig.xml"));
        Command read = commandGroup.getCommand("all companies and departments");
        DataObject root = read.executeQuery();
        DataObject firstCompany = root.getDataObject("COMPANY[1]");
        List departments = firstCompany.getList("departments");
        assertEquals(0, departments.size());

   
View Full Code Here

   
    public void testddDepartmentToFirstCompany() throws Exception {
       
        CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(getConfig("CompanyConfig.xml"));
        Command read = commandGroup.getCommand("all companies and departments");
        DataObject root = read.executeQuery();
        DataObject firstCustomer = root.getDataObject("COMPANY[1]");
        int deptCount = firstCustomer.getList("departments").size();
       
        DataObject newDepartment = root.createDataObject("DEPARTMENT");
        firstCustomer.getList("departments").add(newDepartment);
       
        ApplyChangesCommand apply = commandGroup.getApplyChangesCommand();
        apply.execute(root);
       
View Full Code Here

    public void testFlushCreateHeirarchy() throws Exception {

        CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(getConfig("CompanyConfig.xml"));
        Command select = commandGroup.getCommand("all companies and departments");
        select.setConnection(getConnection());
        DataObject root = select.executeQuery();

        // Create a new Company
        DataObject company = root.createDataObject("COMPANY");
        company.setString("NAME", "Do-rite Pest Control");

        // Create a new Department
        //Do not set ID or CompanyID since these are generated
        DataObject department = root.createDataObject("DEPARTMENT");
        department.setString("NAME", "Do-rite Pest Control");
        department.setString("LOCATION", "The boonies");
        department.setString("NUMBER", "101");
  
        // Associate the new department with the new company
        company.getList("departments").add(department);

        // Get apply command
View Full Code Here

        CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(getConfig("CompanyConfig.xml"));

        Command select = commandGroup.getCommand("company by id with departments");
        Integer idOfNoExistingCompany = new Integer(-1);
        select.setParameterValue("ID", idOfNoExistingCompany);
        DataObject root = select.executeQuery();
       
        //Will fail if there is no property named "COMPANY"
        assertEquals(0, root.getList("COMPANY").size());

    }
View Full Code Here

 
  public void testReadTableInfo() throws Exception {
   
    Command select = Command.FACTORY.createCommand("SELECT * from SYSIBM.SYSTABLES WHERE TYPE = 'T'")
    select.setConnection(getConnection());
    DataObject root = select.executeQuery();
   
    DataObject table = (DataObject)root.get("SYSTABLES[1]");
   
    assertEquals('T', table.getChar("TYPE"));
     
  }
View Full Code Here

 
  protected void printList(List data) {
    Iterator i = data.iterator();
    while ( i.hasNext()) {
      System.out.println();
      DataObject obj = (DataObject) i.next();
      Iterator props = obj.getType().getProperties().iterator();
      while ( props.hasNext()) {
        Property p = (Property) props.next();
        if ( p.isMany() ) {
          System.out.print("[ " + p.getName() + " ] ");
          Iterator children = obj.getList(p).iterator();
          while ( children.hasNext()) {
            DataObject child = (DataObject) children.next();
            System.out.print("[ " + child.get("ID") + " ]");
          }
          System.out.println();
        } else if ( !p.getType().isDataType()) {
          DataObject child = obj.getDataObject(p);
          if ( child != null )
            System.out.println("[ " + p.getName() + " ] " + "[ " + child.get("ID") + " ]");
        } else {
          System.out.println("[ " + p.getName() + " ] " + obj.get(p));
        }
      } 
    }
View Full Code Here

    public void test_1() throws Exception {

        // Read a book instance
        Command select = Command.FACTORY.createCommand("SELECT * FROM BOOK WHERE BOOK_ID = 1");
        select.setConnection(getConnection());
        DataObject root = select.executeQuery();
        DataObject book = root.getDataObject("BOOK[1]");
        // Change a field to mark the instance 'dirty'
        book.setInt("QUANTITY", 2);

        // Flush the change
        ApplyChangesCommand apply = Command.FACTORY.createApplyChangesCommand();
        apply.setConnection(getConnection());

View Full Code Here

    public void test_2() throws Exception {

        // Read a book instance
        Command select = Command.FACTORY.createCommand("SELECT * FROM BOOK WHERE BOOK_ID = 1");
        select.setConnection(getConnection());
        DataObject root = select.executeQuery();
        DataObject book = root.getDataObject("BOOK[1]");
        // Change a field to mark the instance 'dirty'
        book.setInt("QUANTITY", 2);

        // Flush the change
        // Create config programmatically
        ConfigHelper helper = new ConfigHelper();
        helper.addPrimaryKey("BOOK.BOOK_ID");

        ApplyChangesCommand apply = Command.FACTORY.createApplyChangesCommand(helper.getConfig());
        apply.setConnection(getConnection());

        apply.execute(root);

        // Verify
        root = select.executeQuery();
        book = root.getDataObject("BOOK[1]");
        assertEquals(2, book.getInt("QUANTITY"));
    }
View Full Code Here

        helper.addRelationship("CUSTOMER.ID", "ANORDER.CUSTOMER_ID");
       
        Command select = Command.FACTORY.createCommand(statement, helper.getConfig());
        select.setConnection(getConnection());

        DataObject root = select.executeQuery();
        DataObject customer = root.getDataObject("CUSTOMER[1]");

        assertEquals(2, customer.getList("ANORDER").size());

    }
View Full Code Here

TOP

Related Classes of commonj.sdo.DataObject

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.