WebCab Options and Futures Demo v2.5 (J2SE Edition)

## webcab.lib.finance.options.jdbc
Class ImpliedVolatilityJDBC

    java.lang.Object
      |
      +--webcab.lib.finance.options.jdbc.ImpliedVolatilityJDBC

public class ImpliedVolatilityJDBC
extends Object

This is the JDBC Mediator for the `ImpliedVolatility` class. This class consists of several business methods that apply `ImpliedVolatility` methods onto SQL query results and SQL update queries directly from and into your DBMS.

This class performs various JDBC tasks that make use of the mathematical capabilities of the `ImpliedVolatility` class.

This class contains four methods:

- Two methods to retrieve JDBC queries and place the results back into your database
- A method to retrieve JDBC queries and return the results as Java objects
- A method to accept Java objects as parameters and place the results into your database

Every one of these four methods looks up the name of the method you wish to apply to your database entries and according to its parameters, decides where to read the input parameters from and where to write them back to.

Since every method accepts as parameter the name of the method contained by the `ImpliedVolatility` class and determines which one to use according to the number of columns the input query returns or the length of the parameter array, we can consider the following generic examples.

If you wish to invoke one of the methods that ImpliedVolatility provides and write the result to your database, you will need to use the `call (methodName, inputValues, outputQuery)` method:

        // Create an instance of this class
        ImpliedVolatilityJDBC jdbc = new ImpliedVolatilityJDBC (...);

        // Invoke a generic method from ImpliedVolatility
        jdbc.call ("myMethodName", new Double[]
                   {new Double (6), new Double (0.8)},
                   "INSERT INTO DATA3 (RESULT) VALUES (?)");

The previous call invokes method "myMethodName" from the `ImpliedVolatility` class which presumably accepts no more than two double parameters and using the prepared/callable statement

        INSERT INTO DATA3 (RESULT) VALUES (?)

adds a new row to the `DATA3` table and writes the result computed by the "myMethodName" method in the `RESULT` field. As you may notice, the output query is a prepared/callable statement where the question mark has been replaced by the method "myMethodNames"'s result.

If you need to take the input parameters from your database and retrieve the output as an array of Java objects, you will be using the following method:

        // Create an instance of this class
        ImpliedVolatilityJDBC jdbc = new ImpliedVolatilityJDBC (...);

        // Invoke a generic method from ImpliedVolatility
        Object[] o = jdbc.call ("myMethodName", "SELECT * FROM FX_examples.GBP_USD_high");
        for (int i = 0; i < o.length; i++)
            System.out.println (o[i].toString ());

This `call` method retrieves the result set denoted by the `SELECT` statement, applies the method "myMethodName" from the `ImpliedVolatility` class to every row and puts the results in an array in the same order the rows were retrieved.

In order to read from a database and write back to a database, you will need to specify both an input and an output query. If the output location does not depend on the input location, you may use the `call (methodName, inputQuery, outputQuery)` method.

        // Create an instance of this class
        ImpliedVolatilityJDBC jdbc = new ImpliedVolatilityJDBC (...);

        // Invoke a generic method from ImpliedVolatility
        jdbc.call ("myMethodName", "SELECT DATASET, WEIGHT FROM DATA",
                      "INSERT INTO DATA3 (RESULT) VALUES (?)");

For every computed row using the "myMethodName" method from the `ImpliedVolatility` class, you add a new row to the `DATA3` table in the `RESULT` field. Every question mark from the output query is replaced by the value of the result returned by "myMethodName". In case your method returns an array of values, every value is written into a corresponding question mark.

Please note that even though the results are written in the same order they were computed, the entries inserted in the `DATA3` table do not point back to the entries in the input `DATASET` table.

Because of this limitation, we provide a more complex input/output query method which enables you to take full control over the way you update your database. In most input-output SQL queries you will require to somehow calculate the position of the computed result according to the position of the input values, taken from the same database. That is why this fourth method allows you to assign input query column values to certain question mark symbols contained by the output prepared/callable statement. This way you can control every output query to update table cells according to the value of a primary key or foreign key corresponding to the input values.

