Package org.apache.tuscany.das.rdb

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


    /**
     * Delete employee O' month
     */
    public void test4() 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]");
        DataObject employee = company.getDataObject("company->employee_opposite");
        employee.delete();
        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


    /**
     * Add new employee O' month
     */
    public void test5() 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]");
       
        //Create a new employee
        DataObject employee = root.createDataObject("EMPLOYEE");
        employee.setString ("NAME", "Joe Hotshot");
       
      //Assigne a EOTM
        //Strangely this statement results in "Could not find relationships" error
        //although "company.setDataObject("company->employee_opposite", null);" dos not  
        company.setDataObject("company->employee_opposite", employee);    
        
        //Flush changes
        commandGroup.getApplyChangesCommand().execute(root);

        //Verify
        root = read.executeQuery();
        company = root.getDataObject("COMPANY[1]");
       
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]");
View Full Code Here

     * Test ability to correctly flush heirarchy of objects that have generated
     * 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

    /**
     * Test ability to get an empty graph with the Types/Properties intact
     */
    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"
View Full Code Here

    }

    public CustomerProfileData createAccountNOTWORKING(CustomerProfileData customerProfile, boolean createSavings, boolean createCheckings)
            throws RemoteException {
        try {
            CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(createConfigStream());
            commandGroup.setConnection(getConnection());
            Command read = commandGroup.getCommand("all customers");

            // select.setDataObjectModel();
            TypeHelper helper = TypeHelper.INSTANCE;
            read.setDataObjectModel(helper.getType(DataGraphRoot.class));
            DataObject root = read.executeQuery();

            // Create a new stockPurchase
            DataObject customer = root.createDataObject("customerProfileData");

            // THIS SEEMS TO BE THE ONLY WAY TO DO THIS .. NO WAY TO JUST ADD AN EXISTING CUSTOMER.
            customer.set("firstName", customerProfile.getFirstName());
            customer.set("lastName", customerProfile.getLastName());
            customer.set("address", customerProfile.getAddress());
            customer.set("email", customerProfile.getEmail());
            customer.set("loginID", customerProfile.getLoginID());
            customer.set("password", customerProfile.getPassword());

            ApplyChangesCommand apply = commandGroup.getApplyChangesCommand();
            apply.execute(root);
            return getCustomerProfile(customerProfile.getLoginID());

        } catch (Exception e) {
            if (e instanceof RemoteException)
View Full Code Here

            Collection accounts = root.getAccountSummaries();
            AccountSummary accountData = (AccountSummary) accounts.iterator().next();
            float newbalance = accountData.getBalance() + ammount;
            accountData.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", account);
            update.execute();
            conn.close();
            return newbalance;
View Full Code Here

    }

    public StockSummary sellStock(int purchaseLotNumber, int quantity) throws RemoteException {
        try {
            CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(createConfigStream());
            commandGroup.setConnection(getConnection());

            Command read = commandGroup.getCommand("stockbylotSelect");
            TypeHelper helper = TypeHelper.INSTANCE;
            read.setDataObjectModel(helper.getType(DataGraphRoot.class));
            read.setParameterValue("PURCHASELOTNUMBER", purchaseLotNumber);// autoboxing :-)
            DataGraphRoot root = (DataGraphRoot) read.executeQuery();
            List stocks = root.getStockSummaries();
            if (null != stocks && !stocks.isEmpty()) {
                StockSummary stock = (StockSummary) stocks.get(0);
                int newQuatity = Math.max(stock.getQuantity() - quantity, 0);
                if (newQuatity < 1) {

                    Command delete = Command.FACTORY.createCommand("DELETE FROM STOCKS WHERE PURCHASELOTNUMBER = ?");
                    delete.setParameterValue(1, purchaseLotNumber);
                    delete.setConnection(getConnection());
                    delete.execute();

                } else {

                    Command update = commandGroup.getCommand("stockbylot");

                    update.setParameterValue("QUANTITY", newQuatity);
                    update.setParameterValue("PURCHASELOTNUMBER", purchaseLotNumber);
                    update.execute();
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.