Package org.apache.tuscany.das.rdb

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


        Type[] types = { SDODataTypes.LONG, SDODataTypes.STRING, SDODataTypes.STRING };

        ResultSetShape shape = new ResultSetShape(tables, columns, types);

        // Create and initialize command to read customers
        Command readCustomers = Command.FACTORY.createCommand(sqlString,
                getConfig("CustomerConfigWithIDConverter.xml"));
        // Specify result shape
        readCustomers.setResultSetShape(shape);

        readCustomers.setConnection(getConnection());

        // Read
        DataObject root = readCustomers.executeQuery();

        // Verify
        assertEquals(5, root.getList("CUSTOMER").size());
        assertEquals(99, root.getInt("CUSTOMER[1]/ID"));
        assertEquals("Roosevelt", root.getString("CUSTOMER[1]/LASTNAME"));
View Full Code Here


        // Using literals in the select forces invalid resultset metadata
        String sqlString = "Select 99, 'Roosevelt', '1600 Pennsylvania Avenue' from customer";

        // Create and initialize command to read customers
        Command readCustomers = Command.FACTORY.createCommand(sqlString);
        readCustomers.setConnection(getConnection());

        // Read
        DataObject root = readCustomers.executeQuery();

        // Verify
        try {
            assertEquals(5, root.getList("CUSTOMER").size());
            fail("Should fail since there will be no feature named CUSTOMER");
View Full Code Here

   * Read various types. 
   */
  public void testRead() throws Exception {

    //Read customer 1
    Command select = Command.FACTORY.createCommand("Select * from TYPETEST where ID = 1")
    select.setConnection(getConnection());
    DataObject root = select.executeQuery();
   
    DataObject types = (DataObject)root.get("TYPETEST[1]");
   
    java.sql.Timestamp ts = (java.sql.Timestamp)types.get("ATIMESTAMP");
    assertEquals(ts, TypesData.getTimestamp());
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());
View Full Code Here

    public CustomerProfileData testgetCustomerByLoginIDThroughDASRead(final String logonID) throws Exception {

        InputStream mapping = createConfigStream();

        Command select = Command.FACTORY.createCommand("SELECT firstName, lastName, loginID, password, id FROM customers where loginID = :loginID",
                mapping);
        Connection conn = createConnection();
        select.setConnection(conn);
        select.setParameterValue("loginID", logonID);
        TypeHelper helper = TypeHelper.INSTANCE;

        select.setDataObjectModel(helper.getType(DataGraphRoot.class));

        DataGraphRoot root = (DataGraphRoot) select.executeQuery();
        conn.close();

        Collection customers = root.getCustomerProfileData();
        CustomerProfileData customerProfileData = (CustomerProfileData) customers.iterator().next();
        System.out.println(customerProfileData);
View Full Code Here

    }

    public void testWithdrawThroughDAS(withdraw wd) throws Exception {

        Command select = Command.FACTORY.createCommand("SELECT accountNumber, balance FROM accounts where accountNumber = :accountNumber",
                createConfigStream());
        Connection conn = createConnection();
        select.setConnection(conn);
        select.setParameterValue("accountNumber", wd.getAccountNumber());
        TypeHelper helper = TypeHelper.INSTANCE;

        select.setDataObjectModel(helper.getType(DataGraphRoot.class));

        DataGraphRoot root = (DataGraphRoot) select.executeQuery();

        Collection accounts = root.getAccountSummaries();
        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

        super.tearDown();
    }

    public void testRead() throws Exception {

        Command getOrderDetails = Command.FACTORY
                .createCommand("Select * from ORDERDETAILS where ORDERID = :ORDERID AND PRODUCTID = :PRODUCTID");
        getOrderDetails.setConnection(getConnection());

        getOrderDetails.setParameterValue("ORDERID", new Integer(1));
        getOrderDetails.setParameterValue("PRODUCTID", new Integer(1));

        DataObject root = getOrderDetails.executeQuery();

        DataObject orderDetail = (DataObject) root.get("ORDERDETAILS[1]");
        assertEquals(1.1f, orderDetail.getFloat("PRICE"), 0.01);

    }
View Full Code Here

    }

    public void testReadModifyWrite2() throws Exception {

        Command getOrderDetails = Command.FACTORY
                .createCommand("Select * from ORDERDETAILS where ORDERID = 1 AND PRODUCTID = 1");
        getOrderDetails.setConnection(getConnection());
        DataObject root = getOrderDetails.executeQuery();

        DataObject orderDetails = (DataObject) root.get("ORDERDETAILS[1]");
        assertEquals(1.1f, orderDetails.getFloat("PRICE"), 0.01);

        // Modify
        orderDetails.setFloat("PRICE", 0f);

        // Build apply changes command
        ApplyChangesCommand apply = Command.FACTORY.createApplyChangesCommand(getConfig("OrdersOrderDetailsConfig.xml"));
        apply.setConnection(getConnection());

        // Write
        apply.execute(root);

        // Verify
        root = getOrderDetails.executeQuery();
        orderDetails = root.getDataObject("ORDERDETAILS[1]");
        assertEquals(0f, orderDetails.getFloat("PRICE"), 0.01);

    }
View Full Code Here

    }
   
    public void testReadOrdersAndDetails2() throws Exception {

        Command read = Command.FACTORY
                .createCommand("SELECT * FROM ANORDER LEFT JOIN ORDERDETAILS ON ANORDER.ID = ORDERDETAILS.ORDERID ORDER BY ANORDER.ID", getConfig("OrdersOrderDetailsConfig.xml"));
        read.setConnection(getConnection());

        DataObject root = read.executeQuery();

        DataObject firstOrder = root.getDataObject("ANORDER[1]");
        assertEquals(1, firstOrder.getInt("ID"));
        assertEquals(2, firstOrder.getList("ORDERDETAILS").size());

View Full Code Here

 
  public void testSimpleOCC() 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);

    // Explicitly change OCC column in database to force collision
    Command update = Command.FACTORY
        .createCommand("update BOOK set OCC = :OCC where BOOK_ID = 1");
    update.setConnection(getConnection());
    update.setParameterValue("OCC", new Integer(100));
    update.execute();

    //Try to flush the change
    ApplyChangesCommand apply = Command.FACTORY.createApplyChangesCommand(getConfig("BooksConfig.xml"));
    apply.setConnection(getConnection());

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.