home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JREFRNCE.Z / OrderTrackDataModule.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  4.5 KB  |  125 lines

  1. /*
  2.  * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
  3.  * 
  4.  * This SOURCE CODE FILE, which has been provided by Borland as part
  5.  * of a Borland product for use ONLY by licensed users of the product,
  6.  * includes CONFIDENTIAL and PROPRIETARY information of Borland.  
  7.  *
  8.  * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
  9.  * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
  10.  * THE PRODUCT.
  11.  *
  12.  * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
  13.  * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
  14.  * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
  15.  * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
  16.  * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
  17.  * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
  18.  * CODE FILE.
  19.  */
  20.  
  21. //Title:        Cliffhanger Order Status Tracker
  22. //Version:
  23. //Copyright:    Copyright (c) 1997 Borland International, Inc.
  24. //Author:       Application Methods, Inc.
  25. //Description:  Cliffhanger Adventure Gear Order Status Tracking Applet
  26.  
  27. package borland.reference.tracker;
  28.  
  29. import java.awt.*;
  30. import java.awt.event.*;
  31. import borland.jbcl.layout.*;
  32. import borland.jbcl.control.*;
  33. import borland.sql.dataset.*;
  34. import borland.jbcl.dataset.*;
  35. import java.util.*;
  36.  
  37. /**
  38.  * OrderTrackDataModule is the DataModule class for the Applet.  It contains
  39.  * database connectivity parameters, query parameters, and instances of the
  40.  * QueryDataSets and ParameterRow used by the Applet.
  41.  */
  42. public class OrderTrackDataModule implements DataModule{
  43.   private static OrderTrackDataModule myDM;
  44.  
  45.   Database cliffhangerDB = new Database();
  46.   QueryDataSet qdsPOrders = new QueryDataSet();
  47.   ParameterRow pRow = new ParameterRow();
  48.   LabelControl amountLabel = new LabelControl();
  49.   FieldControl amountField = new FieldControl();
  50.  
  51.   Column amountColumn = new Column();
  52.   Column orderDateColumn = new Column();
  53.   Column shipDateColumn = new Column();
  54.   Column statusColumn = new Column();
  55.   ResourceBundle res = Res.getBundle("borland.reference.tracker.Res");
  56.  
  57.   public OrderTrackDataModule() {
  58.     try {
  59.       jbInit();
  60.     }
  61.     catch (Exception e) {
  62.       e.printStackTrace();
  63.     }
  64.   }
  65.  
  66.   private void jbInit() throws Exception{
  67.  
  68.     // Initialize database connection
  69.     cliffhangerDB.setConnection(new borland.sql.dataset.ConnectionDescriptor("jdbc:odbc:Cliffhanger", "SYSDBA", null, true, "sun.jdbc.odbc.JdbcOdbcDriver"));
  70.  
  71.     // Add a parameter on the field "ORDERTRACKNUM" to the row to take advantage of
  72.     // of the parameterized query
  73.     pRow.addColumn("ORDERTRACKNUM", borland.jbcl.util.Variant.STRING);
  74.  
  75.     amountColumn.setColumnName("AMTPAID");
  76.     amountColumn.setCurrency(true);
  77.     amountColumn.setDataType(borland.jbcl.util.Variant.DOUBLE);
  78.  
  79.     orderDateColumn.setColumnName("ORDERDATE");
  80.     orderDateColumn.setDataType(borland.jbcl.util.Variant.DATE);
  81.     orderDateColumn.setDisplayMask(res.getString("MM_dd_yyyy"));
  82.  
  83.     shipDateColumn.setColumnName("SHIPDATE");
  84.     shipDateColumn.setDataType(borland.jbcl.util.Variant.DATE);
  85.     shipDateColumn.setDisplayMask(res.getString("MM_dd_yyyy"));
  86.  
  87.     statusColumn.setColumnName("STATUS");
  88.     statusColumn.setDataType(borland.jbcl.util.Variant.STRING);
  89.  
  90.     // Associate the columns with the dataset
  91.     qdsPOrders.setColumns(new Column[] {amountColumn,
  92.                                         orderDateColumn,
  93.                                         shipDateColumn,
  94.                                         statusColumn});
  95.  
  96.     /**  Define a parameterized query for use by the Applet.  The parameter "ORDERTRACKNUM"
  97.      * will be used to match the user-input to the "ordertracknum" column in the
  98.      * database.
  99.      */
  100.     qdsPOrders.setQuery(new borland.sql.dataset.QueryDescriptor(cliffhangerDB, "select * from orders where ordertracknum = :ORDERTRACKNUM", pRow, true, Load.ALL));
  101.     qdsPOrders.setReadOnly(true);
  102.     qdsPOrders.setEditable(false);
  103.   }
  104.  
  105.   static public OrderTrackDataModule getDataModule() {
  106.     if (myDM == null)
  107.       myDM = new OrderTrackDataModule();
  108.     return myDM;
  109.   }
  110.  
  111.   public void dbConnect() throws DataSetException {
  112.     // This method explicitly opens a connection to the database.
  113.     cliffhangerDB.openConnection();
  114.   }
  115.  
  116.   public borland.sql.dataset.QueryDataSet getOrdersDataSet() {
  117.     return qdsPOrders;
  118.   }
  119.  
  120.   public borland.jbcl.dataset.ParameterRow getOrderNumParameterRow() {
  121.     return pRow;
  122.   }
  123.  
  124. }
  125.