home *** CD-ROM | disk | FTP | other *** search
/ Enter 1999 September / ENTER9_2.bin / prog_8 / jbuilder3 / TRIAL / INTRCLNT / DATA.Z / PerformanceTests.java < prev    next >
Encoding:
Java Source  |  1999-01-18  |  46.4 KB  |  1,150 lines

  1. // Copyright InterBase Software Corporation, 1998.
  2. // Written by com.inprise.interbase.interclient.r&d.PaulOstler :-)
  3.  
  4. /**   
  5.  * Portable performance test suite for InterClient or any other JDBC driver.
  6.  * <p>
  7.  * <b>IMPORTANT STEPS BEFORE RUNNING THIS TEST</b>
  8.  * <ol>
  9.  * <li> 
  10.  * Create an empty test database file to be used for performance tests.
  11.  * Metadata is created automatically by the test program,
  12.  * but a test database must be created manually before running tests.
  13.  * <p>                       
  14.  * For InterBase, manually create test.gdb in the directory of your choice as follows:
  15.  * <ul>      
  16.  * <li> isql
  17.  * <li> create database "test.gdb" [user "sysdba" password "masterkey"];
  18.  * <li> quit;  
  19.  * </ul>
  20.  * The brackets ([]) indicate an optional user/password, only required
  21.  * if system environment variables ISC_USER and ISC_PASSWORD are not set.
  22.  * <p>
  23.  * Some database products, like Oracle, manage their own filespace
  24.  * so skip this step for such products.
  25.  * <li>    Tailor configuration variables.
  26.  *         This is done programmatically by setting the public configuration
  27.  *         variables of this class programmatically in an application program
  28.  *         (with a <code>main()</code>) external to this
  29.  *         <code>PerformanceTests</code> library.
  30.  *         Do <i>not</i> edit the default values in the
  31.  *         <code>PerformanceTest</code> source.
  32.  *         Rather, edit a copy of class <code>interbase.interclient.tests.ExampleTests</code>.
  33.  *         or copy the <code>ExampleTests</code> program and modify its source.
  34.  *         You may want to change the package name (interbase.interclient.tests)
  35.  *         on the first line of your copy of the <code>ExampleTests</code>
  36.  *         source file to the name
  37.  *         of your choice, making sure
  38.  *         the package name matches the new directory location of your test
  39.  *         program relative to your class path,
  40.  *         then compile the new program source.
  41.  *         <p>
  42.  *         Configure variables for the
  43.  *         URLs, drivers, and test control switches in <code>ExampleTests</code> .
  44.  *         <p>
  45.  *         You must manually configure ODBC and BDE
  46.  *         data-source names for test.gdb using the ODBC or BDE
  47.  *         configuration utilities.  For consistency, use
  48.  *         ODBC and BDE alias names as suggested by the defaults
  49.  *         of the various configuration variables in <code>ExampleTests</code>.
  50.  *         The ODBC configuration utiltity
  51.  *         can usually be found in the NT control panel.
  52.  *         The BDE Administrator can be found in the DataGateway program group.
  53.  * <li>    Be sure to start InterServer, DataGateway, InterBase, Sybase Open Server,
  54.  *         dbANYWHERE, or any other servers tested before running <code>ExampleTests</code>.
  55.  *         Also, make sure DataGateway.zip, InterClient.jar,
  56.  *         and any other driver to test are in a library class path for your project.
  57.  * <li>    Discard the performance results of the first test run in order
  58.  *         to factor out the overhead in initial class loading, and
  59.  *         the initial database page allocation for an originally
  60.  *         empty test.gdb.  In other words, run the test twice
  61.  *         so that Java classes are pre-loaded, and take
  62.  *         the results of the second test only.
  63.  * <li>    Look for results and/or errors in the specified output file
  64.  *         as configured.
  65.  * </ol>
  66.  **/
  67. public class PerformanceTests
  68. {
  69.   // *******************************************
  70.   // *** Default public configurables.
  71.   // *** Do not modify the default values in this file.
  72.   // *** Modify publics programmatically via an external class
  73.   // *** such as ExampleTests rather than hardwiring
  74.   // *** values in this class.
  75.   // *******************************************
  76.  
  77.   /**
  78.    * Output file to write the performance test results.
  79.    * This is where you'll want to look after running a test.
  80.    * <p>
  81.    * The default value is null, which means output will be written to System.out.
  82.    **/
  83.   public static String outputFileName = null;
  84.  
  85.   /**
  86.    * An array of database engines, usernames, passwords, URLs, and drivers you wish to test.
  87.    * <p>
  88.    * Each element in the array consists of a tuple
  89.    * <code>{ engineName, username, password, URL, driverClassName }</code>.
  90.    * The engine name is needed
  91.    * to construct dbms-dependent SQL.  Valid engine names are
  92.    * "interbase", "oracle", etc...
  93.    * Some drivers, such as DataGateway, can be used against
  94.    * different engines (known as category 3 drivers).
  95.    * <p>
  96.    * Here are some example client/server tuples that could be tested
  97.    * The remote hostname may be set to localhost to test client/server in loopback mode.
  98.    * <pre>
  99.    * PerformanceTests.driversToTest = new String[][] {
  100.    * // *** Client/server URLs ***
  101.    * // JDBC-ODBC bridge used remotely (uses native dbms client api and dbms net protocol)
  102.    *  { "interbase",
  103.    *    "sysdba",
  104.    *    "masterkey",
  105.    *    "jdbc:odbc:clientServerTest",
  106.    *    "sun.jdbc.odbc.JdbcOdbcDriver" }
  107.    * // InterClient (uses custom client api and remote protocol (RP))
  108.    * ,{ "interbase",
  109.    *    "sysdba",
  110.    *    "masterkey",
  111.    *    "jdbc:interbase://hostname/d:/databases/test.gdb",
  112.    *    "interbase.interclient.Driver" }
  113.    * // Datagateway Broker  (uses custom client api and remote protocol (RP))
  114.    * ,{ "interbase",
  115.    *    "sysdba",
  116.    *    "masterkey",
  117.    *    "jdbc:BorlandBroker://hostname/localTest",
  118.    *    "borland.jdbc.Broker.RemoteDriver" }
  119.    * // Datagateway bridge used remotely (uses native dbms client api and RP)
  120.    * ,{ "interbase",
  121.    *    "sysdba",
  122.    *    "masterkey",
  123.    *    "jdbc:BorlandBridge:clientServerTest",
  124.    *    "borland.jdbc.Bridge.LocalDriver" }
  125.    * // Sybase jConnect (uses custom client api, but uses TDS remote protocol)
  126.    * ,{ "sqlanywhere",
  127.    *    "dba",
  128.    *    "sql",
  129.    *    "jdbc:sybase:Tds:hostname:4444/d:\\sqlany50\\sademo.db",
  130.    *    "com.sybase.jdbc.SybDriver" }
  131.    * // Symantec dbAnywhere
  132.    * ,{ "sqlanywhere",
  133.    *    "dba",
  134.    *    "sql",
  135.    *    "jdbc:dbaw://hostname:8889/Sybase_SQLANY/Sademo/Sademo",
  136.    *    "symantec.itools.db.jdbc.Driver" }
  137.    * // Oracle Thin Driver (uses custom client api, but uses Oracle remote protocol?)
  138.    * ,{ "oracle",
  139.    *    "user",
  140.    *    "password",
  141.    *    "jdbc:oracle:thin:@hostname:1521:ORCL",
  142.    *    "oracle.jdbc.driver.OracleDriver" }
  143.    * // Solid Driver uses Solid protocol
  144.    * ,{ "solid",
  145.    *    "sysdba",
  146.    *    "masterkey",
  147.    *    "jdbc:solid://hostname:1313/sysdba/masterkey",
  148.    *    "solid.jdbc.SolidDriver" }
  149.    * //
  150.    * // *** Local URLs follow (not client/server) ***
  151.    * // Datagateway bridge used locally
  152.    * ,{ "interbase",
  153.    *    "sysdba",
  154.    *    "masterkey",
  155.    *    "jdbc:BorlandBridge:localTest",
  156.    *    "borland.jdbc.Bridge.LocalDriver" }
  157.    * // JDBC-ODBC bridge used locally
  158.    * ,{ "interbase",
  159.    *    "sysdba",
  160.    *    "masterkey",
  161.    *    "jdbc:odbc:localTest"
  162.    *    "sun.jdbc.odbc.JdbcOdbcDriver" }
  163.    * };
  164.    * </pre>
  165.    **/
  166.   public static String[][] driversToTest = null;
  167.  
  168.   // *************************************************
  169.   // *** Configurable test control switches follow ***
  170.   // *** (ie. what to test and what not to test).  ***
  171.   // *** Modify values thru an external application rather than ***
  172.   // *** modifying the default values as set here. ***
  173.   // *************************************************
  174.  
  175.   // *** Toggles for performance suites ***
  176.   public static boolean testMetaData = false;   // exhaustive database metadata extraction
  177.   public static boolean testStrings = false;    // various CHAR(n) tests
  178.   public static boolean testBLObs = false;      // various BLOb tests
  179.   public static boolean testNumbers = false;    // various numeric data
  180.   public static boolean testDates = false;      // Dates, Times, and Timestamps
  181.   public static boolean testProcedures = false; // Stored procedures
  182.  
  183.   public static boolean test1ByteBlobs = false;      // uses dataSize/1 rows
  184.   public static boolean test10ByteBlobs = false;     // uses dataSize/10 rows
  185.   public static boolean test100ByteBlobs = false;    // uses dataSize/100 rows
  186.   public static boolean test1000ByteBlobs = false;   // uses dataSize/1000 rows
  187.   public static boolean test10000ByteBlobs = false;  // uses dataSize/10000 rows
  188.   public static boolean test100000ByteBlobs = false; // uses dataSize/100000 rows
  189.  
  190.   public static boolean test1CharStrings = false;  // most time consuming
  191.   public static boolean test10CharStrings = false;
  192.   public static boolean test100CharStrings = false;
  193.   public static boolean test1000CharStrings = false;
  194.   public static boolean test10000CharStrings = false; // least time consuming
  195.  
  196.   /**
  197.    * Size of bulk data loads for testing.
  198.    * <p>
  199.    * <code>testDataSize</code> indicates how many bytes are inserted or selected for each test.
  200.    * For example, if the <code>testDataSize</code> = 100,000, then the 1-byte blob test will
  201.    * insert 100,00 rows of 1-byte blobs, but the 100,000-byte blob test will
  202.    * insert only a single row.  Decreasing <code>dataSize</code> will decrease the time
  203.    * required to run the performance tests.
  204.    * <p>
  205.    * Default value is 1,000.
  206.    * It is recommended to always make dataSize divisible by 1,000.
  207.    **/
  208.   public static int testDataSize = 1000; // make it divisible by 1,000
  209.  
  210.   /**
  211.    * See InterClient API reference for <code>Connection.setAutoCommit()</code>.
  212.    * <p>
  213.    * Default is false.
  214.    * @see interbase.interclient.Connection#setAutoCommit
  215.    **/
  216.   public static boolean enableAutoCommit = false;
  217.  
  218.   /**
  219.    * Direct the driver manager log stream to <code>ouputFileName</code>.
  220.    * See JavaSoft API reference for <code>DriverManager.setLogStream()</code>.
  221.    * <p>
  222.    * Default is false.
  223.    * @see java.sql.DriverManager#setLogStream
  224.    **/
  225.   public static boolean enableDriverManagerLogStream = false;
  226.  
  227.   /**
  228.    * Character set name, see InterClient API reference for class
  229.    * <code>interbase.interclient.ConnectionProperties</code> for mappings
  230.    * to InterBase character sets.
  231.    * <p>
  232.    * Default is null which means to use the driver defaults.
  233.    * @see interbase.interclient.ConnectionProperties
  234.    **/
  235.   public static String characterSet = null;
  236.  
  237.   /**
  238.    * This is the character to use to construct test strings.
  239.    * For example, if test100chars is enabled, then a test string
  240.    * of 100 characters will be created using this character.
  241.    * <p>
  242.    * Default is 'X'.
  243.    * @see #characterSet
  244.    **/
  245.   public static char character = 'X';
  246.   
  247.   // **********************************************
  248.   // *** End of Configurables *********************
  249.   // **********************************************
  250.  
  251.   // *** specifies the number of bytes per row in NUMBER_TABLE ***
  252.   // *** set below with table declaration for number tests ***
  253.   private static int numberBytesPerRecord__;
  254.  
  255.   // *** String data to be inserted and selected from test database ***
  256.   private static String s1char__ = null;
  257.   private static String s10chars__ = null;
  258.   private static String s100chars__ = null;
  259.   private static String s1000chars__ = null;
  260.   private static String s10000chars__ = null;
  261.  
  262.   // *** Blob data to be inserted and selected from test database ***
  263.   private static byte[] b1byte__ = null;
  264.   private static byte[] b10bytes__ = null;
  265.   private static byte[] b100bytes__ = null;
  266.   private static byte[] b1000bytes__ = null;
  267.   private static byte[] b10000bytes__ = null;
  268.   private static byte[] b100000bytes__ = null;
  269.  
  270.   // *** Performance metric variables ***
  271.   private static long startTime__, endTime__, elapsedTime__;
  272.  
  273.   // *** The engine currently being tested, this is used to determine
  274.   // *** the variant of SQL to use.
  275.   // *** Engine names are passed in as part of the urlsToTest array.
  276.   private static String engine__;
  277.  
  278.   // *** JDBC global object declarations ***
  279.   private static java.sql.Driver d__ = null;
  280.   private static java.sql.Connection c__ = null;
  281.   private static java.sql.Statement s__ = null;
  282.   private static java.sql.PreparedStatement ps__ = null;
  283.   private static java.sql.ResultSet rs__ = null;
  284.   private static java.util.Properties properties__ = null;
  285.   private static String user__ = null;
  286.   private static String password__ = null;
  287.   private static String url__ = null;
  288.  
  289.   // *** Print stream for writing results ***
  290.   private static java.io.PrintStream printStream__ = null;
  291.   
  292.   /**
  293.    * Run the performance tests under the configuration as set
  294.    * by the public configuration variables.
  295.    * Results are written to <code>outputFileFile</code>.
  296.    **/
  297.   synchronized static public void run ()
  298.   {
  299.     // this forces jdbc objects to be closed before
  300.     // this java application exits.
  301.     System.runFinalizersOnExit (true);
  302.  
  303.     if (outputFileName == null) {
  304.       printStream__ = System.out; // System.out is the default
  305.     }
  306.     else {
  307.       try {
  308.         printStream__ =
  309.           new java.io.PrintStream (new java.io.FileOutputStream (outputFileName),
  310.                                    true);  // auto-flush
  311.       }
  312.       catch (java.io.IOException e) {
  313.         System.out.println  ("Couldn't open print stream to " + outputFileName +
  314.                              "Aborting tests...");
  315.         System.exit (1);
  316.       }
  317.     }
  318.  
  319.     showPerformanceTuningVariables ();
  320.  
  321.     try {
  322.       int i;
  323.       
  324.       populateStaticData ();
  325.  
  326.       if (enableDriverManagerLogStream)
  327.         java.sql.DriverManager.setLogStream (printStream__);
  328.  
  329.       // *** Load all available drivers from your class path ***
  330.       for (i=0; i<driversToTest.length; i++) {
  331.         try {
  332.           Class.forName (driversToTest[i][4]);
  333.         }
  334.         catch (ClassNotFoundException e) {
  335.       printStream__.println ("Driver " +
  336.                                driversToTest[i][4] +
  337.                                " not found in classpath.");
  338.         }
  339.       }
  340.  
  341.       printStream__.println ("******************************************************************************");
  342.       printStream__.println ("*** Beginning performance tests ***");
  343.       printStream__.println ("*** The number of rows and bytes selected should match the number inserted ***");
  344.       printStream__.println ("******************************************************************************");
  345.  
  346.       // *** Test all urls specified in driversToTest ***
  347.       for (i=0; i<driversToTest.length; i++) {
  348.         engine__ = driversToTest[i][0];
  349.         user__ = driversToTest[i][1];
  350.         password__ = driversToTest[i][2];
  351.         url__ = driversToTest[i][3];
  352.         printStream__.println ();
  353.         printStream__.println ("*** Testing " + url__ + " ***");
  354.         test ();
  355.         printStream__.println ("*** Finished testing " + url__ + " ***");
  356.       }
  357.  
  358.       printStream__.println ();
  359.       printStream__.println ("*** End Of Tests ***");
  360.       // If you're using the JBuilder debugger,
  361.       // check for errors under JBuilder | View | Execution Log.
  362.     }
  363.     catch (java.sql.SQLException e) {
  364.       showException (e);
  365.     }
  366.     finally {
  367.       printStream__.close ();
  368.     }
  369.   }
  370.  
  371.   private static void showPerformanceTuningVariables ()
  372.   {
  373.     printStream__.println ("*** Running interbase.interclient.PerformanceTests.run() ***");
  374.     printStream__.println ("driversToTest:");
  375.     for (int i=0; i<driversToTest.length; i++) {
  376.       printStream__.print (driversToTest[i][0]);
  377.       printStream__.print (", ");
  378.       printStream__.print (driversToTest[i][1]);
  379.       printStream__.print (", ");
  380.       printStream__.print (driversToTest[i][2]);
  381.       printStream__.print (", ");
  382.       printStream__.print (driversToTest[i][3]);
  383.       printStream__.print (", ");
  384.       printStream__.print (driversToTest[i][4]);
  385.       printStream__.println ();
  386.     }
  387.  
  388.     printStream__.println ("testMetaData: " + testMetaData);
  389.     printStream__.println ("testStrings: " + testStrings);
  390.     printStream__.println ("testBLObs: " + testBLObs);
  391.     printStream__.println ("testNumbers: " + testNumbers);
  392.     printStream__.println ("testDates: " + testDates);
  393.     printStream__.println ("testProcedures: " + testProcedures);
  394.  
  395.     printStream__.println ("test1ByteBlobs: " + test1ByteBlobs);
  396.     printStream__.println ("test10ByteBlobs: " + test10ByteBlobs);
  397.     printStream__.println ("test100ByteBlobs: " + test100ByteBlobs);
  398.     printStream__.println ("test1000ByteBlobs: " + test1000ByteBlobs);
  399.     printStream__.println ("test10000ByteBlobs: " + test10000ByteBlobs);
  400.     printStream__.println ("test100000ByteBlobs: " + test100000ByteBlobs);
  401.  
  402.     printStream__.println ("test1CharStrings: " + test1CharStrings);
  403.     printStream__.println ("test10CharStrings: " + test10CharStrings);
  404.     printStream__.println ("test100CharStrings: " + test100CharStrings);
  405.     printStream__.println ("test1000CharStrings: " + test1000CharStrings);
  406.     printStream__.println ("test10000CharStrings: " + test10000CharStrings);
  407.  
  408.     printStream__.println ("testDataSize: " + testDataSize);
  409.  
  410.     printStream__.println ("enableAutoCommit: " + enableAutoCommit);
  411.     printStream__.println ("enableDriverManagerLogStream: " + enableDriverManagerLogStream);
  412.  
  413.     printStream__.println ("characterSet: " + characterSet);
  414.     printStream__.println ("character: " + character);
  415.   }
  416.  
  417.   private static void populateStaticData ()
  418.   {
  419.     int i;
  420.     
  421.     // *** Populate java strings for inserting into database CHAR fields ***
  422.     // !!! had to lower this to please JBuilder, up to 10,000 later.
  423.     StringBuffer tempBuffer = new StringBuffer (10000); //!!!1,000 when debugging
  424.     for (i=0; i<10000; i++) // !!!10,000 or  1,000 when debugging
  425.       tempBuffer.append (character);
  426.     // !!! comment out next two when debugging
  427.     s10000chars__ = tempBuffer.toString ();
  428.     tempBuffer.setLength (1000);
  429.     s1000chars__ = tempBuffer.toString ();
  430.     tempBuffer.setLength (100);
  431.     s100chars__ = tempBuffer.toString ();
  432.     tempBuffer.setLength (10);
  433.     s10chars__ = tempBuffer.toString ();
  434.     tempBuffer.setLength (1);
  435.     s1char__ = tempBuffer.toString ();
  436.  
  437.     // !!! comment out next two when debugging
  438.     b100000bytes__ = new byte [100000];
  439.     b10000bytes__ = new byte [10000];
  440.     b1000bytes__ = new byte [1000];
  441.     b100bytes__ = new byte [100];
  442.     b10bytes__ = new byte [10];
  443.     b1byte__ = new byte [1];
  444.     for (i=0; i<100000; i++) // !!! up to 100,000, 1,000 when debugging
  445.       b100000bytes__[i] = 56; // !!! up to 100,000, 1,000 when debugging
  446.     // !!!comment out next two when debugging
  447.     System.arraycopy (b100000bytes__, 0, b10000bytes__, 0, 10000);
  448.     System.arraycopy (b10000bytes__, 0, b1000bytes__, 0, 1000);
  449.     System.arraycopy (b1000bytes__, 0, b100bytes__, 0, 100);
  450.     System.arraycopy (b100bytes__, 0, b10bytes__, 0, 10);
  451.     System.arraycopy (b10bytes__, 0, b1byte__, 0, 1);
  452.   }
  453.  
  454.   // url__ and engine__ must be previously set.
  455.   private static void test () throws java.sql.SQLException
  456.   {
  457.     try {
  458.       // *** Get a connection to the url ***
  459.       d__ = java.sql.DriverManager.getDriver (url__);
  460.       printStream__.println ("*** using driver version: " + d__.getMajorVersion() + "." + d__.getMinorVersion() + " ***");
  461.       
  462.       properties__ = new java.util.Properties ();
  463.       properties__.put ("user", user__);
  464.       properties__.put ("password", password__);
  465.       if (characterSet != null)
  466.         properties__.put ("charset", characterSet); // need to resource "charSet"
  467.       c__ = d__.connect (url__, properties__);
  468.  
  469.       // *** Create the metadata needed ***
  470.       c__.setAutoCommit (false);  // Run DDL with autocommit off
  471.       dropTestTables ();
  472.       createTestTables ();
  473.       c__.commit (); // Commit the DDL
  474.       c__.setAutoCommit (enableAutoCommit);
  475.  
  476.       if (testMetaData)
  477.         testMetaData ();
  478.  
  479.       if (testStrings) {
  480.         printStream__.println ("** Beginning string tests **");
  481.     testStringInsertPerformance ();
  482.     testStringSelectPerformance ();
  483.       }
  484.       if (testBLObs) {
  485.         printStream__.println ("** Beginning BLOb tests **");
  486.     testBLObInsertPerformance ();
  487.     testBLObSelectPerformance ();
  488.       }
  489.       if (testNumbers) {
  490.         printStream__.println ("** Beginning number tests **");
  491.     testNumberInsertPerformance ();
  492.     testNumberSelectPerformance ();
  493.       }
  494.       if (testDates) {
  495.         printStream__.println ("** Beginning date tests **");
  496.     testDateInsertPerformance ();
  497.     testDateSelectPerformance ();
  498.       }
  499.       if (testProcedures) {
  500.         printStream__.println ("** Beginning procedure tests **");
  501.     testProcedureInsertPerformance ();
  502.     testProcedureSelectPerformance ();
  503.       }
  504.     }
  505.     catch (java.sql.SQLException e) {
  506.       showException (e);
  507.       throw e;
  508.     }
  509.     finally {
  510.       // The jdbc/odbc bridge needs the commit before close can be called
  511.       if ((c__ != null) && !c__.isClosed()) {
  512.         c__.commit();
  513.         c__.close ();
  514.       }
  515.       c__ = null;
  516.     }
  517.   }
  518.  
  519.   private static void showException (java.sql.SQLException e)
  520.   {
  521.     java.sql.SQLException next = e;
  522.     while (next != null) {
  523.       printStream__.println ("SQL State: " + next.getSQLState () + "");
  524.       printStream__.println ("Error Code: " + next.getErrorCode () + "");
  525.       printStream__.println ("Message: " + next.getMessage () + "");
  526.       next = next.getNextException ();
  527.     }
  528.   }
  529.  
  530.   private static void dropTestTables () throws java.sql.SQLException
  531.   {
  532.     s__ = c__.createStatement();
  533.     try { s__.executeUpdate ("drop table CHAR1_TABLE"); } catch (java.sql.SQLException e) {}
  534.     try { s__.executeUpdate ("drop table CHAR10_TABLE"); } catch (java.sql.SQLException e) {}
  535.     try { s__.executeUpdate ("drop table CHAR100_TABLE"); } catch (java.sql.SQLException e) {}
  536.     try { s__.executeUpdate ("drop table CHAR1000_TABLE"); } catch (java.sql.SQLException e) {}
  537.     try { s__.executeUpdate ("drop table CHAR10000_TABLE"); } catch (java.sql.SQLException e) {}
  538.     try { s__.executeUpdate ("drop table BLOB1_TABLE"); } catch (java.sql.SQLException e) {}
  539.     try { s__.executeUpdate ("drop table BLOB10_TABLE"); } catch (java.sql.SQLException e) {}
  540.     try { s__.executeUpdate ("drop table BLOB100_TABLE"); } catch (java.sql.SQLException e) {}
  541.     try { s__.executeUpdate ("drop table BLOB1000_TABLE"); } catch (java.sql.SQLException e) {}
  542.     try { s__.executeUpdate ("drop table BLOB10000_TABLE"); } catch (java.sql.SQLException e) {}
  543.     try { s__.executeUpdate ("drop table BLOB100000_TABLE"); } catch (java.sql.SQLException e) {}
  544.     try { s__.executeUpdate ("drop table NUMBER_TABLE"); } catch (java.sql.SQLException e) {}
  545.     try { s__.executeUpdate ("drop table DATE_TABLE"); } catch (java.sql.SQLException e) {}
  546.     try { s__.executeUpdate ("drop procedure INSERT_PROC"); } catch (java.sql.SQLException e) {}
  547.     try { s__.executeUpdate ("drop procedure SELECT_PROC"); } catch (java.sql.SQLException e) {}
  548.     try { s__.executeUpdate ("drop procedure EXECUTE_PROC"); } catch (java.sql.SQLException e) {}
  549.     try { s__.executeUpdate ("drop table PROC_CHAR100_TABLE"); } catch (java.sql.SQLException e) {}
  550.     s__.close();
  551.     c__.commit (); // Some drivers don't force commit on DDL
  552.   }
  553.  
  554.   private static void createTestTables () throws java.sql.SQLException
  555.   {
  556.     s__ = c__.createStatement();
  557.     // Could provide SQL in a resource bundle for each engine__
  558.     String charset = (engine__.equals ("interbase") && (characterSet != null))
  559.                      ? (" character set " +
  560.                         interbase.interclient.CharacterEncodings.getInterBaseCharacterSetName (characterSet))
  561.                      : "";
  562.     if (testStrings) {
  563.       if (test1CharStrings)
  564.     s__.executeUpdate ("create table CHAR1_TABLE (S char(1)" + charset + ")");
  565.       if (test10CharStrings)
  566.     s__.executeUpdate ("create table CHAR10_TABLE (S char(10)" + charset + ")");
  567.       if (test100CharStrings)
  568.     s__.executeUpdate ("create table CHAR100_TABLE (S char(100)" + charset + ")");
  569.       if (test1000CharStrings)
  570.     s__.executeUpdate ("create table CHAR1000_TABLE (S char(1000)" + charset + ")");
  571.       if (test10000CharStrings)
  572.     s__.executeUpdate ("create table CHAR10000_TABLE (S char(10000)" + charset + ")");
  573.     }
  574.     if (testBLObs) {
  575.       String longVarBinary;
  576.       if (engine__.equals ("solid"))
  577.     longVarBinary = "long varbinary";
  578.       else if (engine__.equals ("sqlanywhere"))
  579.         longVarBinary = "Image";
  580.       else
  581.     longVarBinary = "blob";
  582.  
  583.       if (test1ByteBlobs)
  584.     s__.executeUpdate ("create table BLOB1_TABLE (B " + longVarBinary + ")");
  585.       if (test10ByteBlobs)
  586.     s__.executeUpdate ("create table BLOB10_TABLE (B " + longVarBinary + ")");
  587.       if (test100ByteBlobs)
  588.     s__.executeUpdate ("create table BLOB100_TABLE (B " + longVarBinary + ")");
  589.       if (test1000ByteBlobs)
  590.     s__.executeUpdate ("create table BLOB1000_TABLE (B " + longVarBinary + ")");
  591.       if (test10000ByteBlobs)
  592.     s__.executeUpdate ("create table BLOB10000_TABLE (B " + longVarBinary + ")");
  593.       if (test100000ByteBlobs)
  594.     s__.executeUpdate ("create table BLOB100000_TABLE (B " + longVarBinary + ")");
  595.     }
  596.     if (testNumbers) {
  597.       numberBytesPerRecord__ = 32; // number of bytes per row in NUMBER_TABLE
  598.       s__.executeUpdate ("create table NUMBER_TABLE (aSmallint        SMALLINT," +
  599.              "                           anInteger        INTEGER," +
  600.              "                           aDouble          DOUBLE PRECISION," +
  601.              "                           aFloat           FLOAT," +
  602.              "                           aNumericSmallint NUMERIC(4,2)," + // SMALLINT
  603.              "                           aNumericInteger  NUMERIC(9,3)," + // INTEGER
  604.              "                           aNumericDouble   NUMERIC(10,4))");// DOUBLE
  605.     }
  606.     if (testDates) {
  607.       s__.executeUpdate ("create table DATE_TABLE (aDate      DATE," +
  608.              "                         aTime      DATE," +
  609.              "                         aTimestamp DATE)");
  610.     }
  611.     if (testProcedures) {
  612.       s__.executeUpdate ("create table PROC_CHAR100_TABLE (S char(100)" + charset + ")");
  613.       s__.executeUpdate ("create procedure INSERT_PROC" +
  614.                          " as begin insert into PROC_CHAR100_TABLE (S) values ('" +
  615.                          s100chars__ + "'); end");
  616.       s__.executeUpdate ("create procedure SELECT_PROC" +
  617.                          " returns (RETURN_VALUE char(100)" + charset + ")" +
  618.                          " as begin for select S from PROC_CHAR100_TABLE into :RETURN_VALUE" +
  619.                          " do suspend; end");
  620.       s__.executeUpdate ("create procedure EXECUTE_PROC" +
  621.                          " returns (RETURN_VALUE char(100)" + charset + ")" +
  622.                          " as begin RETURN_VALUE = USER; end");
  623.     }
  624.     s__.close();
  625.     c__.commit (); // Some drivers don't force commit on DDL
  626.   }
  627.  
  628.   private static void testMetaData () throws java.sql.SQLException
  629.   {
  630.     java.util.Vector tableVector = new java.util.Vector ();
  631.     java.util.Enumeration tableEnum;
  632.     String table;
  633.  
  634.     startTime__ = System.currentTimeMillis ();
  635.     java.sql.DatabaseMetaData dbmd = c__.getMetaData ();
  636.  
  637.     // First collect a vector of table names
  638.     java.sql.ResultSet tempRS =
  639.       dbmd.getTables ("", "", "%", new String[] {"TABLE", "SYSTEM TABLE", "VIEW"});
  640.     while (tempRS.next ()) {
  641.       tableVector.addElement (tempRS.getString ("TABLE_NAME"));
  642.     }
  643.  
  644.     // Tables
  645.     printStream__.println ("*** Tables ***");
  646.     showResultSet (dbmd.getTables ("", "", "%", new String[] {"TABLE", "SYSTEM TABLE", "VIEW"}));
  647.  
  648.     // Table Privileges
  649.     printStream__.println ("*** Table Privileges ***");
  650.     showResultSet (dbmd.getTablePrivileges ("", "", "%"));
  651.  
  652.     // Columns
  653.     printStream__.println ("*** Columns ***");
  654.     showResultSet (dbmd.getColumns ("", "", "%", "%"));
  655.  
  656.     // Column Privileges
  657.     tableEnum = tableVector.elements ();
  658.     while (tableEnum.hasMoreElements ()) {
  659.       table = (String) tableEnum.nextElement ();
  660.       printStream__.println ("*** Column Privileges for table " + table + " ***");
  661.       showResultSet (dbmd.getColumnPrivileges ("", "", table, "%"));
  662.     }
  663.  
  664.     // Best Row Identifier
  665.     int scope = java.sql.DatabaseMetaData.bestRowSession;
  666.     boolean nullable = false;
  667.     tableEnum = tableVector.elements ();
  668.     while (tableEnum.hasMoreElements ()) {
  669.       table = (String) tableEnum.nextElement ();
  670.       printStream__.println ("*** Best Row Identifier for table " + table + " ***");
  671.       showResultSet (dbmd.getBestRowIdentifier ("", "", table, scope, nullable));
  672.     }
  673.  
  674.     // Version Columns
  675.     tableEnum = tableVector.elements ();
  676.     while (tableEnum.hasMoreElements ()) {
  677.       table = (String) tableEnum.nextElement ();
  678.       printStream__.println ("*** Version Columns for table " + table + " ***");
  679.       showResultSet (dbmd.getVersionColumns ("", "", table));
  680.     }
  681.  
  682.     // Primary Keys
  683.     tableEnum = tableVector.elements ();
  684.     while (tableEnum.hasMoreElements ()) {
  685.       table = (String) tableEnum.nextElement ();
  686.       printStream__.println ("*** Primary Keys for table " + table + " ***");
  687.       showResultSet (dbmd.getPrimaryKeys ("", "", table));
  688.     }
  689.  
  690.     // Imported Keys
  691.     tableEnum = tableVector.elements ();
  692.     while (tableEnum.hasMoreElements ()) {
  693.       table = (String) tableEnum.nextElement ();
  694.       printStream__.println ("*** Imported Keys for table " + table + " ***");
  695.       showResultSet (dbmd.getImportedKeys ("", "", table));
  696.     }
  697.  
  698.     // Exported Keys
  699.     tableEnum = tableVector.elements ();
  700.     while (tableEnum.hasMoreElements ()) {
  701.       table = (String) tableEnum.nextElement ();
  702.       printStream__.println ("*** Exported Keys for table " + table + " ***");
  703.       showResultSet (dbmd.getExportedKeys ("", "", table));
  704.     }
  705.  
  706.     // Cross Reference
  707.     java.util.Enumeration primaryTableEnum = tableVector.elements ();
  708.     java.util.Enumeration foreignTableEnum = tableVector.elements ();
  709.     while (primaryTableEnum.hasMoreElements ()) {
  710.       String primaryTable = (String) primaryTableEnum.nextElement ();
  711.       while (foreignTableEnum.hasMoreElements ()) {
  712.         String foreignTable = (String) foreignTableEnum.nextElement ();
  713.         printStream__.println ("*** Cross Reference for primary table " + primaryTable + " and foreign table " + foreignTable + " ***");
  714.         showResultSet (dbmd.getCrossReference ("", "", primaryTable, "", "", foreignTable));
  715.       }
  716.     }
  717.  
  718.     // Procedures
  719.     printStream__.println ("*** Procedures ***");
  720.     showResultSet (dbmd.getProcedures ("", "", "%"));
  721.  
  722.     // Procedure Columns
  723.     printStream__.println ("*** Procedure Columns ***");
  724.     showResultSet (dbmd.getProcedureColumns ("", "", "%", "%"));
  725.  
  726.     // Table Types
  727.     printStream__.println ("*** Table Types ***");
  728.     showResultSet (dbmd.getTableTypes ());
  729.  
  730.     // Type Info
  731.     printStream__.println ("*** Type Info ***");
  732.     showResultSet (dbmd.getTypeInfo ());
  733.  
  734.     // Index Info
  735.     boolean unique = false;
  736.     boolean approximate = true;
  737.     tableEnum = tableVector.elements ();
  738.     while (tableEnum.hasMoreElements ()) {
  739.       table = (String) tableEnum.nextElement ();
  740.       printStream__.println ("*** Index Info for table " + table + " ***");
  741.       showResultSet (dbmd.getIndexInfo ("", "", table, unique, approximate));
  742.     }
  743.  
  744.     endTime__ = System.currentTimeMillis ();
  745.     elapsedTime__ = endTime__ - startTime__;
  746.     printStream__.println ("database metadata extracted in: " + elapsedTime__ + " milliseconds");
  747.   }
  748.  
  749.   private static void showResultSet (java.sql.ResultSet resultSet) throws java.sql.SQLException
  750.   {
  751.     java.sql.ResultSetMetaData metaData = resultSet.getMetaData();
  752.     int[] displaySizes = new int[metaData.getColumnCount ()];
  753.     for (int col=1; col <= metaData.getColumnCount (); col++) {
  754.       displaySizes[col-1] = Math.max (metaData.getColumnName (col).length(),
  755.                                       metaData.getColumnDisplaySize (col)) + 1;
  756.     }
  757.  
  758.     for (int col=1; col <= metaData.getColumnCount (); col++) {
  759.       writeColumnData (metaData.getColumnName (col), col, displaySizes);
  760.     }
  761.     printStream__.println ();
  762.     for (int col=1; col <= metaData.getColumnCount (); col++) {
  763.       writeColumnData (metaData.getTableName (col), col, displaySizes);
  764.     }
  765.     printStream__.println ();
  766.     for (int col=1; col <= metaData.getColumnCount (); col++) {
  767.       writeColumnData (metaData.getColumnLabel (col), col, displaySizes);
  768.     }
  769.     printStream__.println ();
  770.     for (int col=1; col <= metaData.getColumnCount (); col++) {
  771.       writeColumnData (metaData.getColumnTypeName (col), col, displaySizes);
  772.     }
  773.     printStream__.println ();
  774.     for (int col=1; col <= metaData.getColumnCount (); col++) {
  775.       writeColumnData (String.valueOf (metaData.isWritable (col)), col, displaySizes);
  776.     }
  777.     printStream__.println ();
  778.     while (resultSet.next ()) {
  779.       for (int col=1; col <= metaData.getColumnCount (); col++) {
  780.     writeColumnData (resultSet.getString (col), col, displaySizes);
  781.       }
  782.       printStream__.println ();
  783.     }
  784.     printStream__.println ();
  785.     resultSet.close ();
  786.   }
  787.  
  788.   private static void writeColumnData (String string,
  789.                                        int column,
  790.                                        int[] displaySizes)
  791.   {
  792.      printStream__.print (string);
  793.  
  794.      int strLength;
  795.      if (string == null)
  796.        strLength = 4;
  797.      else
  798.        strLength = string.length ();
  799.  
  800.      for (int i=strLength; i < displaySizes[column-1]; i++)
  801.        printStream__.print (' ');
  802.   }
  803.  
  804.   private static void testStringInsertPerformance () throws java.sql.SQLException
  805.   {
  806.     if (test1CharStrings)
  807.       try { insertStrings (s1char__); } catch (java.sql.SQLException e) { showException (e); }
  808.  
  809.     if (test10CharStrings)
  810.       try { insertStrings (s10chars__); } catch (java.sql.SQLException e) { showException (e); }
  811.  
  812.     if (test100CharStrings)
  813.       try { insertStrings (s100chars__); } catch (java.sql.SQLException e) { showException (e); }
  814.  
  815.     if (test1000CharStrings)
  816.       try { insertStrings (s1000chars__); } catch (java.sql.SQLException e) { showException (e); }
  817.  
  818.     if (test10000CharStrings)
  819.       try { insertStrings (s10000chars__); } catch (java.sql.SQLException e) { showException (e); }
  820.   }
  821.  
  822.   private static void insertStrings (String str) throws java.sql.SQLException
  823.   {
  824.     int numRows = Math.max (1, testDataSize/str.length ());
  825.     int numChars = 0;
  826.  
  827.     startTime__ = System.currentTimeMillis ();
  828.     ps__ = c__.prepareStatement ("insert into CHAR" + str.length() + "_TABLE (S) values (?)"); // Network
  829.     for (int row = 0; row < numRows; row++) {
  830.       numChars += str.length();
  831.       ps__.setString (1, str);
  832.       ps__.executeUpdate (); // Network
  833.     }
  834.     ps__.close ();
  835.     endTime__ = System.currentTimeMillis ();
  836.     elapsedTime__ = endTime__ - startTime__;
  837.     printStream__.println ("inserted " + numRows + " rows of " + str.length() + " char strings in: " +
  838.                  elapsedTime__ + " milliseconds (" + numChars + " chars inserted)");
  839.   }
  840.  
  841.   private static void testStringSelectPerformance () throws java.sql.SQLException
  842.   {
  843.     if (test1CharStrings)
  844.       try { selectStrings (s1char__.length()); } catch (java.sql.SQLException e) { showException (e); }
  845.  
  846.     if (test10CharStrings)
  847.       try { selectStrings (s10chars__.length ()); } catch (java.sql.SQLException e) { showException (e); }
  848.  
  849.     if (test100CharStrings)
  850.       try { selectStrings (s100chars__.length ()); } catch (java.sql.SQLException e) { showException (e); }
  851.  
  852.     if (test1000CharStrings)
  853.       try { selectStrings (s1000chars__.length ()); } catch (java.sql.SQLException e) { showException (e); }
  854.  
  855.     if (test10000CharStrings)
  856.       try { selectStrings (s10000chars__.length ()); } catch (java.sql.SQLException e) { showException (e); }
  857.   }
  858.  
  859.   private static void selectStrings (int length) throws java.sql.SQLException
  860.   {
  861.     int numRows = 0;
  862.     int numChars = 0;
  863.     String temp;
  864.  
  865.     startTime__ = System.currentTimeMillis ();
  866.     s__ = c__.createStatement ();
  867.     rs__ = s__.executeQuery ("select S from CHAR" + length + "_TABLE"); // Network
  868.     while (rs__.next ()) { // Networks only when local row cache is exhausted
  869.       temp = rs__.getString(1);
  870.       numRows++;
  871.       numChars += temp.length();
  872.     }
  873.     s__.close ();
  874.     endTime__ = System.currentTimeMillis ();
  875.     elapsedTime__ = endTime__ - startTime__;
  876.     printStream__.println ("selected " + numRows + " rows of " + length + " char strings in: " +
  877.                  elapsedTime__ + " milliseconds (" + numChars  + " chars selected)");
  878.   }
  879.  
  880.   private static void testBLObInsertPerformance () throws java.sql.SQLException
  881.   {
  882.     if (test1ByteBlobs)
  883.       try { insertBLObs (b1byte__); } catch (java.sql.SQLException e) { showException (e); }
  884.  
  885.     if (test10ByteBlobs)
  886.       try { insertBLObs (b10bytes__);  } catch (java.sql.SQLException e) { showException (e); }
  887.  
  888.     if (test100ByteBlobs)
  889.       try { insertBLObs (b100bytes__);  } catch (java.sql.SQLException e) { showException (e); }
  890.  
  891.     if (test1000ByteBlobs)
  892.       try { insertBLObs (b1000bytes__); } catch (java.sql.SQLException e) { showException (e); }
  893.  
  894.     if (test10000ByteBlobs)
  895.       try { insertBLObs (b10000bytes__);  } catch (java.sql.SQLException e) { showException (e); }
  896.  
  897.     if (test100000ByteBlobs)
  898.       try { insertBLObs (b100000bytes__);  } catch (java.sql.SQLException e) { showException (e); }
  899.   }
  900.  
  901.   private static void insertBLObs (byte[] bytes) throws java.sql.SQLException
  902.   {
  903.     java.io.ByteArrayInputStream stream = null;
  904.     int numRows = Math.max (1, testDataSize/bytes.length);
  905.     int numBytes = 0;
  906.  
  907.     startTime__ = System.currentTimeMillis ();
  908.     ps__ = c__.prepareStatement ("insert into BLOB" + bytes.length + "_TABLE (B) values (?)"); // Network
  909.     for (int row = 0; row < numRows; row++) {
  910.       numBytes += bytes.length;
  911.       stream = new java.io.ByteArrayInputStream (bytes);
  912.       ps__.setBinaryStream (1, stream, bytes.length);
  913.       ps__.executeUpdate (); // Network
  914.     }
  915.     ps__.close ();
  916.     endTime__ = System.currentTimeMillis ();
  917.     elapsedTime__ = endTime__ - startTime__;
  918.     printStream__.println ("inserted " + numRows + " rows of " + bytes.length + " byte blobs in: " +
  919.                  elapsedTime__ + " milliseconds (" + numBytes + " bytes inserted)");
  920.   }
  921.  
  922.   private static void testBLObSelectPerformance () throws java.sql.SQLException
  923.   {
  924.     if (test1ByteBlobs)
  925.       try { selectBLObs (b1byte__.length);  } catch (java.sql.SQLException e) { showException (e); }
  926.  
  927.     if (test10ByteBlobs)
  928.       try { selectBLObs (b10bytes__.length); } catch (java.sql.SQLException e) { showException (e); }
  929.  
  930.     if (test100ByteBlobs)
  931.       try { selectBLObs (b100bytes__.length);  } catch (java.sql.SQLException e) { showException (e); }
  932.  
  933.     if (test1000ByteBlobs)
  934.       try { selectBLObs (b1000bytes__.length); } catch (java.sql.SQLException e) { showException (e); }
  935.  
  936.     if (test10000ByteBlobs)
  937.       try { selectBLObs (b10000bytes__.length); } catch (java.sql.SQLException e) { showException (e); }
  938.  
  939.     if (test100000ByteBlobs)
  940.       try { selectBLObs (b100000bytes__.length); } catch (java.sql.SQLException e) { showException (e); }
  941.   }
  942.  
  943.   private static void selectBLObs (int length) throws java.sql.SQLException
  944.   {
  945.     java.io.InputStream stream;
  946.     byte[] readBuffer = new byte[testDataSize]; // More than adequate
  947.     int numRows = 0;
  948.     int bytesRead;
  949.     int numBytes = 0;
  950.  
  951.     try {
  952.       startTime__ = System.currentTimeMillis ();
  953.       s__ = c__.createStatement ();
  954.       rs__ = s__.executeQuery ("select B from BLOB" + length + "_TABLE"); // Network
  955.       while (rs__.next ()) {
  956.     stream = rs__.getBinaryStream (1);
  957.         numRows++;
  958.         while ((bytesRead = stream.read (readBuffer)) != -1) { // Network
  959.           numBytes += bytesRead;
  960.         }
  961.       }
  962.       s__.close ();
  963.       endTime__ = System.currentTimeMillis ();
  964.       elapsedTime__ = endTime__ - startTime__;
  965.       printStream__.println ("selected " + numRows + " rows of " + length + " byte blobs in: " +
  966.              elapsedTime__ + " milliseconds (" + numBytes + " bytes selected)");
  967.     }
  968.     catch (java.io.IOException e) {
  969.       throw new java.sql.SQLException ("IOException: " + e.getMessage ());
  970.     }
  971.   }
  972.  
  973.   private static void testNumberInsertPerformance () throws java.sql.SQLException
  974.   {
  975.     try { insertNumbers (); } catch (java.sql.SQLException e) { showException (e); }
  976.   }
  977.  
  978.   private static void insertNumbers () throws java.sql.SQLException
  979.   {
  980.     int numRows = Math.max (1, testDataSize/numberBytesPerRecord__);
  981.  
  982.     startTime__ = System.currentTimeMillis ();
  983.     ps__ = c__.prepareStatement ("insert into NUMBER_TABLE (aSmallint," +
  984.                  "                          anInteger," +
  985.                  "                          aDouble," +
  986.                  "                          aFloat," +
  987.                  "                          aNumericSmallint," +
  988.                  "                          aNumericInteger," +
  989.                  "                          aNumericDouble)" +
  990.                  " values (?, ?, ?, ?, ?, ?, ?)"); // Network
  991.     for (int row = 0; row < numRows; row++) {
  992.       ps__.setShort (1, (short) 1);
  993.       ps__.setInt (2, 2);
  994.       ps__.setDouble (3, (double) 3);
  995.       ps__.setFloat (4, (float) 4);
  996.       ps__.setInt (5, 5);
  997.       ps__.setInt (6, 6);
  998.       ps__.setDouble (7, (double) 7);
  999.       ps__.executeUpdate (); // Network
  1000.     }
  1001.     ps__.close ();
  1002.     endTime__ = System.currentTimeMillis ();
  1003.     elapsedTime__ = endTime__ - startTime__;
  1004.     printStream__.println ("inserted " + numRows + " rows of " + numberBytesPerRecord__ + " byte number records in: " +
  1005.            elapsedTime__ + " milliseconds (" + numRows*numberBytesPerRecord__ + " bytes inserted)");
  1006.   }
  1007.  
  1008.   private static void testNumberSelectPerformance () throws java.sql.SQLException
  1009.   {
  1010.     try { selectNumbers ();  } catch (java.sql.SQLException e) { showException (e); }
  1011.   }
  1012.  
  1013.   private static void selectNumbers () throws java.sql.SQLException
  1014.   {
  1015.     int numRows = 0;
  1016.  
  1017.     s__ = c__.createStatement ();
  1018.     startTime__ = System.currentTimeMillis ();
  1019.     rs__ = s__.executeQuery ("select aSmallint," +
  1020.                  "       anInteger," +
  1021.                  "       aDouble," +
  1022.                  "       aFloat," +
  1023.                  "       aNumericSmallint," +
  1024.                  "       aNumericInteger," +
  1025.                  "       aNumericDouble" +
  1026.                  " from NUMBER_TABLE"); // Network
  1027.     while (rs__.next ()) { // Networks only when local row cache is exhausted
  1028.       numRows++;
  1029.       rs__.getString (1);
  1030.       rs__.getString (2);
  1031.       rs__.getString (3);
  1032.       rs__.getString (4);
  1033.       rs__.getString (5);
  1034.       rs__.getString (6);
  1035.       rs__.getString (7);
  1036.     }
  1037.     s__.close ();
  1038.     endTime__ = System.currentTimeMillis ();
  1039.     elapsedTime__ = endTime__ - startTime__;
  1040.     printStream__.println ("selected " + numRows + " rows of " + numberBytesPerRecord__ + " byte number records in: " +
  1041.            elapsedTime__ + " milliseconds (" + numRows*numberBytesPerRecord__  + " bytes selected)");
  1042.   }
  1043.  
  1044.   private static void testDateInsertPerformance () throws java.sql.SQLException
  1045.   {
  1046.     try { insertDates ();  } catch (java.sql.SQLException e) { showException (e); }
  1047.   }
  1048.  
  1049.   private static void insertDates () throws java.sql.SQLException
  1050.   {
  1051.     int numRows = Math.max (1, testDataSize/(3*8)); // 3 64-bit fields
  1052.  
  1053.     startTime__ = System.currentTimeMillis ();
  1054.     ps__ = c__.prepareStatement ("insert into DATE_TABLE (aDate," +
  1055.                  "                        aTime," +
  1056.                  "                        aTimestamp)" +
  1057.                  " values (?, ?, ?)"); // Network
  1058.     for (int row = 0; row < numRows; row++) {
  1059.       ps__.setDate (1, new java.sql.Date (98, 1, 3));
  1060.       ps__.setTime (2, new java.sql.Time (0, 0, 0));
  1061.       ps__.setTimestamp (3, new java.sql.Timestamp (98, 1, 3, 0, 0, 0, 0));
  1062.       ps__.executeUpdate (); // Network
  1063.     }
  1064.     ps__.close ();
  1065.     endTime__ = System.currentTimeMillis ();
  1066.     elapsedTime__ = endTime__ - startTime__;
  1067.     printStream__.println ("inserted " + numRows + " rows of 3 field (date, time, timestamp) records in: " +
  1068.                  elapsedTime__ + " milliseconds (" + numRows*3*8 + " bytes inserted)");
  1069.   }
  1070.  
  1071.   private static void testDateSelectPerformance () throws java.sql.SQLException
  1072.   {
  1073.     try { selectDates (); } catch (java.sql.SQLException e) { showException (e); }
  1074.   }
  1075.  
  1076.   private static void selectDates () throws java.sql.SQLException
  1077.   {
  1078.     int numRows = 0;
  1079.  
  1080.     s__ = c__.createStatement ();
  1081.     startTime__ = System.currentTimeMillis ();
  1082.     rs__ = s__.executeQuery ("select aDate," +
  1083.                  "       aTime," +
  1084.                  "       aTimestamp" +
  1085.                  " from DATE_TABLE"); // Network
  1086.  
  1087.     while (rs__.next ()) { // Networks only when local row cache is exhausted
  1088.       numRows++;
  1089.       rs__.getString (1);
  1090.       rs__.getString (2);
  1091.       rs__.getString (3);
  1092.     }
  1093.     s__.close ();
  1094.     endTime__ = System.currentTimeMillis ();
  1095.     elapsedTime__ = endTime__ - startTime__;
  1096.     printStream__.println ("selected " + numRows + " rows of 3 field (date, time, timestamp) records in: " +
  1097.                  elapsedTime__ + " milliseconds (" + numRows*3*8 + " bytes selected)");
  1098.   }
  1099.  
  1100.   private static void testProcedureInsertPerformance () throws java.sql.SQLException
  1101.   {
  1102.     startTime__ = System.currentTimeMillis ();
  1103.     s__ = c__.createStatement ();
  1104.     s__.executeUpdate ("execute procedure INSERT_PROC"); // Network
  1105.     s__.close ();
  1106.     endTime__ = System.currentTimeMillis ();
  1107.     elapsedTime__ = endTime__ - startTime__;
  1108.     printStream__.println ("executed procedure INSERT_PROC in: " +
  1109.                  elapsedTime__ + " milliseconds");
  1110.   }
  1111.  
  1112.   private static void testProcedureSelectPerformance () throws java.sql.SQLException
  1113.   {
  1114.     int numRows = 0;
  1115.  
  1116.     startTime__ = System.currentTimeMillis ();
  1117.     s__ = c__.createStatement ();
  1118.     s__.execute ("execute procedure SELECT_PROC"); // Network
  1119.     rs__ = s__.getResultSet ();
  1120.     while (rs__.next ()) { // Networks only when local row cache is exhausted
  1121.       numRows++;
  1122.       rs__.getString (1);
  1123.     }
  1124.  
  1125.     rs__ = s__.executeQuery ("execute procedure EXECUTE_PROC"); // Network
  1126.     while (rs__.next ()) { // Networks only when local row cache is exhausted
  1127.       numRows++;
  1128.       rs__.getString (1);
  1129.     }
  1130.  
  1131.     rs__ = s__.executeQuery ("select * from SELECT_PROC"); // Network
  1132.     while (rs__.next ()) { // Networks only when local row cache is exhausted
  1133.       numRows++;
  1134.       rs__.getString (1);
  1135.     }
  1136.  
  1137.     rs__ = s__.executeQuery ("select * from EXECUTE_PROC"); // Network
  1138.     while (rs__.next ()) { // Networks only when local row cache is exhausted
  1139.       numRows++;
  1140.       rs__.getString (1);
  1141.     }
  1142.  
  1143.     s__.close ();
  1144.     endTime__ = System.currentTimeMillis ();
  1145.     elapsedTime__ = endTime__ - startTime__;
  1146.     printStream__.println ("executed various procedures in: " +
  1147.                  elapsedTime__ + " milliseconds");
  1148.   }
  1149. }
  1150.