Package org.apache.tuscany.das.rdb

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


    /**
     * Simple read followed by a write. This should fail since there is no
     * config associaed with the applychanges command
     */
    public void test1() throws Exception {
        DAS das = DAS.FACTORY.createDAS(getConnection());
        // Read a book instance
        Command select = das.createCommand("SELECT * FROM BOOK WHERE BOOK_ID = 1");
        DataObject root = select.executeQuery();

        DataObject book = root.getDataObject("BOOK[1]");
        // Change a field to mark the instance 'dirty'
        book.setInt("QUANTITY", 2);

        try {
            das.applyChanges(root);
            fail("An exception should be thrown since here is no config to identify the primary key");
        } catch (RuntimeException ex) {
            // Expected
        }
    }
View Full Code Here


     */
    public void test2() throws Exception {
        // Create config programmatically
        ConfigHelper helper = new ConfigHelper();
        helper.addPrimaryKey("BOOK.BOOK_ID");
        DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection());

        // Read a book instance
        Command select = das.createCommand("SELECT * FROM BOOK WHERE BOOK_ID = 1");
        DataObject root = select.executeQuery();
        DataObject book = root.getDataObject("BOOK[1]");
        // Change a field to mark the instance 'dirty'
        book.setInt("QUANTITY", 2);

        // Flush the change

        das.applyChanges(root);

        // Verify
        root = select.executeQuery();
        book = root.getDataObject("BOOK[1]");
        assertEquals(2, book.getInt("QUANTITY"));
View Full Code Here

        // Read some customers and related orders
        // Create relationship config programmatically
        ConfigHelper helper = new ConfigHelper();
        helper.addRelationship("CUSTOMER.ID", "ANORDER.CUSTOMER_ID");
        DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection());
        Command select = das.createCommand(statement);

        DataObject root = select.executeQuery();
        DataObject customer = root.getDataObject("CUSTOMER[1]");

        assertEquals(2, customer.getList("ANORDER").size());
View Full Code Here

    }

    public void testSimple() throws Exception {

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

        // Build the select command
        Command selectCommand = das.createCommand("select COMPANY.NAME, "
                + "EMPLOYEE.NAME, EMPLOYEE.SN, EMPLOYEE.MANAGER, "
                + "DEPARTMENT.NAME, DEPARTMENT.LOCATION, DEPARTMENT.DEPNUMBER from COMPANY, DEPARTMENT, EMPLOYEE "
                + "where COMPANY.ID=DEPARTMENT.COMPANYID and DEPARTMENT.ID=EMPLOYEE.DEPARTMENTID");

        // Get the graph
View Full Code Here

        assertEquals("John Jones", employee.get("NAME"));
    }

    public void testSimpleStatic() throws Exception {

        DAS das = DAS.FACTORY.createDAS(getConfig("companyMappingWithConverters.xml"), getConnection());
        SDOUtil.registerStaticTypes(CompanyFactory.class);
        // Build the select command
        Command selectCommand = das.createCommand("select COMPANY.NAME, "
                + "EMPLOYEE.NAME, EMPLOYEE.SN, EMPLOYEE.MANAGER, "
                + "DEPARTMENT.NAME, DEPARTMENT.LOCATION, DEPARTMENT.DEPNUMBER from COMPANY, DEPARTMENT, EMPLOYEE "
                + "where COMPANY.ID=DEPARTMENT.COMPANYID and DEPARTMENT.ID=EMPLOYEE.DEPARTMENTID");

        // Get the graph
View Full Code Here

     * This tests provides invalid SQL and should fail on Apply.execute. If not
     * then the engine is generating CUD and overlooking the provided
     * statements.
     */
    public void testCUDGeneration1() throws Exception {
        DAS das = DAS.FACTORY.createDAS(getConfig("basicCustomerMappingWithInvalidCUD.xml"), getConnection());

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

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

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

        // Flush changes
        try {
            das.applyChanges(root);
            fail("Should fail with invalid SQL.  Provided CUD not used!!");
        } catch (RuntimeException e) {
            // Everything OK
        }

View Full Code Here

        }

    }

    public void testInsertCUDGeneration() throws Exception {
        DAS das = DAS.FACTORY.createDAS(getConnection());

        Command select = das.createCommand("Select * from CUSTOMER where ID = 1");
        DataObject root = select.executeQuery();

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

        das.applyChanges(root);

        select = das.createCommand("select * from CUSTOMER where ID = 720");
        root = select.executeQuery();

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

        assertEquals(1, root.getList("CUSTOMER").size());
    }

    public void testReadModifyApply() throws Exception {

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

        // Build the select command to read a specific customer and related
        // orders
        Command select = das.createCommand("SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON "
                + "CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = ?");

        // Parameterize the command
        select.setParameter(1, Integer.valueOf(1));

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

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

        // Modify an order
        DataObject order = (DataObject) customer.get("orders[1]");
        order.setString("PRODUCT", "Kitchen Sink 001");

        das.applyChanges(root);

    }
View Full Code Here

        // Create and initialize a DAS connection and initialize for externally
        // managed transaction boundaries
        java.sql.Connection c = getConnection();

        DAS das = DAS.FACTORY.createDAS(getConfig("passiveConnection.xml"), c);
        // Read customer 1
        Command select = das.getCommand("get a customer");
        DataObject root = select.executeQuery();

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

        String lastName = customer.getString("LASTNAME");

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

        try {
            das.applyChanges(root);

            throw new Exception("Test Exception");

            // Since the DAS is not managing tx boundaries, I must
        } catch (Exception e) {
            // assert here to make sure we didn't run into some hidden error
            assertEquals("Test Exception", e.getMessage());
            // Roll back the transaction
            c.rollback();
        }

        // Verify that the changes did not go through
        root = select.executeQuery();
        assertEquals(lastName, root.getString("CUSTOMER[1]/LASTNAME"));

        // Try again
        customer = (DataObject) root.get("CUSTOMER[1]");
        customer.set("LASTNAME", "Pavick");
        das.applyChanges(root);
        c.commit();

        root = select.executeQuery();
        assertEquals("Pavick", root.getString("CUSTOMER[1]/LASTNAME"));
    }
View Full Code Here

    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testRead() throws Exception {
        DAS das = DAS.FACTORY.createDAS(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();
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.