Package org.apache.tuscany.das.rdb

Examples of org.apache.tuscany.das.rdb.Command


   * Read all customers with a specific last name
   */
  public void testReadMultiple() throws Exception {

    //Create and initialize command to read customers
    Command readCustomers = Command.FACTORY.createCommand("select * from CUSTOMER where LASTNAME = 'Williams'")
    readCustomers.setConnection(getConnection());

    //Read
    DataObject root = readCustomers.executeQuery();
   
    //Verify
    assertEquals(4, root.getList("CUSTOMER").size());
  }
View Full Code Here


   * LASTNAME value is provided via a parameter
   */
  public void testReadMultipleWithParameters() throws Exception {

    //Create and initialize command to read customers
    Command readCustomers = Command.FACTORY.createCommand("select * from CUSTOMER where LASTNAME = :LASTNAME")
    readCustomers.setConnection(getConnection());

    //Parameterize the command
    readCustomers.setParameterValue("LASTNAME", "Williams");
    DataObject root = readCustomers.executeQuery();
   
    //Verify
    assertEquals(4, root.getList("CUSTOMER").size());
  }
View Full Code Here

    assertEquals(4, root.getList("CUSTOMER").size());
  }

  public void testInsert() throws Exception {
   
    Command insert = Command.FACTORY.createCommand("insert into CUSTOMER values (10, 'Williams', '5528 Wells Fargo Dr')")
    insert.setConnection(getConnection());
    insert.execute();

    //Verify
    Command select = Command.FACTORY.createCommand("Select * from CUSTOMER where ID = 10");
    select.setConnection(getConnection());
    DataObject root = select.executeQuery()
    assertEquals(1, root.getList("CUSTOMER").size());
    assertEquals("5528 Wells Fargo Dr", root.get("CUSTOMER[1]/ADDRESS"));

  }
View Full Code Here

  }

  public void testInsertWithParameters() throws Exception {
   
    Command insert = Command.FACTORY.createCommand("insert into CUSTOMER values (:ID, :LASTNAME, :ADDRESS)")
    insert.setConnection(getConnection());
    insert.setParameterValue("ID", new Integer(10));
    insert.setParameterValue("LASTNAME", "Williams");
    insert.setParameterValue("ADDRESS", "5528 Wells Fargo Dr");
    insert.execute();

    //Verify
    Command select = Command.FACTORY.createCommand("Select * from CUSTOMER where ID = 10");
    select.setConnection(getConnection());
    DataObject root = select.executeQuery()
    assertEquals(1, root.getList("CUSTOMER").size());
    assertEquals("5528 Wells Fargo Dr", root.get("CUSTOMER[1]/ADDRESS"));

  }
