Package org.apache.tuscany.das.rdb

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


    /**
     * Read
     */
    public void testRead() throws Exception {

        CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(getConfig("CustomersOrdersConfig.xml"));
        commandGroup.setConnection(getConnection());

        Command read = commandGroup.getCommand("all customers");
        DataObject root = read.executeQuery();

        assertEquals(5, root.getList("CUSTOMER").size());

    }
View Full Code Here


    /**
     * Read an order using parm marker
     */
    public void testReadWithParmmarker() throws Exception {

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

        Command read = commandGroup.getCommand("order by id with ?");
        read.setParameterValue(1, new Integer(1));
        DataObject root = read.executeQuery();

        assertEquals("recombobulator", root.getString("ANORDER[1]/PRODUCT"));

View Full Code Here

    /**
     * Specify connection properties in config
     */
    public void testReadWithConnectionProperties() throws Exception {

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

        Command read = commandGroup.getCommand("all customers");
        DataObject root = read.executeQuery();

        assertEquals(5, root.getList("CUSTOMER").size());

    }
View Full Code Here

    /**
     * Specify connection properties in config. Add explicit update command
     */
    public void testUpdate() throws Exception {

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

        Command read = commandGroup.getCommand("all customers");
        DataObject root = read.executeQuery();
        // Verify precondition
        assertFalse(root.get("CUSTOMER[1]/LASTNAME").equals("Pavick"));
        int id = root.getInt("CUSTOMER[1]/ID");

        Command update = commandGroup.getCommand("update customer");
        update.setParameterValue("ID", new Integer(id));
        update.execute();

        // Verify update - reuse select command
        root = read.executeQuery();
View Full Code Here

     * and related orders. Modify an order and flush changes back
     */
    public void testRead2() throws Exception {

        // Create the group and set common connection
        CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(getConfig("CustomersOrdersConfig.xml"));
        commandGroup.setConnection(getConnection());

        // Read all customers and remember the first one
        Command read = commandGroup.getCommand("all customers");
        DataObject root = read.executeQuery();
        Integer id = (Integer) root.get("CUSTOMER[1]/ID");

        // Read the specific Customer from above and its related orders
        Command custOrders = commandGroup.getCommand("customer and orders");
        custOrders.setParameterValue("ID", id);
        root = custOrders.executeQuery();

        // Modify the first order and flush this change back to the database
        root.setString("CUSTOMER[1]/orders[1]/PRODUCT", "Defibrillator");
        Integer orderId = (Integer) root.get("CUSTOMER[1]/orders[1]/ID");
        ApplyChangesCommand flush = commandGroup.getApplyChangesCommand();
        flush.execute(root);

        // Verify
        Command orderByID = commandGroup.getCommand("order by id");
        orderByID.setParameterValue("ID", orderId);
        assertEquals("Defibrillator", root.getString("ANORDER[1]/PRODUCT"));

    }
View Full Code Here

    }

    protected void testStrockPurchaseThroughDAS(purchaseStock sp) throws InstantiationException, IllegalAccessException, ClassNotFoundException,
            SQLException {

        CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(createConfigStream());
        commandGroup.setConnection(createConnection());
        Command read = commandGroup.getCommand("all stocks");

        DataObject root = read.executeQuery();

        // Create a new stockPurchase
        DataObject stockPurchase = root.createDataObject("STOCKS");
        stockPurchase.set("ID", new Integer(sp.getId()));
        stockPurchase.set("SYMBOL", sp.getStock().getSymbol());
        stockPurchase.set("QUANTITY", new Integer(sp.getStock().getQuantity()));
        stockPurchase.set("PURCHASEPRICE", new Float(11.00));
        stockPurchase.set("PURCHASEDATE", new Date());

        ApplyChangesCommand apply = commandGroup.getApplyChangesCommand();

        apply.execute(root);


View Full Code Here

        AccountSummary account = (AccountSummary) accounts.iterator().next();
        float newbalance = account.getBalance() - wd.getAmount();
        account.setBalance(newbalance);
        // update department set companyid = ? where department.name = ?

        CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(createConfigStream());
        commandGroup.setConnection(conn);
        Command update = commandGroup.getCommand("update balance");
        update.setParameterValue("BALANCE", new Float(newbalance));
        update.setParameterValue("ACCOUNTNUMBER", wd.getAccountNumber());

        update.execute();
        conn.close();
View Full Code Here

    /**
     * Read Company and traverse to EOTM
     */
    public void test1() throws Exception {

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

        Command read = commandGroup.getCommand("get companies with employee of the month");
        DataObject root = read.executeQuery();
        DataObject employee = root.getDataObject("COMPANY[1]/company->employee_opposite");

        assertEquals("Mary Smith", employee.getString("NAME"));
    }
View Full Code Here

    /**
     * Read Employee and traverse to Company
     */
    public void test2() throws Exception {

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

        Command read = commandGroup.getCommand("get named employee with company");
        read.setParameterValue("NAME", "Mary Smith");
        DataObject root = read.executeQuery();
        DataObject company = root.getDataObject("EMPLOYEE[1]/company->employee");

        assertEquals("ACME Publishing", company.getString("NAME"));
View Full Code Here

    /**
     * Un-assign employee O' month
     */
    public void test3() throws Exception {

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

        Command read = commandGroup.getCommand("get companies with employee of the month");
        DataObject root = read.executeQuery();
        DataObject company = root.getDataObject("COMPANY[1]");
        company.setDataObject("company->employee_opposite", null);
        assertNull(company.getDataObject("company->employee_opposite"));
  
        //Flush changes
        commandGroup.getApplyChangesCommand().execute(root);

        //Verify
        root = read.executeQuery();
        company = root.getDataObject("COMPANY[1]");
        assertNull(company.getDataObject("company->employee_opposite"));
View Full Code Here

TOP

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

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.