Please take a look at the following listing:

        // Create an instance of this class
        ImpliedVolatilityJDBC jdbc = new ImpliedVolatilityJDBC (...);

        // Invoke a generic method from ImpliedVolatility
        jdbc.call ("myMethodName",
                   "SELECT C_ID, SHARES, VALUE FROM TRADES",
                   "UPDATE CUSTOMER SET MONEY=? WHERE C_ID=?",
                   new int[][] {
                    {2, 1}
                   });

As you can see "myMethodName" is the method of choice from the `ImpliedVolatility` class and

        SELECT C_ID, SHARES, VALUE FROM TRADES

is the query to return the input values. The last parameter is an array of integer pairs, where the left item of every pair represents the number of the IN parameter (the question mark) of the prepared/callable statement and the right item points to the value from the input query result set to assign the IN parameter to. Both indices start numbering from `1`. The input value is reassigned with every row to the corresponding IN parameter. In our case, we are assigning the second IN parameter (`WHERE C_ID=?`) to the first input column, `C_ID`.

Note that all input parameters assigned to at least one IN parameter will not be passed on to the method used to compute the input values. In this case only the fields `SHARES` and `VALUE` in the `TRADES` table will be considered. Of course if you require an assigned parameter to be computed as well, specify its name again in your `SELECT` statement. In order to establish a JDBC connection to your database, specify the following when invoking the constructors of this class:

- Driver Name
  The name of the driver distributed by your DBMS vendor. For example, if you wish to connect to Oracle9i the driver name you will use will be "oracle.jdbc.driver.OracleDriver".
- URL
  The url is database vendor specific as well and will describe the name of the server, the database port number and maybe a service name. Under Oracle9i the URL you would use would have the following format:

  `jdbc:oracle:thin:@servername:1521:service`

- Username and Password
  The username and password are in most cases indispensable when connecting to any database.
- Properties
  This variable may be left `null` in most cases. It should be used in order to transfer properties additional to username and password.

This class defines every constructor from the ImpliedVolatility class with either one input/output database connection or two different input and output database connections. Every connection is defined as described above.

See Also:
  `ImpliedVolatility`

Constructor Summary
`ImpliedVolatilityJDBC(String driverName, String url, String user, String password, Properties info)` Creates a new instance of this `JDBC interface' that encapsulates a ImpliedVolatility class.
`ImpliedVolatilityJDBC(String inputDriverName, String inputURL, String inputUser, String inputPassword, Properties inputInfo, String outputDriverName, String outputURL, String outputUser, String outputPassword, Properties outputInfo)` Creates a new instance of this `JDBC interface' that encapsulates a ImpliedVolatility class.

Method Summary
`void` `call(String methodName, Object[] inputValues, String outputQuery)` Given an array of Java objects, this method identifies the corresponding `ImpliedVolatility` method `methodName` and writes the result of the computation to the database, as indicated by the output query.
`Object[]` `call(String methodName, String inputQuery)` Given a `SELECT` type SQL query (retrieving rows from a database), this method identifies the corresponding `ImpliedVolatility` method `methodName` and applies it to every row in the query result set returning the results in a `Object[]` array.
`void` `call(String methodName, String inputQuery, String outputQuery)` Given a `SELECT` type SQL query (retrieving rows from a database), this method identifies the corresponding `ImpliedVolatility` method `methodName` and applies it to every row in the query result set writing the results back to the database as specified by the output query.
`void` `call(String methodName, String inputQuery, String outputQuery, int[][] inputOutputPairs)` Given a `SELECT` type SQL query (retrieving rows from a database), this method identifies the corresponding `ImpliedVolatility` method `methodName` and applies it to every row in the query result set writing the results back to the database as specified by the output query and the input-output pairs.
`void` `close()` Close all open database connections and frees all JDBC-specific held resources, including the underlying ImpliedVolatility instance.
`ImpliedVolatility` `instance()` This method returns the underlying instance of the `ImpliedVolatility` business class.
`Object` `oneSelect(String methodName, String inputQuery)` Invokes method `methodName` once using values from running one `SELECT` statement.
`void` `oneSelect(String methodName, String inputQuery, String outputQuery)` Invokes method `methodName` once using values from running one `SELECT` statement and writes the result(s) back to the database running one `INSERT/UPDATE` statement.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ImpliedVolatilityJDBC

    public ImpliedVolatilityJDBC(String inputDriverName,
                                 String inputURL,
                                 String inputUser,
                                 String inputPassword,
                                 Properties inputInfo,
                                 String outputDriverName,
                                 String outputURL,
                                 String outputUser,
                                 String outputPassword,
                                 Properties outputInfo)
                          throws ImpliedVolatilityJDBCException,
                                 SQLException

  Creates a new instance of this `JDBC interface' that encapsulates a ImpliedVolatility class. The JDBC specific parameters are used to create the JDBC connections, while the others are used to initialize the ImpliedVolatility class.

Parameters:
  `inputDriverName` - The name of the driver used for the input connection.
  `inputURL` - The URL that describes the input connection address.
  `inputUser` - The input connection username.
  `inputPassword` - The input connection password.
  `inputInfo` - Additional input connection properties, `null` for none.
  `outputDriverName` - The name of the driver used for the output connection.
  `outputURL` - The URL that describes the input connection address.
  `outputUser` - The output connection username.
  `outputPassword` - The output connection password.
  `outputInfo` - Additional output connection properties, leave `null` for none.
See Also:
  `ImpliedVolatility.ImpliedVolatility()`

### ImpliedVolatilityJDBC

    public ImpliedVolatilityJDBC(String driverName,
                                 String url,
                                 String user,
                                 String password,
                                 Properties info)
                          throws SQLException,
                                 ImpliedVolatilityJDBCException

  Creates a new instance of this `JDBC interface' that encapsulates a ImpliedVolatility class. The JDBC specific parameters are used to create the JDBC connections, while the others are used to initialize the ImpliedVolatility class.

