com.faa.flyfaa
Class FlyfaaDbBean

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--com.faa.flyfaa.FlyfaaDbBean
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class FlyfaaDbBean
extends javax.servlet.http.HttpServlet

JavaBean used for interacting with the database. The flyFAA startup servlet, FlyFAAPoolServlet, creates an instance of OracleConnectionCacheImpl which is saved in the servlet context as a property called "dbcache" from which this class creates database connections using OracleConnectionCacheImpl's getConnection() method. Some other methods of interest provided by this class are:

Author:
Jeffrey H. Carroll
See Also:
Serialized Form

Field Summary
private  oracle.jdbc.pool.OracleConnectionCacheImpl cache
          Cache of database connection pools established at application start-up time.
private  javax.servlet.ServletConfig cfg
          Pointer to the ServletConfig.
private  java.lang.String Logf
          Pointer to the log file, which will be named FLYlogyyyy_Monddhhmm.txt (for example, FLYlog2003_Jan291940.txt) and is currently set up to reside in the /web/trace/atcscc/java_logs directory.
private  FlyFAAProjectBean project
          Pointer to the Project Bean
(package private)  java.lang.String strDD
          String to contain the HTML data produced by FillDelayData
 
Fields inherited from class javax.servlet.http.HttpServlet
HEADER_IFMODSINCE, HEADER_LASTMOD, LSTRING_FILE, lStrings, METHOD_DELETE, METHOD_GET, METHOD_HEAD, METHOD_OPTIONS, METHOD_POST, METHOD_PUT, METHOD_TRACE
 
Fields inherited from class javax.servlet.GenericServlet
config
 
Constructor Summary
FlyfaaDbBean()
          Database access bean constructor.
 
Method Summary
 java.lang.String banner(java.lang.String bgcolor, java.lang.String word2, java.lang.String word3)
          Generates the title banner for an error message.
 void closeConnectionObject(java.sql.Connection conn)
          Closes a given Connection object.
 long ComputeElapsedTime(long t1, long t2)
          Returns a long representing the absolute value of the difference between one time given in a long variable and a second time given in a long variable.
 java.sql.Connection connect()
          Makes a connection to the database as long as the 'cache' property has been set.
 java.lang.String ConvertMins(double nMins)
          Converts minutes to hours and minutes.
 void destroy()
           
 java.lang.String execGetCenters(java.lang.String keyword, java.sql.Connection conn)
          Calls the database stored procedure OIS.GET_CENTERS to get a list of centers associated with a keyword (like 'NOWEST' or 'ZDC1').
 boolean execGetNewTMIs()
          Executes code similar to the database stored procedure OIS.NEW_TMIS to find out if there are any new Traffic Management Initiatives since the last time that the DatabaseUpdater ran.
 java.lang.String execGetTip(java.lang.String airport, java.sql.Connection conn)
          Calls the database stored procedure OIS.GET_TIP_LOCAL to get a tool tip for an airport.
 java.sql.ResultSet execQuery(java.lang.String sql, java.sql.Connection conn)
          Executes an SQL query given as sql using the given Connection.
 int execUpdate(java.sql.Connection conn, java.lang.String sql)
          Executes an SQL INSERT, UPDATE or DELETE command.
 oracle.jdbc.pool.OracleConnectionCacheImpl getCache()
          Gets the FlyfaaDbBean's "cache" property (an object of type OracleConnectionCacheImpl), which was initially instantiated by the start-up servlet FlyFAAPoolServlet.
 java.util.Calendar getGMTCalendar()
          Gets a GMT Calendar.
 java.util.Calendar getGMTCalendar(int year, int month, int date, int hour, int minute)
          Gets a GMT Calendar with a specified date and time.
 boolean getLock(FlyFAAProjectBean b)
          Gets the lock flag for the flyFAA Java Application from the FlyFAAProjectBean.
 java.lang.String getstrDD()
          Gets the FlyfaaDbBean's "strDD" property
 java.lang.String PartialSeconds(long t)
          Returns a string representation of a time given in a long variable formatted in seconds and milliseconds.
 java.lang.String SecondsOut(long time1, long time2)
          Computes the time difference between two times (in long variables) and returns a string representing the time difference in seconds and milliseconds.
 void setCache(oracle.jdbc.pool.OracleConnectionCacheImpl occi)
          Sets the FlyfaaDbBean's "cache" property to the given OracleConnectionCacheImpl, which is set up by the start-up servlet FlyFAAPoolServlet.
 void setProject(FlyFAAProjectBean proj)
          Sets the FlyfaaDbBean's "project" property to the given FlyFAAProjectBean.
 void setstrDD(java.lang.String s)
          Sets the FlyfaaDbBean's "strDD" property to the given String.
 
