Package org.apache.tuscany.das.rdb

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


   * statements.
   */
  public void testCUDGeneration1() throws Exception {

    // Read customer with particular ID
    Command select = Command.FACTORY
        .createCommand("Select * from CUSTOMER where ID = 1");
    select.setConnection(getConnection());
    DataObject root = select.executeQuery();

    DataObject customer = (DataObject) root.get("CUSTOMER[1]");

    // Modify customer
    customer.set("LASTNAME", "Pavick");
View Full Code Here


    }

  }

  public void testInsertCUDGeneration() throws Exception {
    Command select = Command.FACTORY
        .createCommand("Select * from CUSTOMER where ID = 1");
    select.setConnection(getConnection());
    DataObject root = select.executeQuery();

    DataObject customer = root.createDataObject("CUSTOMER");
    customer.setInt("ID", 720);
    customer.set("LASTNAME", "foobar");
    customer.set("ADDRESS", "asdfasdf");

    ApplyChangesCommand apply = Command.FACTORY.createApplyChangesCommand();
    apply.setConnection(getConnection());
    apply.execute(root);

    select = Command.FACTORY
        .createCommand("select * from CUSTOMER where ID = 720");
    select.setConnection(getConnection());
    root = select.executeQuery();

    assertEquals(1, root.getList("CUSTOMER").size());
  }
View Full Code Here

  public void testReadModifyApply() throws Exception {

    // Build the select command to read a specific customer 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("1xM_mapping_no_cud.xml"));

    // Parameterize the command
    select.setConnection(getConnection());
    select.setParameterValue("ID", new Integer(1));

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

    // Modify a customer
    DataObject customer = (DataObject) root.get("Customer[1]");
    customer.set("LASTNAME", "Pavick");

View Full Code Here

   * Test ability to assign DataObject type and propertyaliases with xml file
   */
  public void testRead() throws Exception {

    // Read a customer
    Command select = Command.FACTORY.createCommand(
        "SELECT * FROM CUSTOMER WHERE CUSTOMER.ID = 1", getConfig("customerMapping.xml"));
    select.setConnection(getConnection());

    DataObject root = select.executeQuery();
    DataObject customer = root.getDataObject("Customer[1]");
    assertEquals(1, customer.getInt("id"));
    assertEquals("1212 foobar lane", customer.getString("address"));
    assertEquals("Williams", customer.getString("lastname"));
   
View Full Code Here

        java.sql.Connection c = getConnection();

        try {

            // Read customer 1
            Command select = Command.FACTORY.createCommand("Select * from CUSTOMER where ID = 1");
            select.setConnection(c);
            DataObject root = select.executeQuery();

            DataObject customer = (DataObject) root.get("CUSTOMER[1]");

            // Modify customer
            customer.set("LASTNAME", "Pavick");

            // Build apply changes command
            ApplyChangesCommand apply = Command.FACTORY.createApplyChangesCommand();
            apply.setConnection(c, false);

            // Flush changes
            apply.execute(root);

            // Verify changes
            root = select.executeQuery();
            assertEquals("Pavick", root.getString("CUSTOMER[1]/LASTNAME"));

            // Since the DAS is not managing tx boundaries, I must
        } catch (Exception e) {
            c.rollback();
View Full Code Here

    //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);
       
        //verify
        root = read.executeQuery();
        firstCustomer = root.getDataObject("COMPANY[1]");
        assertEquals (deptCount + 1, firstCustomer.getList("departments").size());
   
View Full Code Here

     * keys
     */
    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
        ApplyChangesCommand apply = commandGroup.getApplyChangesCommand();
        apply.setConnection(getConnection());

        // Flush changes
        apply.execute(root);

        // Save the id
        Integer id = (Integer) company.get("ID");

        // Verify the change

        select = commandGroup.getCommand("company by id with departments");
        select.setParameterValue("ID", id);
        root = select.executeQuery();
        assertEquals("Do-rite Pest Control", root.getDataObject("COMPANY[1]")
                .getString("NAME"));

    }
View Full Code Here

     */
    public void testGetEmptyGraph() throws Exception {

        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

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.