亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? brokermodeldbimpl.java

?? java寫的股票交易系統
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
package trader.db;

import java.util.*;
import java.sql.*;
import trader.*;


public class BrokerModelDbImpl implements BrokerModel {
  ArrayList changeListeners = new ArrayList(10);
  Connection theConnection;
  
  public BrokerModelDbImpl() throws Exception {
    this("localhost");
  }

  public BrokerModelDbImpl(String hostName) throws Exception {
    String  database = "sample";     // --action StockMarket
    String url;
    try {
      //** 1 Register a JDBC driver
      //**   The name of the pointbase driver class is
      //**   "com.pointbase.jdbc.jdbcUniversalDriver"
      Class.forName("com.pointbase.jdbc.jdbcUniversalDriver");
      //** 2 Construct the url string for JDBC access.
      //**   To be flexible use the local variables hostName
      //**   and database to construct the url string 
      url = "jdbc:pointbase://" + hostName +
        "/" + database;
      //** 3 Assign to theConnection attribute a connection
      //**   object obtained by invoking the getConnection
      //**   method on the DriverManager class
      theConnection = DriverManager.getConnection
        (url, "public", "public");
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
  }

  /** ---------------------------------------------------------
   * This is a helper method used by many methods.
   * It returns a Connection object. 
   * In a single threaded environment you can return a single
   * connection object stored in the attribute theConnection.
   * In a multi-threaded environment each thread will require
   * its own connection. A future subclass of this class can
   * override this method and obtain the connection object 
   * from a connection pool.
   */
  protected Connection obtainConnection() throws SQLException{
    // return the theConnection attribute
    return theConnection;
  }

  /** ---------------------------------------------------------
   * This is a helper method used by many methods
   * It returns true if the ssn (ie customer id) is found in 
   * the Customer table
   */
  protected boolean ssnExists(String ssn) {
    try {
      Connection con = obtainConnection();
      Statement stmt = con.createStatement();
      ResultSet result = stmt.executeQuery
        ("SELECT ssn FROM Customer WHERE ssn="+ "'" +ssn+ "'");
      return result.next();
    } catch (SQLException e) {
      System.err.println ("in ssnExists, query for " + ssn + " failed");
      e.printStackTrace();
      return false;
    }
  }
  //modified  by  ourteam 051228
  protected boolean symbolExists(String id, String symbol, int quantity) {
    try {
      Connection con = obtainConnection();
      Statement stmt = con.createStatement();
      ResultSet result = stmt.executeQuery
        ("SELECT SSN FROM Shares WHERE SSN='" + id.trim()
        + "' AND symbol='"+symbol.trim()+ "' AND quantity >=" + quantity);
      return result.next();
    } catch (SQLException e) {
      System.err.println ("in symbolExists, query for " + symbol + " failed");
      e.printStackTrace();
      return false;
    }
  }
//end
// Broker model state change listener registration methods
  /**-----------------------------------------------------------
   * Adds requester to the list of objects to be notified when an
   * object(Customer, Portfolio or Stock) in the broker model 
   * alters state   
   */
  public void addChangeListener(BrokerView bv)
    throws BrokerException {
    //** 1 add bv to changeListeners using the add method   
    changeListeners.add(bv);
  }
  

  /**-----------------------------------------------------------
   * This method notifies all registered BrokerView listeners
   * that a customer object has changed.
   */
  private void fireModelChangeEvent(Customer cust) {
    BrokerView v;
    for (int i=0; i<changeListeners.size(); i++) {
      try {    
        System.out.println("Model:fireModelChangeEvent loop " +i);
        v = (BrokerView) changeListeners.get(i);
        v.handleCustomerChange(cust);
      } catch(Exception e) {
        System.out.println(e.toString());
      }
    }
  }

// Iteration 1 Customer segment broker model methods
// Customer segment state change methods
  /**----------------------------------------------------------
   * Adds the Customer to the broker model 
   */ 
  public void addCustomer(Customer cust) 
    throws BrokerException {
    try {
      String id = null;
      String name = null;
      String addr = null;
      Connection con;
      Statement stmt;
      int rowCount;
      String request;
      //** 1 Assign id with id from cust object
      id = cust.getId();
      //** 2 Assign name with name from cust object
      name = cust.getName();
      //** 3 Assign addr with addr from cust object
      addr = cust.getAddr(); 
      //Q? what is the purpose of the following 3 code lines?
      if (ssnExists(id)) {
        throw new BrokerException("Duplicate id");
      }
      //** 4 Assign con by invoking the obtainConnection()
      //**   for example see similar step in ssnExists method
      con = obtainConnection();
      //** 5 Assign stmt by invoking createStatement on con
      //**   for example see similar step in ssnExists method
      stmt = con.createStatement();
      // The following creates the required INSERT SQL string
      request = 
        "INSERT INTO Customer (ssn, cust_name, address) VALUES ("
        + "'" + id + "'" + ","
        + "'" + name + "'" + ","
        + "'" + addr + "'" + ")";
      //** 6 Assign rowCount with the value returned by invoking 
      //**   executeUpdate(request) method on the stmt object
      rowCount = stmt.executeUpdate(request);
      //** 7 Invoke the fireModelChangeEvent with cust as param.
      //**   Q? why is this step necessary?
      fireModelChangeEvent(cust);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BrokerException("BrokerDbImpl.addCustomer\n" +e);
    }
  }

  /**-------------------------------------------------------------
   * deletes the customer from the broker model
   */
  public void deleteCustomer(Customer cust)
    throws BrokerException{
    try {
      String id = null;
      Connection con;
      Statement stmt;
      int rowCount;
      String request;
      //** 1 Assign id with id from cust object
      id = cust.getId();
      //Q? What is the purpose of the following 4 code lines?
      con = obtainConnection();
      stmt = con.createStatement();
      if (!ssnExists(id)) {
        throw new BrokerException("Record for " + id +
          " not found");
      }
      //** 2 Assign con by invoking the obtainConnection()
      //**   for example see similar step in ssnExists method
      //con = obtainConnection();
      //** 3 Assign stmt by invoking createStatement on con
      //**   for example see similar step in ssnExists method
      //stmt = con.createStatement();
      // The following creates the required DELETE SQL string
      // to delete rows from the Shares table
      request = 
        "DELETE FROM Shares WHERE ssn=" + "'" + id + "'";
      //** 4 Assign rowCount with the value returned by invoking 
      //**   executeUpdate(request) method on the stmt object
      rowCount = stmt.executeUpdate(request);

      // The following creates the required DELETE SQL string
      // to delete the customer from the Customers table
      request = 
        "DELETE FROM Customer WHERE ssn=" + "'" + id + "'";
      //** 5 Assign rowCount with the value returned by invoking 
      //**   executeUpdate(request) method on the stmt object
      rowCount = stmt.executeUpdate(request);
      //** 6 Using the setName method set the string 
      //**   "- customer deleted -" to the name field of the
      //**   cust object . 
      cust.setName("- customer deleted -");
      //** 7 Invoke the fireModelChangeEvent with cust as param.
      fireModelChangeEvent(cust);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BrokerException
        ("BrokerDbImpl.deleteCustomer\n" +e);
    }
  }
  
  //modified  by  ourteam 051228
  //begin
  public void addPortfolio(Portfolio port) 
    throws BrokerException {
    try {
      String id = null;
      String name = null;
      float  price=0;
      int quantity=0;
      Share[] shares = null;
      String  symbol=null;
      //int quantity=0;
      Connection con;
      Statement stmt;
      int rowCount;
      String request=null;
      //System.out.println("database: addPortfolio begin");
      //** 1 Assign id with id from cust object
      id = port.getCustomer().getId();
      //** 2 Assign name with name from cust object
      name = port.getCustomer().getName();
      //** 3 Assign addr with addr from cust object
      System.out.println("id="+id+"name="+name);
      shares = port.getShares();
      System.out.println("shares.length="+shares.length);
      symbol=shares[0].getStock().getSymbol();
      price=shares[0].getStock().getPrice();
      quantity=shares[0].getQuantity();
      //symbol=port.getShare().getStock().getSymbol();
      //quantity = port.getShare().getQuantity();
      //Q? what is the purpose of the following 3 code lines?
      System.out.println("get from shares[0]: symbol ="+symbol+",price="+price);
      con = obtainConnection();
      stmt = con.createStatement();
      if (!ssnExists(id)) {
      	throw  new  BrokerException("you  can't  invest");
      	/*request = 
        "INSERT INTO Shares (ssn,symbol, quantity) VALUES ("
        + "'" + symbol + "'" + ","
        + "'" + price + "" + ","
        + "" + quantity + "" + ")";*/
        //throw new BrokerException("Duplicate id");
      //** 4 Assign con by invoking the obtainConnection()
      //**   for example see similar step in ssnExists method
      //con = obtainConnection();
      //** 5 Assign stmt by invoking createStatement on con
      //**   for example see similar step in ssnExists method
      //stmt = con.createStatement();
      // The following creates the required INSERT SQL string
      //else
      //request = 
       //"INSERT INTO Customer (ssn, cust_name, shares) VALUES ("
      //  + "'" + id + "'" + ","
      //  + "'" + name + "'" + ","
      //  + "'" + shares.getQuantity() + "'" +shares.getStock().getSymbol()+"'"+ ")";
    }
     else if(!symbolExists(id,symbol,quantity)){ 
     /*    request = 
        "INSERT INTO Shares (ssn,symbol, quantity) VALUES ("
        + "'" + symbol + "',"
        + price + ","
        + quantity + ")";*/
        
        request = 
        "INSERT INTO Shares (ssn,symbol, quantity) VALUES ("
        + "'" + id + "',"
        + "'" + symbol + "',"
        + quantity + ")";
      }
     else{
      	 /*
      	 request= "UPDATE Shares SET QUANTITY=QUANTITY+" + quantity
       	 			+ " WHERE SSN='" + id + "' AND SYMBOL='" + symbol + "'";
       	 */
       	 
       	 request= "UPDATE Shares SET QUANTITY=QUANTITY+" + quantity
       	 			+ " WHERE SSN='" + id + "' AND SYMBOL='" + symbol + "'";
      	}
      System.out.println("SQL before:"+request);	
    //request = "";
      //** 6 Assign rowCount with the value returned by invoking 
      //**   executeUpdate(request) method on the stmt object
      rowCount = stmt.executeUpdate(request);
      System.out.println("SQL after:"+request);
      //** 7 Invoke the fireModelChangeEvent with cust as param.
      //**   Q? why is this step necessary?
      fireModelChangeEvent(port.getCustomer());
    } catch (Exception e) {
      e.printStackTrace();
      throw new BrokerException("BrokerDbImpl.addPortfolio\n" +e);
    }
  }

  /**-------------------------------------------------------------
   * deletes the customer from the broker model
   */
  public void deletePortfolio(Portfolio port)
    throws BrokerException{
    try {
      String id = null;
      String symbol=null;
      String  name=null;
      float  price=0;
      Share[] shares = null;
      int  quantity=0;
      id = port.getCustomer().getId();
      name = port.getCustomer().getName();
      shares = port.getShares();
      symbol=shares[0].getStock().getSymbol();
      price=shares[0].getStock().getPrice();
      quantity=shares[0].getQuantity();
      Connection con;
      Statement stmt;
      int rowCount;
      String request=null;
      //** 1 Assign id with id from cust object
      //id = port.getCustomer().getId();
      //symbol = port.getShare().getStock().getSymbol();
      //quantity = port.getShare().getQuantity();
      //first id, symbol exist?
      //second symbol's number > quantity?
      //third sell symbol
      
      con = obtainConnection();
      stmt = con.createStatement();
      //Q? What is the purpose of the following 4 code lines?
      if (!symbolExists(id, symbol, quantity)) {
        throw new BrokerException("Record for " + id + "'s " + symbol +
          " not found");
      } else {
      //modified by ourteam 051228
      //begin
       	request= "UPDATE Shares SET QUANTITY=QUANTITY-" + quantity
       	 			+ " WHERE SSN='" + id + "' AND SYMBOL='" + symbol + "'";
      	rowCount = stmt.executeUpdate(request);
      }
      //end
      //request = 
        //"DELETE FROM Shares WHERE ssn=" + "'" + id + "'";
      //** 4 Assign rowCount with the value returned by invoking 
      //**   executeUpdate(request) method on the stmt object
      //rowCount = stmt.executeUpdate(request);

      // The following creates the required DELETE SQL string
      // to delete the customer from the Customers table
      //request = 
	       // "DELETE FROM Customer WHERE ssn=" + "'" + id + "'";
      //** 5 Assign rowCount with the value returned by invoking 
      //**   executeUpdate(request) method on the stmt object
      //** 6 Using the setName method set the string 
      //**   "- customer deleted -" to the name field of the
      //**   cust object . 
      //** 7 Invoke the fireModelChangeEvent with cust as param.
      //fireModelChangeEvent(port.getCustomer());
    } catch (Exception e) {
      e.printStackTrace();
      throw new BrokerException
        ("BrokerDbImpl.deletePortfolio\n" +e);
    }
  }
  
  //end


  /**-------------------------------------------------------------
   * Updates the customer in the broker model
   */
  public void updateCustomer(Customer cust)
    throws BrokerException {
    try {
      String id = null;
      String name = null;
      String addr = null;
      Connection con;
      Statement stmt;
      String request;
      int rowCount;
      //** 1 Assign id with id from cust object
      id = cust.getId();
      //** 2 Assign name with name from cust object
      name = cust.getName();
      //** 3 Assign addr with addr from cust object
      addr = cust.getAddr(); 
      //** Q? What is the purpose of the following 4 code lines
      if (!ssnExists(id)) {
        throw new BrokerException("Record for " + id +
          " not found");

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一二三在线| 精品一区二区三区在线播放 | 91亚洲精华国产精华精华液| 亚洲黄一区二区三区| 午夜国产精品影院在线观看| 国产成人在线视频免费播放| 欧美三级中文字幕在线观看| 日本一区二区视频在线观看| 日本在线播放一区二区三区| 一本一道波多野结衣一区二区| 精品日韩在线一区| 日日欢夜夜爽一区| 99久久99久久免费精品蜜臀| 久久免费的精品国产v∧| 天堂va蜜桃一区二区三区漫画版| www.欧美日韩| 欧美精彩视频一区二区三区| 老鸭窝一区二区久久精品| 欧美视频一区二区在线观看| 成人欧美一区二区三区视频网页 | 国产成人av电影在线| 欧美一区二区三区免费在线看| 尤物av一区二区| 99久久精品国产导航| 国产精品人成在线观看免费 | 精品国产乱码久久久久久影片| 亚洲一二三级电影| 色哟哟在线观看一区二区三区| 久久精品一区四区| 国产一区二区电影| 久久久久国产精品人| 久久99九九99精品| 久久综合久久99| 国产麻豆视频一区| 久久久三级国产网站| 黑人精品欧美一区二区蜜桃| 日韩无一区二区| 国内久久婷婷综合| 2020日本不卡一区二区视频| 国产一区福利在线| 国产精品三级电影| thepron国产精品| 成人欧美一区二区三区1314| 91热门视频在线观看| 亚洲欧美经典视频| 欧美视频第二页| 日本强好片久久久久久aaa| 日韩一级成人av| 国产一区二区不卡| 亚洲欧洲www| 欧美三级在线播放| 久久精品国产澳门| 国产亚洲一区字幕| 北条麻妃国产九九精品视频| 亚洲青青青在线视频| 欧美色网一区二区| 久久激情综合网| 久久婷婷成人综合色| 成人高清视频免费观看| 亚洲制服丝袜av| 日韩一区二区影院| 成人免费精品视频| 一区二区三区在线视频观看58| 欧美日韩日日骚| 国产成人午夜电影网| 一区二区在线观看免费视频播放| 欧美日韩精品一区二区三区| 麻豆成人久久精品二区三区红 | 亚洲国产一区二区在线播放| 欧美日韩一区高清| 蜜桃传媒麻豆第一区在线观看| 欧美国产日韩精品免费观看| 色综合久久99| 精彩视频一区二区三区| 亚洲女同一区二区| 欧美一级欧美三级在线观看| 国产91精品精华液一区二区三区| 性做久久久久久免费观看| 久久久久久一二三区| 欧美偷拍一区二区| 成人动漫在线一区| 日本大胆欧美人术艺术动态| 国产精品久久国产精麻豆99网站| 91精品国产一区二区人妖| www.久久精品| 黄色日韩网站视频| 亚洲国产精品久久艾草纯爱| 国产人久久人人人人爽| 欧美高清www午色夜在线视频| 成人国产精品免费网站| 国产在线乱码一区二区三区| 亚洲成年人网站在线观看| 国产精品伦理在线| 久久这里只有精品6| 7777精品伊人久久久大香线蕉完整版 | 91精品国产乱码久久蜜臀| 成人免费毛片嘿嘿连载视频| 久久99久久久久久久久久久| 亚洲国产欧美在线| 亚洲人成精品久久久久久| 亚洲国产成人一区二区三区| 宅男在线国产精品| 欧美日韩免费电影| 欧美亚洲国产怡红院影院| 不卡av在线网| 国产成人综合在线| 国产美女视频一区| 久久99精品国产麻豆婷婷洗澡| 亚洲成av人片在www色猫咪| 中文字幕欧美一区| 中文天堂在线一区| 亚洲国产岛国毛片在线| 日本一区二区动态图| 久久久久久综合| 久久久久99精品国产片| 精品国产亚洲在线| 亚洲精品在线观看网站| 精品国产乱码久久久久久免费| 日韩一区二区三区电影| 日韩欧美一级二级三级| 日韩一级完整毛片| 久久综合中文字幕| 国产日韩精品一区| 国产精品乱人伦| 亚洲欧洲www| 亚洲一区二区三区美女| 亚洲韩国精品一区| 免费黄网站欧美| 国产一区二区免费看| 大胆亚洲人体视频| 日本乱人伦一区| 欧美日韩免费视频| 日韩亚洲欧美中文三级| 2020日本不卡一区二区视频| 中文欧美字幕免费| 一区二区三区欧美激情| 日韩成人精品在线| 国产综合久久久久久久久久久久| 高清在线成人网| 色88888久久久久久影院按摩| 欧美日韩国产首页在线观看| 欧美日韩国产美| 久久综合给合久久狠狠狠97色69| 国产午夜久久久久| 一区二区三区四区乱视频| 天堂久久久久va久久久久| 国产一区 二区| 日本福利一区二区| 精品嫩草影院久久| 中文字幕一区二区三区在线不卡 | 97精品国产97久久久久久久久久久久 | 国产午夜一区二区三区| 亚洲美女偷拍久久| 久草精品在线观看| 在线视频亚洲一区| 2020日本不卡一区二区视频| 亚洲欧美精品午睡沙发| 激情五月婷婷综合网| 91免费在线看| 精品国产乱码久久久久久免费| 亚洲同性gay激情无套| 蜜臀av性久久久久av蜜臀妖精| 成人av综合在线| 日韩欧美国产一区在线观看| 亚洲欧洲性图库| 极品少妇xxxx偷拍精品少妇| 色婷婷久久久综合中文字幕| 精品成人免费观看| 亚洲va在线va天堂| 国产盗摄女厕一区二区三区| 欧美一区二区网站| 亚洲精品欧美综合四区| 国产麻豆日韩欧美久久| 欧美一激情一区二区三区| 一区二区三区在线视频免费观看| 国产精品一二三在| 日韩欧美一二三| 亚洲丰满少妇videoshd| 色综合色综合色综合 | 国产成人欧美日韩在线电影| 欧美一区二区三区白人| 亚洲一区二区三区自拍| 成人国产亚洲欧美成人综合网| 日韩免费视频一区二区| 天天色综合成人网| 欧美性猛交xxxxxx富婆| 亚洲欧美日韩国产综合在线| 国产91精品免费| 国产目拍亚洲精品99久久精品| 蜜桃精品视频在线| 91精品欧美福利在线观看| 亚洲午夜激情网站| 色偷偷成人一区二区三区91 | 99久久777色| 国产精品久久777777| 高潮精品一区videoshd| 久久久久久影视| 国产酒店精品激情| 国产欧美一区二区三区在线看蜜臀 | 国产人久久人人人人爽|