db
Class DBUtils

java.lang.Object
  extended bydb.DBUtils

public class DBUtils
extends java.lang.Object

Contains methods to initiate user queries. Queries or calls to methods that generate standard queries are invoked and this class interfaces with the actual data access engine to run these queries against the database.


Field Summary
private static java.util.ArrayList batchQueries
          collection queries which are sent to the database to process as a batch when its size reaches a certain level
 
Constructor Summary
DBUtils()
           
 
Method Summary
static void clearBatchQueries()
          Initializes the bach Queries array list to begin accepting new update queries
static boolean constructInsertQuery(java.util.HashMap values, boolean lastUpdate)
          Constructs an insert query for the values passed in via the hashmap
static void constructUpdateQuery(java.util.HashMap values, boolean lastUpdate)
          Constructs an update query for the values passed in via the hashmap
private static java.lang.String convertQueryToXML(java.lang.String query)
          Converts the standard string query into an XML wrapped query
static boolean dropStockStatTable()
          Drops all items in the stock stat table in preperation for adding new statistics values
static void executeBatch()
          Sends off a batch query request in a threaded manner and returns and clears the arraylist batchQueries to get ready for the next batch of queries to be created.
private static void executeMiniBatch(java.util.ArrayList miniBatch)
          Executes a batch of queries created inside the DBUtils class.
static java.lang.Object getDataSetForTicker(java.lang.String ticker)
          Gets the results set for an individual ticker name.
static java.lang.Object getDbDesc()
          Runs a description query to retrieve a description of the stockStat table
static java.lang.Object getStatisticsList()
          Gets an unaltered result set encapsulating the list of all stocks that have statistics associated with them
static java.lang.Object getStockList()
          Gets an unaltered result set encapsulating the list of all stocks in the database
static java.lang.Object getTestStockList()
          Gets an unaltered test result set encapsulating the list of one stock in the database - AAUK
static jqubeObjects.DataSet runDateQuery(jqubeObjects.UserQuery q)
          Run a date range query to receive a date range data set to plot and put in the results set table model
static jqubeObjects.DataSet runInitializeQuery()
          Runs the initial query that is returns results to populate the table on the main panel containing the entire list of stocks and company name
static jqubeObjects.DataSet runNewsQuery(jqubeObjects.UserQuery q)
          Run a news query to receive every news story available for the ticker withing the specified date range
static jqubeObjects.DataSet runQuery(java.lang.String query)
          Takes the user query and passes it to the functions to handle connecting to and executing the query
static jqubeObjects.DataSet runStockQuery(jqubeObjects.UserQuery q)
          Construct, send and retrieve results for a single user query encapsulated in the query object
static java.lang.Object runStockStatQuery()
          Runs a query to retrieve the stock statistics for every stock in the database
static boolean runTestQuery(java.lang.String connectionString)
          Run a test query to test the connectivity to the database.
static void updateMarketInStatTable()
          Re-associates the market with each ticker in the stock stat table after all statistic insert statemts have been run.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

batchQueries

private static java.util.ArrayList batchQueries
collection queries which are sent to the database to process as a batch when its size reaches a certain level

Constructor Detail

DBUtils

public DBUtils()
Method Detail

convertQueryToXML

private static java.lang.String convertQueryToXML(java.lang.String query)
Converts the standard string query into an XML wrapped query

Parameters:
query - Regular string query
Returns:
The query wrapped in XML tags

runQuery

public static jqubeObjects.DataSet runQuery(java.lang.String query)
Takes the user query and passes it to the functions to handle connecting to and executing the query

Parameters:
query - The XML wrapped query to pass to the database
Returns:
The results from the query

runTestQuery

public static boolean runTestQuery(java.lang.String connectionString)
Run a test query to test the connectivity to the database.

The passed in connectionString can either be a valid string or null, in which case the default connection string set in the DBConnect class is used to attempt to form the connection.

Returns:
true if the connection succeeded, false otherwise