Parameters:
  `driverName` - The name of the driver used for establishing the connection.
  `url` - The URL that describes the connection address.
  `user` - The username to use when establishing the connection.
  `password` - The password to use when establishing the connection.
  `info` - Additional JDBC properties. Leave `null` for none.
See Also:
  `ImpliedVolatility.ImpliedVolatility()`

Method Detail

### instance

    public ImpliedVolatility instance()

  This method returns the underlying instance of the `ImpliedVolatility` business class. Use this method to work directly with the `ImpliedVolatility` class.

### close

    public void close()

  Close all open database connections and frees all JDBC-specific held resources, including the underlying ImpliedVolatility instance. Any caught SQL exceptions are ignored.

### oneSelect

    public Object oneSelect(String methodName,
                            String inputQuery)
                     throws SQLException,
                            ImpliedVolatilityJDBCException

  Invokes method `methodName` once using values from running one `SELECT` statement. The parameters of the underlying method can be primitives (e.g. numbers), one-dimensional arrays, but at most one of them can be a two-dimensional array.

  The `inputQuery` parameter of this method specifies the `SELECT` statement to use in invoking the underlying method. The columns of the result set returned by the `SELECT` statement correspond to the values of the parameters being sent to the underlying method as described below.

  #### Calling Methods with Primitive Parameters

  If `methodName` takes only non-array parameters, the method will be evaluated only for the first row in the `SELECT` result-set. The parameters will match their corresponding column in the same order -- first column value goes to the first parameter, second column value goes to the second parameter etc. The number of columns returned must be equal to or greater than the number of parameters in `methodName`'s declaration.

  #### Calling Methods with One-Dimensional Arrays and Primitive Parameters

  If `methodName` takes both non-array and one-dimensional array parameters, the method will be evaluated only for the first row in the `SELECT` result-set for the non-array parameters, and for the entire column values for the one-dimensional array parameters. The parameters will match their corresponding column in the same order -- first column values go to the first parameter, second column values go to the second parameter etc. The number of columns returned must be equal to or greater than the number of parameters in `methodName`'s declaration.

  #### Calling Methods with a Two-Dimensional Array Parameter

  If `methodName` takes (besides non-array and one-dimensional array parameters) one two-dimensional array parameter, the values being sent to the two-dimensional array parameter stretch between the last of the first columns (corresponding to the first primitive and/or array parameters) and the first of the last columns (corresponding to the last primitive and/or array parameters). In this case, this method will assume that all values returned by the `SELECT` statement are being used. Also note that every column represents a one-dimensional array element in the two-dimensional array value.

  Consider the following example for a fictive underlying method with the following signature:

           double bicubicSplinePointwiseEvaluation(
                              double[] tabulationPointsInFirstVariable
                              double[] tabulationPointsInSecondVariable,
                              double[][] function,
                              double interpolationPointFirstCoordinate,
                              double interpolationPointSecondCoordinate)

  First two parameters will be assigned to the first two columns returned by the `SELECT` statement and the last two parameters will be assigned to the last two columns. The third parameter, which is a two-dimensional array will be assigned to the remaining columns.

  If the underlying method's return type is `void`, this method will return `null`.

  Parameters:
    `methodName` - The name of the method from ImpliedVolatility you wish to call
    `inputQuery` - The `SELECT` statement which returns the values of the parameters being sent to the `methodName` method.
  Returns:
    The value returned by `methodName` as invoked using the values from the database, or `null` if the `methodName`'s return type is `void`.
    `SQLException`
    `ImpliedVolatilityJDBCException`

