Examples of VoltTableRow


Examples of org.voltdb.VoltTableRow

                    type_limit_sell, price_quotes[i],
                    type_limit_buy, price_quotes[i]);
            VoltTable reqs = voltExecuteSQL()[0];
           
            for (int j = 0; j < reqs.getRowCount() && tradeRequestBuffer.size() < MAX_SEND_LEN; j++) {
                VoltTableRow req = reqs.fetchRow(j);
               
                long trade_id = req.getLong("TR_T_ID");
                double price_quote = req.getDouble("TR_BID_PRICE");
                String trade_type = req.getString("TR_TT_ID");
                int trade_qty = (int)req.getLong("TR_QTY");
               
                voltQueueSQL(updateTrade, now_dts, status_submitted, trade_id);
                voltQueueSQL(deleteTradeRequest, trade_id);
                voltQueueSQL(insertTradeHistory, trade_id, now_dts, status_submitted);
                voltExecuteSQL();
View Full Code Here

Examples of org.voltdb.VoltTableRow

        // info about the trade
        voltQueueSQL(getTrade, trade_id);
        VoltTable trade = voltExecuteSQL()[0];
       
        assert trade.getRowCount() == 1;
        VoltTableRow trade_row = trade.fetchRow(0);
       
        long acct_id = trade_row.getLong("T_CA_ID");
        String type_id = trade_row.getString("T_TT_ID");
        String symbol = trade_row.getString("T_S_SYMB");
        int trade_qty = (int)trade_row.getLong("T_QTY");
        double charge = trade_row.getDouble("T_CHRG");
        int is_lifo = (int)(int)trade_row.getLong("T_LIFO");
        int trade_is_cash = (int)trade_row.getLong("T_IS_CASH");
       
        // info about a  type of the trade and customer's holdings for the symbol
        voltQueueSQL(getTradeType, type_id);
        voltQueueSQL(getHoldingSummary, acct_id, symbol);
        VoltTable[] trade_type_hold = voltExecuteSQL();
       
        VoltTable trade_type = trade_type_hold[0];
        assert trade_type.getRowCount() == 1;
        VoltTableRow trade_type_row = trade_type.fetchRow(0);
       
        String type_name = trade_type_row.getString("TT_NAME");
        int type_is_sell = (int)(int)trade_type_row.getLong("TT_IS_SELL");
        int type_is_market = (int)trade_type_row.getLong("TT_IS_MRKT");
       
        VoltTable hold_sum = trade_type_hold[1];
        int hs_qty = 0;
        if (hold_sum.getRowCount() > 0) {
            assert hold_sum.getRowCount() == 1;
            hs_qty = (int)hold_sum.fetchRow(0).getLong("HS_QTY");
        }
       
        // frame 2: modifying the customer's holdings
       
        // first, some cusomer's account info
        voltQueueSQL(getCustomerAccount, acct_id);
        VoltTable account = voltExecuteSQL()[0];
       
        assert account.getRowCount() == 1;
        VoltTableRow account_row = account.fetchRow(0);
       
        long broker_id = account_row.getLong("CA_B_ID");
        long cust_id = account_row.getLong("CA_C_ID");
        int tax_status = (int)account_row.getLong("CA_TAX_ST");
       
        int needed_qty = trade_qty;
        double buy_value = 0;
        double sell_value = 0;
        Date trade_dts = Calendar.getInstance().getTime();
       
        if (type_is_sell == 1) {
            if (hs_qty == 0) {
                voltQueueSQL(insertHoldingSummary, acct_id, symbol, -trade_qty);
                voltExecuteSQL();
            }
            else if (hs_qty != trade_qty) {
                voltQueueSQL(updateHoldingSummary, hs_qty - trade_qty, acct_id, symbol);
                voltExecuteSQL();
            }
           
            if (hs_qty > 0) {
                if (is_lifo == 1) {
                    voltQueueSQL(getHoldingDesc, acct_id, symbol);
                }
                else {
                    voltQueueSQL(getHoldingAsc, acct_id, symbol);
                }
               
                // modify existing holdings
                VoltTable hold_list = voltExecuteSQL()[0];
                for (int i = 0; i < hold_list.getRowCount() && needed_qty != 0; i++) {
                    VoltTableRow hold = hold_list.fetchRow(i);
                   
                    long hold_id = hold.getLong("H_T_ID");
                    int hold_qty = (int)hold.getLong("H_QTY");
                    double hold_price = hold.getDouble("H_PRICE");
                   
                    if (hold_qty > needed_qty) {
                        voltQueueSQL(insertHoldingHistory, hold_id, trade_id, hold_qty, hold_qty - needed_qty);
                        voltQueueSQL(updateHolding, hold_qty - needed_qty, hold_id);
                       
                        buy_value += needed_qty * hold_price;
                        sell_value += needed_qty * trade_price;
                        needed_qty = 0;
                    }
                    else {
                        voltQueueSQL(insertHoldingHistory, hold_id, trade_id, hold_qty, 0);
                        voltQueueSQL(deleteHolding, hold_id);
                       
                        buy_value += hold_qty * hold_price;
                        sell_value += hold_qty * trade_price;
                        needed_qty = needed_qty - hold_qty;
                    }
                }
                // execute all updates from the above loop
                voltExecuteSQL();
            }
               
            // need to sell more? go short
            if (needed_qty > 0) {
                voltQueueSQL(insertHoldingHistory, trade_id, trade_id, 0, -needed_qty);
                voltQueueSQL(insertHolding, trade_id, acct_id, symbol, trade_dts, trade_price, -needed_qty);
                voltExecuteSQL();
            }
            else if (hs_qty == trade_qty) {
                voltQueueSQL(deleteHoldingSummary, acct_id, symbol);
                voltExecuteSQL();
            }
        }
        else { // buy trade
            if (hs_qty == 0) {
                voltQueueSQL(insertHoldingSummary, acct_id, symbol, trade_qty);
                voltExecuteSQL();
            }
            else if (-hs_qty != trade_qty) {
                voltQueueSQL(updateHoldingSummary, hs_qty + trade_qty, acct_id, symbol);
                voltExecuteSQL();
            }
           
            if (hs_qty < 0) {
                if (is_lifo == 1) {
                    voltQueueSQL(getHoldingDesc, acct_id, symbol);
                }
                else {
                    voltQueueSQL(getHoldingAsc, acct_id, symbol);
                }
               
                // modify existing holdings
                VoltTable hold_list = voltExecuteSQL()[0];
                for (int i = 0; i < hold_list.getRowCount() && needed_qty != 0; i++) {
                    VoltTableRow hold = hold_list.fetchRow(i);
                   
                    long hold_id = hold.getLong("H_T_ID");
                    int hold_qty = (int)hold.getLong("H_QTY");
                    double hold_price = hold.getDouble("H_PRICE");
                   
                    if (hold_qty + needed_qty < 0) {
                        voltQueueSQL(insertHoldingHistory, hold_id, trade_id, hold_qty, hold_qty + needed_qty);
                        voltQueueSQL(updateHolding, hold_qty + needed_qty, hold_id);
                       
                        sell_value += needed_qty * hold_price;
                        buy_value += needed_qty * trade_price;
                        needed_qty = 0;
                    }
                    else {
                        voltQueueSQL(insertHoldingHistory, hold_id, trade_id, hold_qty, 0);
                        voltQueueSQL(deleteHolding, hold_id);
                       
                        hold_qty = -hold_qty;
                        sell_value += hold_qty * hold_price;
                        buy_value += hold_qty * trade_price;
                        needed_qty = needed_qty - hold_qty;
                    }
                }
                // execute all updates from the above loop
                voltExecuteSQL();
            }
               
            // all shorts are covered? a new long is created
            if (needed_qty > 0) {
                voltQueueSQL(insertHoldingHistory, trade_id, trade_id, 0, needed_qty);
                voltQueueSQL(insertHolding, trade_id, acct_id, symbol, trade_dts, trade_price, needed_qty);
                voltExecuteSQL();
            }
            else if (-hs_qty == trade_qty) {
                voltQueueSQL(deleteHoldingSummary, acct_id, symbol);
                voltExecuteSQL();
            }
        }
       
        // frame 3: taxes
        double tax_amount = 0;
        if ((tax_status == 1 || tax_status == 2) && sell_value > buy_value) {
            voltQueueSQL(getTaxrate, cust_id);
            VoltTable tax_rate = voltExecuteSQL()[0];
           
            assert tax_rate.getRowCount() == 1;
            double tax_rates = tax_rate.fetchRow(0).getDouble(0);
            tax_amount = (sell_value - buy_value) * tax_rates;
           
            voltQueueSQL(updateTrade1, tax_amount, trade_id);
            voltExecuteSQL();
        }
       
        // frame 4: calculate the broker's commission
        voltQueueSQL(getSecurity, symbol);
        voltQueueSQL(getCustomer, cust_id);
        VoltTable[] sec_cust = voltExecuteSQL();
       
        VoltTable sec = sec_cust[0];
        VoltTable cust = sec_cust[1];
       
        assert sec.getRowCount() == 1;
        assert cust.getRowCount() == 1;
       
        VoltTableRow sec_row = sec.fetchRow(0);
        String s_ex_id = sec_row.getString("S_EX_ID");
        String s_name = sec_row.getString("S_NAME");
        int c_tier = (int)cust.fetchRow(0).getLong("C_TIER");
       
        voltQueueSQL(getCommissionRate, c_tier, type_id, s_ex_id, trade_qty, trade_qty); // limit to 1 row
        VoltTable comm = voltExecuteSQL()[0];
       
View Full Code Here

Examples of org.voltdb.VoltTableRow

           
            // DATA
            this.output[i] = new Object[vt.getRowCount()][vt.getColumnCount()];
            int j = 0;
            while (vt.advanceRow()) {
                VoltTableRow row = vt.getRow();
                for (int k = 0; k < this.output[i][j].length; k++) {
                    this.output[i][j][k] = row.get(k);
                } // FOR (columns)
                j++;
            } // WHILE (rows)
        } // FOR (tables)
    }
