Package org.apache.tuscany.das.rdb

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


 
 
  public void testReadTableInfo() throws Exception {
   
    Command select = Command.FACTORY.createCommand("SELECT * from SYSIBM.SYSTABLES WHERE TYPE = 'T'")
    select.setConnection(getConnection());
    DataObject root = select.executeQuery();
   
    DataObject table = (DataObject)root.get("SYSTABLES[1]");
   
    assertEquals('T', table.getChar("TYPE"));
     
View Full Code Here


     * config associaed with the applychanges command
     */
    public void test_1() 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);

        // Flush the change
View Full Code Here

     * programmatically using the ConfigHelper.
     */
    public void test_2() 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);

        // Flush the change
        // Create config programmatically
        ConfigHelper helper = new ConfigHelper();
        helper.addPrimaryKey("BOOK.BOOK_ID");

        ApplyChangesCommand apply = Command.FACTORY.createApplyChangesCommand(helper.getConfig());
        apply.setConnection(getConnection());

        apply.execute(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");
       
        Command select = Command.FACTORY.createCommand(statement, helper.getConfig());
        select.setConnection(getConnection());

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

        assertEquals(2, customer.getList("ANORDER").size());

    }
View Full Code Here

        // Create Table config programmatically
        ConfigHelper helper = new ConfigHelper();
        helper.addTable("BOOK", "Book");
        helper.addPrimaryKey("Book.BOOK_ID");
       
        Command select = Command.FACTORY.createCommand(statement, helper.getConfig());
        select.setConnection(getConnection());
        select.setParameterValue("ID", new Integer(1));

        DataObject root = select.executeQuery();
       
        DataObject newBook = root.createDataObject("Book");
        newBook.setString("NAME", "Ant Colonies of the Old World");
        newBook.setInt("BOOK_ID", 1001);
        root.getList("Book").add(newBook);
              
        ApplyChangesCommand apply = Command.FACTORY.createApplyChangesCommand(helper.getConfig());
        apply.setConnection(getConnection());
        apply.execute(root);
       
        //Verify
        select.setParameterValue("ID", new Integer(1001));
        root = select.executeQuery();
        assertEquals("Ant Colonies of the Old World", root.getString("Book[1]/NAME"));
       
    }
View Full Code Here

    public CustomerProfileData getCustomerProfile(String logonID) throws RemoteException {

        try {
            InputStream mapping = createConfigStream();
            Command select = Command.FACTORY.createCommand(
                    "SELECT firstName, lastName, loginID, password, id FROM customers where loginID = :loginID", mapping);
            Connection conn = getConnection();
            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();
           
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 = getConnection();
        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();
        return customerProfileData;
View Full Code Here

    public CustomerProfileData createAccount(CustomerProfileData customerProfile, boolean createSavings, boolean createCheckings)
            throws RemoteException {

        try {
            Command insert = Command.FACTORY.createCommand("insert into customers (firstName,lastName,address,email, loginID, password  ) values ('"
                    + customerProfile.getFirstName() + "', '" + customerProfile.getLastName() + "', '" + customerProfile.getAddress() + "', '"
                    + customerProfile.getEmail() + "', '" + customerProfile.getLoginID() + "', '" + customerProfile.getPassword() + "')");
            insert.setConnection(getConnection());
            insert.execute();
            CustomerProfileData ret = getCustomerProfile(customerProfile.getLoginID());
            String cid = ret.getId() + "";
            if (createSavings) {
                insert = Command.FACTORY.createCommand("insert into accounts (id,accountNumber, accountType, balance  ) values (" + cid + ", '"
                        + AccountServiceImpl.SAVINGS_ACCOUNT_PREFIX + cid + "', '" + AccountServiceImpl.ACCOUNT_TYPE_SAVINGS + "', " + 1.0F + ")");
                insert.setConnection(getConnection());
                insert.execute();

            }
            if (createCheckings) {
                insert = Command.FACTORY.createCommand("insert into accounts (id,accountNumber, accountType, balance  ) values (" + cid + ", '"
                        + AccountServiceImpl.CHECKING_ACCOUNT_PREFIX + cid + "', '" + AccountServiceImpl.ACCOUNT_TYPE_CHECKINGS + "', " + 1.0F + ")");
                insert.setConnection(getConnection());
                insert.execute();

            }

            return ret;
        } catch (Exception e) {
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.
View Full Code Here

        try {
            final AccountFactory accountFactory = AccountFactory.INSTANCE;
            final AccountReport accountReport = accountFactory.createAccountReport();
            InputStream mapping = createConfigStream();

            Command select = Command.FACTORY.createCommand("SELECT accountNumber, accountType, balance FROM accounts where id = :id", mapping);
            Connection conn = getConnection();
            select.setConnection(conn);
            select.setParameterValue("id", customerID);
            TypeHelper helper = TypeHelper.INSTANCE;
            select.setDataObjectModel(helper.getType(DataGraphRoot.class));
            DataGraphRoot root = (DataGraphRoot) select.executeQuery();
            accountReport.getAccountSummaries().addAll(root.getAccountSummaries());

            // Get Stocks

            select = Command.FACTORY.createCommand(
                    "SELECT Symbol, quantity, purchasePrice, purchaseDate, purchaseLotNumber  FROM stocks where id = :id", createConfigStream());
            select.setConnection(conn);
            select.setParameterValue("id", customerID);
            select.setDataObjectModel(helper.getType(DataGraphRoot.class));

            // select.addConverter("STOCKS.PURCHASEDATE", DateConverter.class.getName());

            root = (DataGraphRoot) select.executeQuery();
            accountReport.getStockSummaries().addAll(root.getStockSummaries());

            conn.close();

            return accountReport;
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.