### oneSelect

    public void oneSelect(String methodName,
                          String inputQuery,
                          String outputQuery)
                   throws SQLException,
                          ImpliedVolatilityJDBCException

  Invokes method `methodName` once using values from running one `SELECT` statement and writes the result(s) back to the database running one `INSERT/UPDATE` statement. The parameters of the underlying method can be primitives (e.g. numbers), one-dimensional arrays, but at most one of them can be a two-dimensional array.

  The `inputQuery` parameter of this method specifies the `SELECT` statement to use in invoking the underlying method. The columns of the result set returned by the `SELECT` statement correspond to the values of the parameters being sent to the underlying method as described below.

  #### Calling Methods with Primitive Parameters

  If `methodName` takes only non-array parameters, the method will be evaluated only for the first row in the `SELECT` result-set. The parameters will match their corresponding column in the same order -- first column value goes to the first parameter, second column value goes to the second parameter etc. The number of columns returned must be equal to or greater than the number of parameters in `methodName`'s declaration.

  #### Calling Methods with One-Dimensional Arrays and Primitive Parameters

  If `methodName` takes both non-array and one-dimensional array parameters, the method will be evaluated only for the first row in the `SELECT` result-set for the non-array parameters, and for the entire column values for the one-dimensional array parameters. The parameters will match their corresponding column in the same order -- first column values go to the first parameter, second column values go to the second parameter etc. The number of columns returned must be equal to or greater than the number of parameters in `methodName`'s declaration.

  #### Calling Methods with a Two-Dimensional Array Parameter

  If `methodName` takes (besides non-array and one-dimensional array parameters) one two-dimensional array parameter, the values being sent to the two-dimensional array parameter stretch between the last of the first columns (corresponding to the first primitive and/or array parameters) and the first of the last columns (corresponding to the last primitive and/or array parameters). In this case, this method will assume that all values returned by the `SELECT` statement are being used. Also note that every column represents a one-dimensional array element in the two-dimensional array value.

  The `outputQuery` parameter is being run after calling `methodName`. It must be a prepared statement, with question-mark placeholders (parameters) corresponding to the values returned by `methodName`. If `methodName` returns a non-array value (e.g. a `double` value), the first parameter of the prepared statement will be set to this value. If `methodName` returns an array, the values of its elements are being set one-by-one to every parameter in the output statement.

  Consider the following example for a fictive underlying method with the following signature:

           double bicubicSplinePointwiseEvaluation(
                              double[] tabulationPointsInFirstVariable
                              double[] tabulationPointsInSecondVariable,
                              double[][] function,
                              double interpolationPointFirstCoordinate,
                              double interpolationPointSecondCoordinate)

  First two parameters will be assigned to the first two columns returned by the `SELECT` statement and the last two parameters will be assigned to the last two columns. The third parameter, which is a two-dimensional array will be assigned to the remaining columns.

  The `double` value returned by the method will be set as the first IN parameter (the first question-mark) of the output statement. For example, the following output query:

          INSERT INTO TABLE (COLUMN) VALUES (?)

  will be run as:

          INSERT INTO TABLE (COLUMN) VALUES (double value)

  where double value is the value returned by `methodName`.

  Parameters:
    `methodName` - The name of the method from ImpliedVolatility you wish to call
    `inputQuery` - The `SELECT` statement which returns the values of the parameters being sent to the `methodName` method.
    `outputQuery` - The `INSERT/UPDATE` statement to run in order to populate the values returned by the `methodName` method to the database.
    `SQLException`
    `ImpliedVolatilityJDBCException`