View Full Code Here

Examples of org.voltdb.VoltTableRow

                /*
                 * we should "retrieve" some values here, however only is_cash and is_mrkt are required
                 * other values just serve as frame OUT params
                 * the values are in memory so it would not be cheating not to retrieve them -- it's cheap anyway
                 */
                VoltTableRow trade_row = trade.fetchRow(0);
                is_cash[i] = (int)trade_row.getLong("T_IS_CASH");
                is_market[i] = (int)trade_row.getLong("TT_IS_MRKT");
               
                if (is_cash[i] == 1) {
                    voltQueueSQL(getCash, trade_ids[i]);
                }
            }
           
            voltExecuteSQL(); // for possible cash transactions; the result is not needed for the client
           
            // results
            result = trade_lookup_ret_template_frame1.clone(256);
            for (int i = 0; i < max_trades; i++) {
                result.addRow(is_cash[i], is_market[i]);
            }
        }
        else if (frame_to_execute == 2 || frame_to_execute == 3) {
            if (frame_to_execute == 2) {
                voltQueueSQL(getTrade_frame2, acct_id, "CMPT", start_trade_dts, end_trade_dts);
            }
            else {
                voltQueueSQL(getTrade_frame3, symbol, "CMPT", start_trade_dts, end_trade_dts);
            }
           
            VoltTable trades = voltExecuteSQL()[0];
           
            result = trade_lookup_ret_template_frame23.clone(256);
            for (int i = 0; i < trades.getRowCount(); i++) {
                VoltTableRow trade_row = trades.fetchRow(i);
               
                long trade_id = trade_row.getLong("T_ID");
                int is_cash = (int)trade_row.getLong("T_IS_CASH");
               
                voltQueueSQL(getSettlement, trade_id);
                voltQueueSQL(getTradeHistory, trade_id);
                if (is_cash == 1) {
                    voltQueueSQL(getCash, trade_id);
View Full Code Here

Examples of org.voltdb.VoltTableRow

       
        voltQueueSQL(getCustomer, cust_id);
        VoltTable cust = voltExecuteSQL()[0];
       
        assert cust.getRowCount() == 1;
        VoltTableRow customer = cust.fetchRow(0);
       
        voltQueueSQL(getAssets, cust_id);
        VoltTable assets = voltExecuteSQL()[0];
       
        /*
         * Here goes the code that should have gone to the SQL part, but could not because of H-Store limitations.
         * Probably not the most efficient way to do this. Especially sorting. Oh, well...
         */
        Map<Long, Double> cust_bal = new HashMap<Long, Double>();
        Map<Long, Double> cust_holds = new HashMap<Long, Double>();
       
        for (int i = 0; i < assets.getRowCount(); i++) {
            VoltTableRow asset  = assets.fetchRow(i);
           
            long acct_id = asset.getLong("CA_ID");
            double cash_bal = asset.getDouble("CA_BAL");
            double hold_asset = asset.getDouble(2);
           
            // might be null, if no holdings for the account
            if (assets.wasNull()) {
                hold_asset = 0;
            }
View Full Code Here

Examples of org.voltdb.VoltTableRow

            try {
                LOG.info("Processing " + num_tuples + " (sample=10) tuples for statistics on " + catalog_tbl.getName());
                boolean show_progress = (num_tuples > 25000);
                for (int i = 0; i < num_tuples; i += 10) {
                    if (i >= num_tuples) break;
                    VoltTableRow tuple = voltTable.fetchRow(i);
                    for (int j = 0; j < num_columns; j++) {
                        loader_query.params[j] = tuple.get(j, col_types[j]);
                    } // FOR
                    table_stats.process(stats_catalog_db, loader_xact);
                    if (show_progress && i > 0 && i % 10000 == 0) LOG.info(i + " tuples");
//                        if (i > 25000) break;
                } // FOR
View Full Code Here

Examples of org.voltdb.VoltTableRow

        voltQueueSQL(getAccount1, acct_id);
        VoltTable acc_info = voltExecuteSQL()[0];
       
        assert acc_info.getRowCount() == 1;
       
        VoltTableRow acc_info_row = acc_info.fetchRow(0);
        String acct_name = acc_info_row.getString("CA_NAME");
        long broker_id = acc_info_row.getLong("CA_B_ID");
        long cust_id = acc_info_row.getLong("CA_C_ID");
        int tax_status = (int)acc_info_row.getLong("CA_TAX_ST");
       
        voltQueueSQL(getCustomer, cust_id);
        voltQueueSQL(getBroker, broker_id);
        VoltTable[] cust_broker_info = voltExecuteSQL();
       
        assert cust_broker_info[0].getRowCount() == 1;
        assert cust_broker_info[1].getRowCount() == 1;
        VoltTableRow cust_row = cust_broker_info[0].fetchRow(0);
        VoltTableRow broker_row = cust_broker_info[1].fetchRow(0);
       
        String cust_f_name = cust_row.getString("C_F_NAME");
        String cust_l_name = cust_row.getString("C_L_NAME");
        int cust_tier = (int)cust_row.getLong("C_TIER");
        String tax_id = cust_row.getString("C_TAX_ID");
        String broker_name = broker_row.getString("B_NAME");
       
        // frame 2: check if the account executor has rights to do that
        if (!exec_l_name.equals(cust_l_name) || !exec_f_name.equals(cust_f_name) || !exec_tax_id.equals(tax_id)) {
            voltQueueSQL(getACL, acct_id, exec_f_name, exec_l_name, exec_tax_id);
            VoltTable acl = voltExecuteSQL()[0];
           
            assert acl.getRowCount() == 1;
           
            if (acl.fetchRow(0).get(0) == null) {
                throw new VoltAbortException("ACL for a Trade-Order transaction is NULL");
            }
        }
       
        // frame 3: estimating overall financial impact
        long co_id;
        String exch_id;
        String s_name;
       
        if (symbol.equals("")) {
            voltQueueSQL(getCompany, co_name);
            VoltTable comp = voltExecuteSQL()[0];
           
            assert comp.getRowCount() == 1;
            co_id = comp.fetchRow(0).getLong("CO_ID");
           
            voltQueueSQL(getSecurity1, co_id, issue);
            VoltTable sec = voltExecuteSQL()[0];
           
            assert sec.getRowCount() == 1;
            VoltTableRow sec_row = sec.fetchRow(0);
           
            exch_id = sec_row.getString("S_EX_ID");
            s_name = sec_row.getString("S_NAME");
            symbol = sec_row.getString("S_SYMB");
        }
        else {
            voltQueueSQL(getSecurity2, symbol);
            VoltTable sec = voltExecuteSQL()[0];
           
            assert sec.getRowCount() == 1;
            VoltTableRow sec_row = sec.fetchRow(0);
           
            co_id = sec_row.getLong("S_CO_ID");
            exch_id = sec_row.getString("S_EX_ID");
            s_name = sec_row.getString("S_NAME");
                   
            voltQueueSQL(getCompany2, co_id);
            VoltTable comp = voltExecuteSQL()[0];
           
            assert comp.getRowCount() == 1;
            co_name = comp.fetchRow(0).getString("CO_NAME");
        }
       
        voltQueueSQL(getLastTrade, symbol);
        voltQueueSQL(getTradeType, trade_type_id);
        voltQueueSQL(getHoldingSummmary, acct_id, symbol);
        VoltTable[] res = voltExecuteSQL();
       
        assert res[0].getRowCount() == 1;
        assert res[1].getRowCount() == 1;
       
        double market_price = res[0].fetchRow(0).getDouble("LT_PRICE");
       
        VoltTableRow tt_row = res[1].fetchRow(0);
        int type_is_market = (int)tt_row.getLong("TT_IS_MRKT");
        int type_is_sell = (int)tt_row.getLong("TT_IS_SELL");
       
        // for market orders price is determined by the last trade
        if (type_is_market == 1) {
            requested_price = market_price;
        }
       
        int hs_qty = 0;
        if (res[2].getRowCount() == 1) {
            hs_qty = (int)res[2].fetchRow(0).getLong("HS_QTY");
        }
       
        double buy_value = 0;
        double sell_value = 0;
        long needed_qty = trade_qty;
       
        // estimate impact on short and long positions
        if (type_is_sell == 1) {
            if (hs_qty > 0) {
                if (is_lifo == 1) {
                    voltQueueSQL(getHoldingDesc, acct_id, symbol);
                }
                else {
                    voltQueueSQL(getHoldingAsc, acct_id, symbol);
                }
               
                VoltTable hold_list = voltExecuteSQL()[0];
               
                for (int i = 0; i < hold_list.getRowCount() && needed_qty != 0; i++) {
                    VoltTableRow hold = hold_list.fetchRow(i);
                    int hold_qty = (int)hold.getLong("H_QTY");
                    double hold_price = hold.getDouble("H_PRICE");
                   
                    if (hold_qty > needed_qty) {
                        buy_value += needed_qty * hold_price;
                        sell_value += needed_qty * requested_price;
                        needed_qty = 0;
                    }
                    else {
                        buy_value += hold_qty * hold_price;
                        sell_value += hold_qty * requested_price;
                        needed_qty = needed_qty - hold_qty;
                    }
                }
            }
        }
        else { // buy transaction
            if (hs_qty < 0) {
                if (is_lifo == 1) {
                    voltQueueSQL(getHoldingDesc, acct_id, symbol);
                }
                else {
                    voltQueueSQL(getHoldingAsc, acct_id, symbol);
                }
               
                VoltTable hold_list = voltExecuteSQL()[0];
               
                for (int i = 0; i < hold_list.getRowCount() && needed_qty != 0; i++) {
                    VoltTableRow hold = hold_list.fetchRow(i);
                    int hold_qty = (int)hold.getLong("H_QTY");
                    double hold_price = hold.getDouble("H_PRICE");
                   
                    if (hold_qty + needed_qty < 0) {
                        sell_value += needed_qty * hold_price;
                        buy_value += needed_qty * requested_price;
                        needed_qty = 0;
View Full Code Here

Examples of org.voltdb.VoltTableRow

                    stats.preprocess(catalogContext.database);
                    m_tableStatsData.put(catalog_tbl, stats);
                }
                vt.resetRowPosition();
                while (vt.advanceRow()) {
                    VoltTableRow row = vt.getRow();
                    stats.process(catalogContext.database, row);
                } // WHILE
            } // SYNCH
        }
        return (cr);
View Full Code Here

Examples of org.voltdb.VoltTableRow

                    partition, vt.getRowCount()));
       
        if (debug.val)
            LOG.debug(String.format("<StoreData, change to ReduceInputTable> to Partition:%d>\n %s",partition,vt));
        while (vt.advanceRow()) {
            VoltTableRow row = vt.fetchRow(vt.getActiveRowIndex());
            assert(row != null);
            input.add(row);
        }
        vt.resetRowPosition();
       
View Full Code Here

Examples of org.voltdb.VoltTableRow

        assertEquals(vt0.getRowCount(), vt1.getRowCount());
        assertEquals(vt0.getColumnCount(), vt1.getColumnCount());
        assert(vt1.getColumnCount() > 0);
        int rows = 0;
        while (vt0.advanceRow() && vt1.advanceRow()) {
            VoltTableRow row0 = vt0.fetchRow(vt0.getActiveRowIndex());
            VoltTableRow row1 = vt1.fetchRow(vt1.getActiveRowIndex());
           
            for (int i = 0; i < vt0.getColumnCount(); i++) {
//                System.err.println(i + ": " + row1.get(i));
                assertEquals(row0.get(i), row1.get(i));
            } // FOR
            rows++;
        } // WHILE
        assert(rows > 0);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.