WebCab Technical Analysis
(J2EE Edition)

com.webcab.ejb.finance.trading.indicators.jdbc
Interface OscillatorsJDBC

All Superinterfaces:
EJBObject, Remote

public interface OscillatorsJDBC
extends EJBObject

A JDBC interface for the Oscillators Enterprise JavaBean. This component consists of several business methods that apply Oscillators methods onto SQL query results and SQL update queries directly from and into your DBMS.

This component is designed to easily transfer onto an Application Server JDBC specific tasks that make use of the mathematical capabilities of the Oscillators enterprise Bean.

This component contains four methods:

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 Oscillators bean 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 a bean's method the standard way by passing its parameters directly from your Java class and you require the resulting number to be written in a certain location in your database, you need to use the call (methodName, inputValues, outputQuery) method:

    // Create an EJB instance of this component
    JDBCInterface jdbc = jdbcHome.create (...)
    
    // Invoke a generic method from the Oscillators bean
    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 Oscillators bean 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.

Say 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 EJB instance of this component
    JDBCInterface jdbc = jdbcHome.create (...)

    // Invoke a generic method from the Oscillators bean
    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 Oscillators bean 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 EJB instance of this component
    JDBCInterface jdbc = jdbcHome.create (...)

    // Invoke a generic method from the Oscillators bean
    jdbc.call ("myMethodName", "SELECT DATASET, WEIGHT FROM DATA",
                  "INSERT INTO DATA3 (RESULT ) VALUES (?)");
 
For every computed row using the "myMethodName" method from the Oscillators bean, 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, you cannot tell which corresponding input values have been used for every row.

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 EJB instance of this component
    JDBCInterface jdbc = jdbcHome.create (...)

    // Invoke a generic method from the Oscillators bean
    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 Oscillators bean 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.


Method Summary
 void call(String methodName, Serializable[] inputValues, String outputQuery)
          Given an array of Java objects, this method identifies the corresponding Oscillators method methodName and writes the result of the computation to the database, as indicated by the output query.
 Serializable[] call(String methodName, String inputQuery)
          Given a SELECT type SQL query (retrieving rows from a database), this method identifies the corresponding Oscillators method methodName and applies it to every row in the query result set returning the results in a Serializable[] 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 Oscillators 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 Oscillators 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.
 
Methods inherited from interface javax.ejb.EJBObject
getEJBHome, getHandle, getPrimaryKey, isIdentical, remove
 

Method Detail

call

public void call(String methodName,
                 String inputQuery,
                 String outputQuery)
          throws SQLException,
                 OscillatorsJDBCException,
                 RemoteException
Given a SELECT type SQL query (retrieving rows from a database), this method identifies the corresponding Oscillators 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 bean 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 bean does not contain methods that have the same name and the same number of parameters.

Parameters:
methodName - The name of the Oscillators 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
OscillatorsJDBCException
RemoteException

call

public void call(String methodName,
                 String inputQuery,
                 String outputQuery,
                 int[][] inputOutputPairs)
          throws SQLException,
                 OscillatorsJDBCException,
                 RemoteException
Given a SELECT type SQL query (retrieving rows from a database), this method identifies the corresponding Oscillators 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 bean 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 bean 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 Oscillators 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
OscillatorsJDBCException
RemoteException

call

public void call(String methodName,
                 Serializable[] inputValues,
                 String outputQuery)
          throws SQLException,
                 OscillatorsJDBCException,
                 RemoteException
Given an array of Java objects, this method identifies the corresponding Oscillators method methodName and writes the result of the computation to the database, as indicated by the output query.

If the bean 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 Oscillators method you wish to analyze.
outputQuery - A prepared/callable statement with at least one IN parameter describing where in the database to put the computed result.
SQLException
OscillatorsJDBCException
RemoteException

call

public Serializable[] call(String methodName,
                           String inputQuery)
                    throws SQLException,
                           OscillatorsJDBCException,
                           RemoteException
Given a SELECT type SQL query (retrieving rows from a database), this method identifies the corresponding Oscillators method methodName and applies it to every row in the query result set returning the results in a Serializable[] array.

If the bean 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 bean does not contain methods that have the same name and the same number of parameters.

Parameters:
methodName - The name of the Oscillators 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
OscillatorsJDBCException
RemoteException

WebCab Technical Analysis
(J2EE Edition)