runInitializeQuery

public static jqubeObjects.DataSet runInitializeQuery()
Runs the initial query that is returns results to populate the table on the main panel containing the entire list of stocks and company name

Returns:
the data set containing all companies and ticker names

runStockQuery

public static jqubeObjects.DataSet runStockQuery(jqubeObjects.UserQuery q)
Construct, send and retrieve results for a single user query encapsulated in the query object

Parameters:
q - User Query object that defines a query
Returns:
The results from the user query

runDateQuery

public static jqubeObjects.DataSet runDateQuery(jqubeObjects.UserQuery q)
Run a date range query to receive a date range data set to plot and put in the results set table model

Parameters:
q - User query object specifying the start and end date of the date range query
Returns:
The results from the user query

runNewsQuery

public static jqubeObjects.DataSet runNewsQuery(jqubeObjects.UserQuery q)
Run a news query to receive every news story available for the ticker withing the specified date range

Parameters:
q - User query object specifying the ticker, start and end date of the news query
Returns:
The results from the user query

getStockList

public static java.lang.Object getStockList()
Gets an unaltered result set encapsulating the list of all stocks in the database

Returns:
untyped results set object containing a list of ticker/company names

getStatisticsList

public static java.lang.Object getStatisticsList()
Gets an unaltered result set encapsulating the list of all stocks that have statistics associated with them

Returns:
untyped results set object containing a list of tickers/company names

getTestStockList

public static java.lang.Object getTestStockList()
Gets an unaltered test result set encapsulating the list of one stock in the database - AAUK

Returns:
untyped results set object containing a list of ticker

getDataSetForTicker

public static java.lang.Object getDataSetForTicker(java.lang.String ticker)
Gets the results set for an individual ticker name.

Runs the query:

SELECT ticker, open, close, high, low, volume, date, date_format(date,'%c') month, date_format(date,'%Y') year

FROM stock

WHERE ticker = 'ticker'

ORDER BY date ASC

Parameters:
ticker - the ticker to query for
Returns:
an untyped ResultSet object

clearBatchQueries

public static void clearBatchQueries()
Initializes the bach Queries array list to begin accepting new update queries


constructUpdateQuery

public static void constructUpdateQuery(java.util.HashMap values,
                                        boolean lastUpdate)
Constructs an update query for the values passed in via the hashmap

Parameters:
values - hashmap of values to update the stockstat table with
lastUpdate - true if this is the last update statistic to be loaded to the database

constructInsertQuery

public static boolean constructInsertQuery(java.util.HashMap values,
                                           boolean lastUpdate)
Constructs an insert query for the values passed in via the hashmap

Parameters:
values - hashmap of values to insert into the stockstat table
lastUpdate - true if this is the last insert statistic to be loaded to the database
Returns:
true if this call to the function caused the batch insert to execute, false otherwise

runStockStatQuery

public static java.lang.Object runStockStatQuery()
Runs a query to retrieve the stock statistics for every stock in the database

Returns:
an untyped result set object

dropStockStatTable

public static boolean dropStockStatTable()
Drops all items in the stock stat table in preperation for adding new statistics values


updateMarketInStatTable

public static void updateMarketInStatTable()
Re-associates the market with each ticker in the stock stat table after all statistic insert statemts have been run.

Runs the update queries as a batch set.


getDbDesc

public static java.lang.Object getDbDesc()
Runs a description query to retrieve a description of the stockStat table

Returns:
an untyped result set object

executeBatch

public static void executeBatch()
Sends off a batch query request in a threaded manner and returns and clears the arraylist batchQueries to get ready for the next batch of queries to be created.


executeMiniBatch

private static void executeMiniBatch(java.util.ArrayList miniBatch)
Executes a batch of queries created inside the DBUtils class.

This gets around the problem of other major batch threads deleting a small set of batch queries that have not been invoked yet.

Parameters:
miniBatch - the collection of queries to run in batch mode