亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
欧美日韩精品一区二区天天拍小说| 国产欧美视频在线观看| 日韩欧美成人午夜| 亚洲精品第一国产综合野| 国内成+人亚洲+欧美+综合在线| 色就色 综合激情| 2023国产精品| 欧美aaa在线| 欧美日韩免费观看一区三区| 日本一区二区三区在线不卡| 久久精品国产99国产| 亚洲免费av高清| 99精品欧美一区二区三区小说| 欧美男人的天堂一二区| 91麻豆国产香蕉久久精品| 日韩欧美国产综合在线一区二区三区 | 国内外精品视频| 欧美日韩亚洲综合一区 | 成人久久18免费网站麻豆| 精品国产精品网麻豆系列| 香蕉成人啪国产精品视频综合网| 99re成人精品视频| 国产拍揄自揄精品视频麻豆| 国产一区二区三区免费在线观看| 69成人精品免费视频| 香蕉乱码成人久久天堂爱免费| 91免费观看在线| 亚洲视频 欧洲视频| 94色蜜桃网一区二区三区| 国产精品水嫩水嫩| 成人av网站免费| 18涩涩午夜精品.www| 91蜜桃视频在线| 亚洲视频在线一区| 91麻豆成人久久精品二区三区| 国产精品天干天干在观线| 不卡的电影网站| 亚洲欧美色一区| 欧美日韩精品欧美日韩精品一 | 亚洲特黄一级片| 91黄色免费观看| 亚洲1区2区3区4区| 精品久久国产97色综合| 国产老女人精品毛片久久| 欧美激情综合在线| 91网站黄www| 亚洲成人免费影院| 日韩三级.com| 国产成人精品综合在线观看 | 亚洲欧洲av另类| 欧美亚一区二区| 另类小说图片综合网| 国产色一区二区| 日本精品免费观看高清观看| 丝袜a∨在线一区二区三区不卡| 3d成人动漫网站| 大胆亚洲人体视频| 亚洲午夜激情av| 久久久国产综合精品女国产盗摄| 99精品视频在线免费观看| 日韩va欧美va亚洲va久久| 久久久久久亚洲综合| 色综合av在线| 国产美女在线观看一区| 伊人开心综合网| 欧美电影免费观看完整版| 99久久久久免费精品国产| 日韩成人精品视频| 亚洲欧美另类小说视频| 日韩精品资源二区在线| 成人国产电影网| 奇米综合一区二区三区精品视频| 中文字幕日韩av资源站| 欧美一区二区三区小说| 97aⅴ精品视频一二三区| 久久99热这里只有精品| 亚洲精品老司机| 日本一区二区三区四区在线视频| 在线播放视频一区| 91在线国产观看| 国产精品自拍av| 日韩影视精彩在线| 亚洲久本草在线中文字幕| 久久一区二区三区四区| 欧美日韩国产小视频在线观看| 高清不卡在线观看av| 韩国女主播一区二区三区| 亚洲风情在线资源站| 亚洲婷婷综合久久一本伊一区| 日韩欧美在线影院| 欧美老年两性高潮| 色综合欧美在线视频区| 大桥未久av一区二区三区中文| 久久国产精品色| 麻豆高清免费国产一区| 日韩avvvv在线播放| 亚洲韩国精品一区| 一区二区三区中文字幕精品精品 | 欧美精品一区二区三区高清aⅴ| 91免费观看在线| 99久久国产综合精品女不卡| 风间由美一区二区av101| 久久99国产精品免费网站| 日韩av中文在线观看| 日韩制服丝袜先锋影音| 三级成人在线视频| 日韩中文字幕av电影| 天堂一区二区在线免费观看| 五月天中文字幕一区二区| 亚洲精品中文字幕乱码三区 | 免费高清成人在线| 日韩和欧美一区二区| 日韩黄色免费网站| 麻豆精品视频在线| 精品一区精品二区高清| 精品一区二区国语对白| 国产在线精品免费av| 国产一区久久久| 成人免费视频视频在线观看免费 | 一区二区不卡在线播放| 亚洲成人在线观看视频| 日韩黄色小视频| 久久99久久99精品免视看婷婷 | 麻豆一区二区三| 国产一区高清在线| 99精品久久99久久久久| 欧美亚洲国产怡红院影院| 欧美精品在线一区二区三区| 777欧美精品| 久久久久久久综合色一本| 欧美国产精品劲爆| 一区二区三区日韩| 日精品一区二区| 国产中文字幕精品| jlzzjlzz亚洲女人18| 欧美三级日韩在线| 欧美成人精品二区三区99精品| 国产亚洲成年网址在线观看| 亚洲色图都市小说| 日本不卡的三区四区五区| 国产99久久久国产精品潘金网站| 99精品国产91久久久久久| 欧美另类高清zo欧美| 久久久精品日韩欧美| 亚洲一区二区av在线| 韩国视频一区二区| 欧美性猛交xxxxxxxx| 久久久精品天堂| 亚洲国产精品人人做人人爽| 极品瑜伽女神91| 色久优优欧美色久优优| 精品国产免费视频| 亚洲一区国产视频| 国产成人一区二区精品非洲| 在线亚洲人成电影网站色www| 日韩欧美卡一卡二| 亚洲欧美电影一区二区| 国产尤物一区二区在线| 在线视频综合导航| 国产欧美日韩不卡免费| 午夜精品影院在线观看| 91在线观看高清| 久久亚洲春色中文字幕久久久| 亚洲激情综合网| 成人美女视频在线看| 欧美成人性福生活免费看| 亚洲欧美视频在线观看| 国产一区二区三区四区五区美女| 在线日韩av片| 亚洲视频在线一区观看| 国产夫妻精品视频| 日韩欧美一区二区视频| 亚洲五月六月丁香激情| 99国产精品久久久久久久久久久 | 欧美人妖巨大在线| 亚洲九九爱视频| 波多野结衣中文一区| 欧美精品一区视频| 麻豆极品一区二区三区| 在线播放中文字幕一区| 亚洲夂夂婷婷色拍ww47| 99re成人在线| 国产精品全国免费观看高清| 国产一二精品视频| 2021中文字幕一区亚洲| 美日韩黄色大片| 91麻豆精品国产| 婷婷国产v国产偷v亚洲高清| 欧美艳星brazzers| 亚洲一区二区三区不卡国产欧美| av爱爱亚洲一区| 国产精品丝袜在线| 99精品欧美一区二区三区小说 | 国产美女精品一区二区三区| 日韩免费观看2025年上映的电影| 婷婷六月综合亚洲| 日韩一区二区三免费高清| 青青国产91久久久久久| 欧美成人一级视频| 国产精品一区免费视频|