View Full Code Here

  }


  public void testSingleTableMerge() throws Exception {
   
    Command select = Command.FACTORY
        .createCommand("Select ID, LASTNAME, ADDRESS from CUSTOMER where ID <= :ID");
    select.setConnection(getConnection());
    select.setParameterValue("ID", "3");
    DataObject graph1 = select.executeQuery();
    assertEquals(3, graph1.getList("CUSTOMER").size());

    select.setParameterValue("ID", "5");
    DataObject graph2 = select.executeQuery();
    assertEquals(5, graph2.getList("CUSTOMER").size());

    GraphMerger merger = new GraphMerger();
    merger.addPrimaryKey("CUSTOMER.ID");
    DataObject mergedGraph = merger.merge(graph1, graph2);
View Full Code Here

    assertEquals(5, mergedGraph.getList("CUSTOMER").size());
  }

  public void testSingleTableMergeThreeGraphs() throws Exception {

    Command select = Command.FACTORY
        .createCommand("Select ID, LASTNAME, ADDRESS from CUSTOMER where ID <= :ID");
    select.setConnection(getConnection());
    select.setParameterValue("ID", "3");
    DataObject graph1 = select.executeQuery();
    assertEquals(3, graph1.getList("CUSTOMER").size());

    select.setParameterValue("ID", "4");
    DataObject graph2 = select.executeQuery();
    assertEquals(4, graph2.getList("CUSTOMER").size());

    select.setParameterValue("ID", "5");
    DataObject graph3 = select.executeQuery();
    assertEquals(5, graph3.getList("CUSTOMER").size());

    GraphMerger merger = new GraphMerger();
    merger.addPrimaryKey("CUSTOMER.ID");
    ArrayList graphs = new ArrayList();
View Full Code Here

  }

   
    public void testMultiTableMerge2() throws Exception {
        //Read some customers and related orders
        Command select = Command.FACTORY.createCommand(
                "SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = :ID", getConfig("CustomersOrdersConfig.xml"))
        select.setConnection(getConnection());
       
        select.setConnection(getConnection());
        select.setParameterValue("ID", new Integer(1));
        DataObject graph1 = select.executeQuery();
       
        DataObject customer = (DataObject)graph1.getList("CUSTOMER").get(0);
        assertEquals(2, customer.getList("orders").size());   
       
        select.setParameterValue("ID", new Integer(2));
        DataObject graph2 = select.executeQuery();
        DataObject customer2 = (DataObject)graph2.getList("CUSTOMER").get(0);
        assertEquals(1, graph2.getList("CUSTOMER").size());
        assertEquals(1, customer2.getList("orders").size());
        assertEquals(2, customer2.getInt("ID"));
       
View Full Code Here

       
    }
   
    public void testMultiTableAppendSingleTable2() throws Exception {
        //Read some customers and related orders
        Command select = Command.FACTORY.createCommand(
                "SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = :ID", getConfig("CustomersOrdersConfig.xml"))
        select.setConnection(getConnection());
       
        select.setConnection(getConnection());
        select.setParameterValue("ID", new Integer(1));
        DataObject graph1 = select.executeQuery();
       
        DataObject customer = (DataObject)graph1.getList("CUSTOMER").get(0);
        assertEquals(2, customer.getList("orders").size());
       
        Command select2 = Command.FACTORY.createCommand("select * from ANORDER");
        select2.setConnection(getConnection());
        DataObject graph2 = select2.executeQuery();
        assertEquals(4, graph2.getList("ANORDER").size());
       
        GraphMerger merger = new GraphMerger();
        merger.addPrimaryKey("CUSTOMER.ID");
        merger.addPrimaryKey("ANORDER.ID");
View Full Code Here

    }

    public void testSimple() throws Exception {

        // Build the select command
        Command selectCommand = Command.FACTORY.createCommand("select COMPANY.NAME, "
                + "EMPLOYEE.NAME, EMPLOYEE.SN, EMPLOYEE.MANAGER, "
                + "DEPARTMENT.NAME, DEPARTMENT.LOCATION, DEPARTMENT.NUMBER from COMPANY, DEPARTMENT, EMPLOYEE "
                + "where COMPANY.ID=DEPARTMENT.COMPANYID and DEPARTMENT.ID=EMPLOYEE.DEPARTMENTID", getConfig("companyMapping.xml"));

        // Parameterize the command
        selectCommand.setConnection(getConnection());

        // Get the graph
        DataObject root = selectCommand.executeQuery();

        // Get a company
        DataObject company = (DataObject) root.getList("CompanyType").get(0);
        assertEquals("MegaCorp", company.get("NAME"));
View Full Code Here

    public void testSimpleStatic() throws Exception {

      SDOUtil.registerStaticTypes(CompanyFactory.class);
        // Build the select command
        Command selectCommand = Command.FACTORY.createCommand("select COMPANY.NAME, "
                + "EMPLOYEE.NAME, EMPLOYEE.SN, EMPLOYEE.MANAGER, "
                + "DEPARTMENT.NAME, DEPARTMENT.LOCATION, DEPARTMENT.NUMBER from COMPANY, DEPARTMENT, EMPLOYEE "
                + "where COMPANY.ID=DEPARTMENT.COMPANYID and DEPARTMENT.ID=EMPLOYEE.DEPARTMENTID", getConfig("companyMappingWithConverters.xml"));

        // Parameterize the command
        selectCommand.setConnection(getConnection());
        selectCommand.setDataObjectModel(TypeHelper.INSTANCE.getType(DatagraphRoot.class));

        // Get the graph
        DatagraphRoot root = (DatagraphRoot) selectCommand.executeQuery();
       
       
        CompanyType company = (CompanyType) root.getCompanies().get(0);

        assertEquals("MegaCorp", company.getName());
View Full Code Here

TOP

Related Classes of org.apache.tuscany.das.rdb.Command

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.