### call

    public void call(String methodName,
                     String inputQuery,
                     String outputQuery)
              throws SQLException,
                     ImpliedVolatilityJDBCException

  Given a `SELECT` type SQL query (retrieving rows from a database), this method identifies the corresponding `ImpliedVolatility` method `methodName` and applies it to every row in the query result set writing the results back to the database as specified by the output query.

  If the class contains more than one method with the same name, this method will make its choice according to the number of columns the query will return. Note that the type of every column is not taken into consideration, since the class does not contain methods that have the same name and the same number of parameters.

  Parameters:
    `methodName` - The name of the `ImpliedVolatility` method you wish to analyze.
    `inputQuery` - The SQL query text that will retrieve the results you wish to apply the method `methodName` to.
    `outputQuery` - A prepared/callable statement (containing question mark symbols) to specify the `UPDATE/INSERT` write-back procedure.
    `SQLException`
    `ImpliedVolatilityJDBCException`

### call

    public void call(String methodName,
                     String inputQuery,
                     String outputQuery,
                     int[][] inputOutputPairs)
              throws SQLException,
                     ImpliedVolatilityJDBCException

  Given a `SELECT` type SQL query (retrieving rows from a database), this method identifies the corresponding `ImpliedVolatility` method `methodName` and applies it to every row in the query result set writing the results back to the database as specified by the output query and the input-output pairs.

  If the class contains more than one method with the same name, this method will make its choice according to the number of columns the query will return. Note that the column types are not taken into consideration, since the class does not contain methods that have the same name and the same number of parameters.

  Every pair specifies the index (starting from `1`) of the prepared/callable statement IN parameter and the index (starting from `1`) of the input query column to assign to. Every column assigned to at least one IN parameter is not used for evaluation.

  Parameters:
    `methodName` - The name of the `ImpliedVolatility` method you wish to analyze.
    `inputQuery` - The SQL query text that will retrieve the results you wish to apply the method `methodName` to.
    `outputQuery` - A prepared/callable statement (containing question mark symbols) to specify the `UPDATE/INSERT` write-back procedure.
    `inputOutputPairs` - A list of pairs that assign to certain IN parameters column values returned by the input query. If you leave this parameter null or empty, this method will behave similarly to `call(methodName, inputQuery, outputQuery)`.
    `SQLException`
    `ImpliedVolatilityJDBCException`

### call

    public void call(String methodName,
                     Object[] inputValues,
                     String outputQuery)
              throws SQLException,
                     ImpliedVolatilityJDBCException

  Given an array of Java objects, this method identifies the corresponding `ImpliedVolatility` method `methodName` and writes the result of the computation to the database, as indicated by the output query.

  If the class contains more than one method with the same name, this method will make its choice according to the length of the array of objects.

  If the method returns an array of objects, every of its elements are assigned to the IN parameters of the prepared/callable statement.

  Parameters:
    `methodName` - The name of the `ImpliedVolatility` method you wish to analyze.
    `inputValues` - An array of objects representing input values for the `methodName`.
    `outputQuery` - A prepared/callable statement with at least one IN parameter describing where in the database to put the computed result.
    `SQLException`
    `ImpliedVolatilityJDBCException`

### call

    public Object[] call(String methodName,
                         String inputQuery)
                  throws SQLException,
                         ImpliedVolatilityJDBCException

  Given a `SELECT` type SQL query (retrieving rows from a database), this method identifies the corresponding `ImpliedVolatility` method `methodName` and applies it to every row in the query result set returning the results in a `Object[]` array.

  If the class contains more than one method with the same name, this method will make its choice according to the number of columns the query will return. Note that the type of every column is not taken into consideration, since the class does not contain methods that have the same name and the same number of parameters.

  Parameters:
    `methodName` - The name of the `ImpliedVolatility` method you wish to analyze.
    `inputQuery` - The SQL query text that will retrieve the results you wish to apply the method `methodName` to.
  Returns:
    An array of results where every item represents the result of the method `methodName` applied to the corresponding row from the SQL query result-set.
    `SQLException`
    `ImpliedVolatilityJDBCException`

WebCab Options and Futures Demo v2.5 (J2SE Edition)