Methods inherited from class javax.servlet.http.HttpServlet
, doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getAllDeclaredMethods, getLastModified, maybeSetLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

Logf

private java.lang.String Logf
Pointer to the log file, which will be named FLYlogyyyy_Monddhhmm.txt (for example, FLYlog2003_Jan291940.txt) and is currently set up to reside in the /web/trace/atcscc/java_logs directory.

strDD

java.lang.String strDD
String to contain the HTML data produced by FillDelayData

cache

private oracle.jdbc.pool.OracleConnectionCacheImpl cache
Cache of database connection pools established at application start-up time.

project

private FlyFAAProjectBean project
Pointer to the Project Bean

cfg

private javax.servlet.ServletConfig cfg
Pointer to the ServletConfig. checkFAAData will get the project bean reference from the servlet context if it's possible to get the ServletConfig.
Constructor Detail

FlyfaaDbBean

public FlyfaaDbBean()
Database access bean constructor. References the package private FlyLog.LogFile property to set up a pointer to the logfile.
Method Detail

setstrDD

public void setstrDD(java.lang.String s)
Sets the FlyfaaDbBean's "strDD" property to the given String. This string is HTML which is generated by FillDelayData.

Parameters:
s - String of HTML produced by FillDelayData

getstrDD

public java.lang.String getstrDD()
Gets the FlyfaaDbBean's "strDD" property

Returns:
String HTML produced by FillDelayData

setProject

public void setProject(FlyFAAProjectBean proj)
Sets the FlyfaaDbBean's "project" property to the given FlyFAAProjectBean.

Parameters:
proj - FlyFAAProjectBean object reference

setCache

public void setCache(oracle.jdbc.pool.OracleConnectionCacheImpl occi)
Sets the FlyfaaDbBean's "cache" property to the given OracleConnectionCacheImpl, which is set up by the start-up servlet FlyFAAPoolServlet.

Parameters:
occi - OracleConnectionCacheImpl to use as the database connection pool cache

getCache

public oracle.jdbc.pool.OracleConnectionCacheImpl getCache()
Gets the FlyfaaDbBean's "cache" property (an object of type OracleConnectionCacheImpl), which was initially instantiated by the start-up servlet FlyFAAPoolServlet.

Returns:
this bean's database connection pool cache

connect

public java.sql.Connection connect()
                            throws java.sql.SQLException,
                                   java.io.IOException
Makes a connection to the database as long as the 'cache' property has been set. If the cache's getConnection() method returns null (which it may do since the cache uses the Fixed Return Null Scheme), this method loops for up to five seconds attempting to obtain a connection. If, after that time, a Connection remains unavailable, this method throws an IOException.

Returns:
Connection - a Connection to the database
Throws:
java.sql.SQLException - if a database access error occurs
java.io.IOException - if a connection cannot be obtained within 5 seconds

destroy

public void destroy()
Overrides:
destroy in class javax.servlet.GenericServlet

closeConnectionObject

public void closeConnectionObject(java.sql.Connection conn)
                           throws java.sql.SQLException
Closes a given Connection object.

Parameters:
conn - The Connection object to be closed
Throws:
java.sql.SQLException - if a database access error occurs

execQuery

public java.sql.ResultSet execQuery(java.lang.String sql,
                                    java.sql.Connection conn)
                             throws java.sql.SQLException
Executes an SQL query given as sql using the given Connection.

Parameters:
sql - String containing an SQL query (which should produce a ResultSet) to be executed by the database
conn - A database connection object
Returns:
ResultSet - the ResultSet produced by the given query
Throws:
java.sql.SQLException - if a database access error occurs

execUpdate

public int execUpdate(java.sql.Connection conn,
                      java.lang.String sql)
               throws java.sql.SQLException
Executes an SQL INSERT, UPDATE or DELETE command.

Parameters:
conn - Connection object
sql - String containing an SQL INSERT, UPDATE or DELETE statement or an SQL statement that returns nothing
Returns:
int - either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
Throws:
java.sql.SQLException - if a database access error occurs

execGetTip

public java.lang.String execGetTip(java.lang.String airport,
                                   java.sql.Connection conn)
                            throws java.sql.SQLException,
                                   java.io.IOException
Calls the database stored procedure OIS.GET_TIP_LOCAL to get a tool tip for an airport.

Parameters:
airport - Airport ID for which the tooltip is to be obtained
conn - handle to a database Connection object; if null, this method will try to obtain a connection
Returns:
String - containing tool tip text in HTML

