⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sampledata.java

📁 Oracle的J2EE Sample
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 /*
 * @author  : Elangovan
 * @version : 1.0
 *
 * Development Environment : Oracle9i JDeveloper
 * Name of the File        : SampleData.java
 *
 * Creation / Modification History
 *    Elangovan           28-Aug-2003        Created
 *
 */
package oracle.otnsamples.ibfbs.admin.helper;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.ArrayList;

import oracle.toplink.tools.schemaframework.SequenceDefinition;
import oracle.toplink.tools.schemaframework.TableDefinition;
import oracle.toplink.tools.schemaframework.OracleSequenceDefinition;

import oracle.otnsamples.ibfbs.toplink.Stockrate;
import oracle.otnsamples.ibfbs.toplink.Symbol;
import oracle.otnsamples.ibfbs.toplink.News;
import oracle.otnsamples.ibfbs.toplink.Exchange;

/**
 * This class holds the data ( tables, sequences and sample data) that is required
 * by FBS application. 
 * 
 * @see DataPopulator.java
 */
public class SampleData {
  
  public static SimpleDateFormat dtFormat = new SimpleDateFormat("dd-MMM-yyyy");
 
  /**
   * Returns Stock Exchange table definition.
   *   Table Name: Exchange
   *     ExchangeID   (Primary Key)
   *     ExchangeName 
   *     Location     
   * 
   * @return  Exchange table definition.
   */
  public static TableDefinition getExchangeTableDefn() {
  
    TableDefinition exchgTable = new TableDefinition();
    exchgTable.setName("EXCHANGE");
    exchgTable.addPrimaryKeyField("EXCHANGEID",Integer.class,10);
    exchgTable.addField("EXCHANGENAME",String.class,20);
    exchgTable.addField("LOCATION",String.class,200);
    return exchgTable;
  }


  /**
   * Returns Symbol table definition.
   * 
   * Table Name : Symbol
   *    Symbol (Primary Key)
   *    CompanyName
   *    CompanyProfile
   *    Traded
   *    ExchangeID References Exchange(ExchangeID)
   * 
   * @return  Symbol table definition
   */
  public static TableDefinition getSymbolTableDefn() {
  
    TableDefinition symbolTable = new TableDefinition();
    symbolTable.setName("SYMBOL");
    symbolTable.addPrimaryKeyField("SYMBOL",String.class,10);
    symbolTable.addField("COMPANYNAME",String.class,100);
    symbolTable.addField("COMPANYPROFILE",String.class,2000);
    symbolTable.addField("TRADED",String.class,1);
    symbolTable.addField("EXCHANGEID",Integer.class,10);
    symbolTable.addForeignKeyConstraint("exchange_symbol_fk","EXCHANGEID","EXCHANGEID","EXCHANGE");
    return symbolTable;
  }

  /**
   * Returns Stockrate table definition.
   * 
   * Table Name : StockRate
   *   Symbol References Symbol(Symbol)  Primary Key
   *   StockDate                         Primary Key
   *   LowPrice
   *   HighPrice
   * 
   * @return Stockrate table definition. 
   */
  public static TableDefinition getStockrateTableDefn() {
  
    TableDefinition srTable = new TableDefinition();
    srTable.setName("STOCKRATE");
    srTable.addPrimaryKeyField("SYMBOL",String.class,10);
    srTable.addPrimaryKeyField("STOCKDATE",Timestamp.class);
    srTable.addField("LOWPRICE",Double.class,15,2);
    srTable.addField("HIGHPRICE",Double.class,15,2);
    srTable.addForeignKeyConstraint("symbol_stockrate_fk","SYMBOL","SYMBOL","SYMBOL");
    return srTable;
  }
  
  /**
   * Returns News table definition.
   * 
   *  Table Name : News
   *     NewsID   PrimaryKey
   *     NewsDate
   *     Symbol   References Symbol(Symbol)
   *     NewsTitle
   *     NewsURL
   * 
   * @return News table definition. 
   */
  public static TableDefinition getNewsTableDefn() {
    TableDefinition newsTable = new TableDefinition();
    newsTable.setName("NEWS");
    newsTable.addPrimaryKeyField("NEWSID",BigDecimal.class,10);
    newsTable.addField("NEWSDATE",java.sql.Date.class);
    newsTable.addField("SYMBOL",String.class,10);
    newsTable.addField("NEWSTITLE",String.class,1000);
    newsTable.addField("NEWSURL",String.class,1000);
    newsTable.addForeignKeyConstraint("news_symbol_fk","SYMBOL","SYMBOL","SYMBOL");
    return newsTable;
  }
 
  /**
   * Returns Oracle sequence definition with the specified name, increment and
   * starts with 'startwith'.
   * 
   * @param seqName Sequence name
   * @param incr increment 
   * @param startwith starts with
   * @return  sequence definition
   */
  public static SequenceDefinition getOracleSequenceDefn(String seqName, int incr,
                                                         int startwith) {
                                                         
    OracleSequenceDefinition seq = new OracleSequenceDefinition(seqName);
    // Increment By
    seq.setIncrement(incr);
    // Start With
    seq.setStart(startwith);
    return seq;
  }
  
  /**
   * Constructs a new Symbol instance with the specified details.
   * 
   * @param sname Symbol name
   * @param cname Company name
   * @param cprofile company profile
   * @param traded wheather traded by this FBS
   * @param exchgId Exchange ID
   * @return Symbol instance
   */
  public static Symbol getSymbol(String sname,String cname, String cprofile, 
                                 String traded, int exchgId) {
    Symbol symbol = new Symbol();
    symbol.setSymbol(sname);
    symbol.setCompanyname(cname);
    symbol.setCompanyprofile(cprofile);
    symbol.setTraded(traded);
    symbol.setExchangeid(new Integer(exchgId));
    return symbol;
  }
  
  /**
   * Contructs a new instance of Stockrate with the specified details.
   * 
   * @param sname Stock Symbol name
   * @param sdate Stock rate on this date
   * @param lprice low price of the day
   * @param hprice high price of the day
   * @return  Stockrate instance
   */
  public static Stockrate getStockrate(String sname, java.util.Date sdate, 
                                           double lprice, double hprice) {
  
    Stockrate sr = new Stockrate();
    
    sr.setSymbol(sname);
    sr.setStockdate(new Timestamp(sdate.getTime()));
    sr.setLowprice(new Double(lprice));
    sr.setHighprice(new Double(hprice));
    
    return sr;
  }
  
  /**
   * Constructs a new News instance with the specified details.
   * 
   * @param newsdate News on this date.
   * @param sym Stock symbol
   * @param title News title
   * @param url HTTP url for the news item

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -