Package org.apache.tuscany.das.rdb

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


    /**
     * Read
     */
    public void testReadUsingConfigInput() throws Exception {
        Config config = ConfigUtil.loadConfig(getConfig("CustomersOrdersConfig.xml"));
        DAS das = DAS.FACTORY.createDAS(config, getConnection());

        Command read = das.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 {

        DAS das = DAS.FACTORY.createDAS(getConfig("CustomersOrdersConfig.xml"), getConnection());

        Command read = das.getCommand("order by id");
        read.setParameter(1, Integer.valueOf(1));
        DataObject root = read.executeQuery();

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

View Full Code Here

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

        DAS das = DAS.FACTORY.createDAS(getConfig("CustomersOrdersConfig.xml"), getConnection());

        Command read = das.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 = das.getCommand("update customer");
        update.setParameter(1, Integer.valueOf(id));
        update.execute();

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

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

        // Create the group and set common connection
        DAS das = DAS.FACTORY.createDAS(getConfig("CustomersOrdersConfig.xml"), getConnection());

        // Read all customers and remember the first one
        Command read = das.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 = das.getCommand("customer and orders");
        custOrders.setParameter(1, 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");
        das.applyChanges(root);

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

    }
View Full Code Here

    /**
     * Read a specific customer
     */
    public void testReadSingle() throws Exception {

        DAS das = DAS.FACTORY.createDAS(getConfig("CustomerConfigWithIDConverter.xml"), getConnection());   
        // Create and initialize command to read customers
        Command readCustomers = das.getCommand("literal");         

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

        // Verify
View Full Code Here

    public void testReadSingleVerifyShapeUse() throws Exception {

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

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

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

        // Verify
View Full Code Here

        assertEquals(2, firstOrder.getList("ORDERDETAILS").size());

    }

    public void testReadAndDelete() throws Exception {
        DAS das = DAS.FACTORY.createDAS(getConfig("OrdersOrderDetailsConfig.xml"), getConnection());
        Command getOrderDetails = das.createCommand("Select * from ORDERDETAILS where ORDERID = ? AND PRODUCTID = ?");

        getOrderDetails.setParameter(1, Integer.valueOf(1));
        getOrderDetails.setParameter(2, Integer.valueOf(1));

        DataObject root = getOrderDetails.executeQuery();

        DataObject orderDetail = (DataObject) root.get("ORDERDETAILS[1]");
        orderDetail.delete();
        das.applyChanges(root);

    }
View Full Code Here

        new BookData(getAutoConnection()).refresh();
    }

    public void testSimpleOCC() throws Exception {

        DAS das = DAS.FACTORY.createDAS(getConfig("BooksConfig.xml"), getConnection());
        // Read a book instance
        Command select = das.getCommand("select book 1");
        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 = das.getCommand("update book 1");
        update.setParameter(1, new Integer(100));
        update.execute();

        // Try to apply changes and catch the expected An update collision occurred
        try {
            das.applyChanges(root);
            fail("An OCCException should be thrown");
        } catch (RuntimeException ex) {
            if (!ex.getMessage().equals("An update collision occurred")) {
                throw ex;
            }
View Full Code Here

            }
        }
    }

    public void testManagedOCC() throws Exception {
        DAS das = DAS.FACTORY.createDAS(getConfig("ManagedBooksConfig.xml"), getConnection());
        Command select = das.getCommand("select book 1");
        DataObject root = select.executeQuery();
        DataObject book = root.getDataObject("BOOK[1]");
        // Change a field to mark the instance 'dirty'
        book.setInt("QUANTITY", 2);
        int occValue = book.getInt("OCC");
        das.applyChanges(root);

        root = select.executeQuery();
        book = root.getDataObject("BOOK[1]");
        assertEquals(occValue + 1, book.getInt("OCC"));
    }
View Full Code Here

        book = root.getDataObject("BOOK[1]");
        assertEquals(occValue + 1, book.getInt("OCC"));
    }

    public void testManagedOCCFailure() throws Exception {
        DAS das = DAS.FACTORY.createDAS(getConfig("ManagedBooksConfig.xml"), getConnection());
        // Read a book instance
        Command select = das.getCommand("select book 1");
        DataObject root = select.executeQuery();
        DataObject book = root.getDataObject("BOOK[1]");
        // Change a field to mark the instance 'dirty'
        book.setInt("QUANTITY", 2);

        DAS das2 = DAS.FACTORY.createDAS(getConfig("ManagedBooksConfig.xml"), getConnection());
        // Read a book instance
        Command select2 = das2.getCommand("select book 1");
        DataObject root2 = select2.executeQuery();
        DataObject book2 = root2.getDataObject("BOOK[1]");
        // Change a field to mark the instance 'dirty'
        book2.setInt("QUANTITY", 5);
        das2.applyChanges(root2);

        // Try to apply changes and catch the expecetd An update collision occurred
        try {
            das.applyChanges(root);
            fail("An OCCException should be thrown");
View Full Code Here

TOP

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

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.