Package org.apache.tuscany.das.rdb

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


        try {
            InputStream mapping = createConfigStream();
            Connection conn = getConnection();
            DAS das = DAS.FACTORY.createDAS(mapping, conn);

            Command select = das.createCommand("SELECT firstName, lastName, loginID, password, id FROM customers where loginID = ?");

            select.setParameter(1, logonID);

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

            Collection customers = root.getList("CustomerProfileData");
            CustomerProfileData customerProfileData = (CustomerProfileData) customers.iterator().next();
View Full Code Here


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

        try {
            DAS das = DAS.FACTORY.createDAS(getConnection());
            Command insert = das.createCommand("insert into customers (firstName,lastName,address,email, loginID, password  ) values ('"
                    + customerProfile.getFirstName() + "', '" + customerProfile.getLastName() + "', '" + customerProfile.getAddress() + "', '"
                    + customerProfile.getEmail() + "', '" + customerProfile.getLoginID() + "', '" + customerProfile.getPassword() + "')");

            insert.execute();
            CustomerProfileData ret = getCustomerProfile(customerProfile.getLoginID());
            String cid = ret.getId() + "";
            if (createSavings) {
                insert = das.createCommand("insert into accounts (id,accountNumber, accountType, balance  ) values (" + cid + ", '"
                        + AccountServiceImpl.SAVINGS_ACCOUNT_PREFIX + cid + "', '" + AccountServiceImpl.ACCOUNT_TYPE_SAVINGS + "', " + 1.0F + ")");
                insert.execute();

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

            }

            return ret;
        } catch (Exception e) {
View Full Code Here

    public CustomerProfileData createAccountNOTWORKING(CustomerProfileData customerProfile, boolean createSavings, boolean createCheckings)
            throws RemoteException {
        try {
            DAS das = DAS.FACTORY.createDAS(createConfigStream(), getConnection());
            Command read = das.getCommand("all customers");

            // select.setDataObjectModel();
            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

            InputStream mapping = createConfigStream();

            Connection conn = getConnection();
            DAS das = DAS.FACTORY.createDAS(mapping, conn);

            Command select = das.createCommand("SELECT accountNumber, accountType, balance FROM accounts where id = ?");
            select.setParameter(1, customerID);

            DataObject root = select.executeQuery();
            accountReport.getAccountSummaries().addAll(root.getList("AccountSummary"));

            // Get Stocks

            select = das.createCommand("SELECT Symbol, quantity, purchasePrice, purchaseDate, purchaseLotNumber  FROM stocks where id = ?");
            select.setParameter(1, customerID);

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

            root = select.executeQuery();
            accountReport.getStockSummaries().addAll(root.getList("StockSummary"));

            conn.close();

            return accountReport;
View Full Code Here

        try {
            Connection conn = getConnection();
            DAS das = DAS.FACTORY.createDAS(createConfigStream(), conn);

            Command select = das.createCommand("SELECT accountNumber, balance FROM accounts where accountNumber = ?");
            select.setParameter(1, account);

            DataObject root = select.executeQuery();
            Collection accounts = root.getList("AccountSummary");
            AccountSummary accountData = (AccountSummary) accounts.iterator().next();
            float newbalance = accountData.getBalance() + ammount;
            accountData.setBalance(newbalance);
            // update department set companyid = ? where department.name = ?

            Command update = das.getCommand("update balance");
            update.setParameter(1, new Float(newbalance));
            update.setParameter(2, account);
            update.execute();
            conn.close();
            return newbalance;
        } catch (Exception e) {
            throw new RemoteException(e.getClass().getName(), e);
        }
View Full Code Here

    public StockSummary sellStock(int purchaseLotNumber, int quantity) throws RemoteException {
        try {
            DAS das = DAS.FACTORY.createDAS(createConfigStream(), getConnection());

            Command read = das.getCommand("stockbylotSelect");
            read.setParameter(1, purchaseLotNumber);// autoboxing :-)
            DataObject root = read.executeQuery();
            List stocks = root.getList("StockSummary");
            if (null != stocks && !stocks.isEmpty()) {
                StockSummary stock = (StockSummary) stocks.get(0);
                int newQuatity = Math.max(stock.getQuantity() - quantity, 0);
                if (newQuatity < 1) {

                    Command delete = das.createCommand("DELETE FROM STOCKS WHERE PURCHASELOTNUMBER = ?");
                    delete.setParameter(1, purchaseLotNumber);
                    delete.execute();

                } else {

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

                    update.setParameter(1, newQuatity);
                    update.setParameter(2, purchaseLotNumber);
                    update.execute();

                    stock.setQuantity(newQuatity);
                }
                return stock;
            }
View Full Code Here

    public StockSummary purchaseStock(int id, StockSummary stock) throws RemoteException {

        try {
            DAS das = DAS.FACTORY.createDAS(getConnection());
            Command insert = das.createCommand("insert into stocks (id, symbol, quantity, purchasePrice, purchaseDate) values (?,?,?,?,?)");
            insert.setParameter(1, new Integer(id));
            insert.setParameter(2, stock.getSymbol());
            insert.setParameter(3, stock.getQuantity());
            insert.setParameter(4, stock.getPurchasePrice());
            insert.setParameter(5, DateConverter.INSTANCE.getColumnValue(stock.getPurchaseDate()));

            insert.execute();

            return stock;
        } catch (Exception e) {
            if (e instanceof RemoteException) {
                throw (RemoteException) e;
View Full Code Here

    public void testWithdrawThroughDAS(withdraw wd) throws Exception {

        Connection conn = createConnection();
        DAS das = DAS.FACTORY.createDAS(createConfigStream(), conn);
        Command select = das.getCommand("get account");

        select.setParameter(1, wd.getAccountNumber());

        DataObject root = select.executeQuery();

        Collection accounts = root.getList("AccountSummary");
        AccountSummary account = (AccountSummary) accounts.iterator().next();
        float newbalance = account.getBalance() - wd.getAmount();
        account.setBalance(newbalance);
        // update department set companyid = ? where department.name = ?

        Command update = das.getCommand("update balance");
        update.setParameter(1, new Float(newbalance));
        update.setParameter(2, wd.getAccountNumber());

        update.execute();
        conn.close();
    }
View Full Code Here

    protected void testStrockPurchaseThroughDAS(purchaseStock sp) throws InstantiationException, IllegalAccessException, ClassNotFoundException,
            SQLException {

        DAS das = DAS.FACTORY.createDAS(createConfigStream(), createConnection());
        Command read = das.getCommand("all stocks");

        DataObject root = read.executeQuery();

        // Create a new stockPurchase
        DataObject stockPurchase = root.createDataObject("StockSummary");
        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();
        Connection conn = createConnection();
        DAS das = DAS.FACTORY.createDAS(mapping, conn);
        Command select = das.createCommand("SELECT firstName, lastName, loginID, password, id FROM customers where loginID = ?");

        select.setParameter(1, logonID);

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

        Collection customers = root.getList("CustomerProfileData");
        CustomerProfileData customerProfileData = (CustomerProfileData) customers.iterator().next();
        System.out.println(customerProfileData);
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.