Throws:
java.sql.SQLException - If a database access error occurs
java.io.IOException - if conn is null and a Connection cannot be obtained within 5 seconds

execGetNewTMIs

public boolean execGetNewTMIs()
                       throws java.lang.Exception
Executes code similar to the database stored procedure OIS.NEW_TMIS to find out if there are any new Traffic Management Initiatives since the last time that the DatabaseUpdater ran. Counts the number of new closures, delays, ground stops and ground delay programs whose update_time is greater than the last time the DatabaseUpdater ran (returned by getDbStartTime()). This method detects deleted records by checking the DELETED_TIME column.

Returns:
true - if there are new Traffic Management Initiatives, indicating that the DatabaseUpdater should run, false otherwise.

Throws:
java.sql.SQLException - if a database access error occurs
java.io.IOException - if a Connection cannot be obtained within 5 seconds

execGetCenters

public java.lang.String execGetCenters(java.lang.String keyword,
                                       java.sql.Connection conn)
                                throws java.sql.SQLException,
                                       java.io.IOException
Calls the database stored procedure OIS.GET_CENTERS to get a list of centers associated with a keyword (like 'NOWEST' or 'ZDC1').
Parameters:
keyword - keyword which corresponds to a list of centers
conn - handle to a database Connection object; if null, this method will try to obtain a connection
Returns:
String - containing list of centers associated with the keyword

Throws:
java.sql.SQLException - If a database access error occurs
java.io.IOException - if conn is null and a Connection cannot be obtained within 5 seconds

banner

public java.lang.String banner(java.lang.String bgcolor,
                               java.lang.String word2,
                               java.lang.String word3)
Generates the title banner for an error message. Usage: banner(bgcolor, word, word).

Parameters:
bgcolor - String containing the background color for the banner (include the #)
word2 - String with the first word to be shown in the banner
word3 - String with the second word to be shown in the banner
Returns:
String - HTML code containing the banner table

getLock

public boolean getLock(FlyFAAProjectBean b)
Gets the lock flag for the flyFAA Java Application from the FlyFAAProjectBean. Waits for lock to be available before continuing.

Parameters:
b - FlyFAAProjectBean reference
Returns:
true only after the lock is obtained

getGMTCalendar

public java.util.Calendar getGMTCalendar()
Gets a GMT Calendar.

Returns:
Calendar in the GMT timezone without any time being set.

getGMTCalendar

public java.util.Calendar getGMTCalendar(int year,
                                         int month,
                                         int date,
                                         int hour,
                                         int minute)
Gets a GMT Calendar with a specified date and time.

Parameters:
year - int containing the year of the date to which the calendar is being set
month - int containing the month of the date to which the calendar is being set (0-based)
date - int containing the day of the month of the date to which the calendar is being set
hour - int containing the hour of the date to which the calendar is being set
minute - int containing the minute of the date to which the calendar is being set
Returns:
Calendar in the GMT timezone while setting the given time.

SecondsOut

public java.lang.String SecondsOut(long time1,
                                   long time2)
Computes the time difference between two times (in long variables) and returns a string representing the time difference in seconds and milliseconds. The absolute value of the two longs is obtained, so it does not matter which one represents the earlier time.

Parameters:
time1 - long representing one of the times
time2 - long representing the other time
Returns:
String containing the number of seconds and milliseconds represented by the difference between time2 and time1 in "#0.000" format with " seconds" added on to the end of the string. "unknown number of seconds" is returned if an exception arises while casting to DecimalFormat.

PartialSeconds

public java.lang.String PartialSeconds(long t)
Returns a string representation of a time given in a long variable formatted in seconds and milliseconds. The result represents the number of seconds which remain after dividing by 60.

Parameters:
t - long representing a time in milliseconds
Returns:
String containing the number of seconds and milliseconds represented by the given time in "#0.000" format with " seconds" added on to the end of the string. "unknown number of seconds" is returned if an exception arises while casting to DecimalFormat.

ComputeElapsedTime

public long ComputeElapsedTime(long t1,
                               long t2)
Returns a long representing the absolute value of the difference between one time given in a long variable and a second time given in a long variable. In addition, a computation is performed to compute the number of hours, minutes and seconds represented by the time difference; the result of the computation is written to the FlyLog.

Parameters:
t1 - long representing one of the times
t2 - long representing the other time
Returns:
long containing the number of milliseconds represented by the absolute value of the difference between t1 and t2.

ConvertMins

public java.lang.String ConvertMins(double nMins)
Converts minutes to hours and minutes.

Parameters:
nMins - double number of minutes to be converted
Returns:
String representing the number of minutes expressed in terms of hour(s) and minute(s)