WIDAR Classes

ca.nrc.widar.mccc.crm
Class CrmDb

java.lang.Object
  extended by java.lang.Thread
      extended by ca.nrc.widar.mccc.crm.CrmDb
All Implemented Interfaces:
java.awt.event.ActionListener, java.lang.Runnable, java.util.EventListener

public class CrmDb
extends java.lang.Thread
implements java.awt.event.ActionListener

WIDAR/EVLA - CRM: CrmDb Class

A class which facilitates the connection to the MySQL CrmDb that exists (or will exists) on the MCCC.

Copyright: National Research Council of Canada and Associated Universities Inc., 2010, 2011, 2012

Since:
1.0
Author:
Dave Del Rizzo (Dave.DelRizzo@nrc.gc.ca)
 

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static java.lang.String CLASSNAME
           
static java.lang.String DEFAULT_DATABASE
           
static java.lang.String DEFAULT_DRIVER
           
static java.lang.String DEFAULT_HOST
           
static java.lang.String DEFAULT_PASSWORD
           
static java.lang.Integer DEFAULT_PORT
           
static java.lang.String DEFAULT_URL
           
static java.lang.String DEFAULT_USERNAME
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CrmDb(ca.nrc.widar.jaxb.crm.CrmDbInfo cdiXml)
          Common Constructor for the CrmDb Class.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          Receives an ActionEvent, determines the source and performs instructions accordingly.
 void addActionListener(java.awt.event.ActionListener listener)
          Adds a listener to the action listener list within this class.
static void close()
          Attempt to close a connection to the DB
static boolean connect()
          Attempt to establish a connection with the database defined in the class variables.
protected  void fireActionEvent(java.lang.String value)
          Generates an action event for each class listed in the listener list, and calls the actionPerformed method in that class.
static java.sql.Connection getConnection()
          Returns the CrmDb Connection for any queries requiring to connect.
static ca.nrc.widar.jaxb.crm.CrmDbInfo getCrmDbInfo()
          Returns a CrmDbInfo object with the current CrmDb parameters, including a string version of the URL.
static java.lang.String getHost()
          Returns the Host name
static java.sql.Statement getReadOnlyStatement()
          Returns a read-only statement for any query requiring a Statement.
static java.sql.Statement getStatement()
          Returns a Statement for any query requiring a Statement.
static void halt()
          Closes the current CrmDb Connection and sets the running variable to false, allowing the execution loop of this Thread to stop upon being interrupted.
static boolean isConnected()
          Return the status of the DB connection
static boolean isDriverLoaded()
          Return the status of the DB Driver
static boolean isRunning()
          Return the status of the Db Server
 void removeActionListener(java.awt.event.ActionListener listener)
          Removes a listener from the action listener list within this class.
 void run()
          The execution loop of the CrmDb object.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASSNAME

public static final java.lang.String CLASSNAME
See Also:
Constant Field Values

DEFAULT_HOST

public static final java.lang.String DEFAULT_HOST
See Also:
Constant Field Values

DEFAULT_DATABASE

public static final java.lang.String DEFAULT_DATABASE
See Also:
Constant Field Values

DEFAULT_DRIVER

public static final java.lang.String DEFAULT_DRIVER
See Also:
Constant Field Values

DEFAULT_URL

public static final java.lang.String DEFAULT_URL
See Also:
Constant Field Values

DEFAULT_USERNAME

public static final java.lang.String DEFAULT_USERNAME
See Also:
Constant Field Values

DEFAULT_PASSWORD

public static final java.lang.String DEFAULT_PASSWORD
See Also:
Constant Field Values

DEFAULT_PORT

public static final java.lang.Integer DEFAULT_PORT
Constructor Detail

CrmDb

public CrmDb(ca.nrc.widar.jaxb.crm.CrmDbInfo cdiXml)
Common Constructor for the CrmDb Class. Attempts to establish a connection to the database specified in the input parameters, and sets status variables accordingly. If input parameters are missing, or the input CrmDbInfo object is null, the values are populated with default hard-coded values.

Parameters:
cdiXml - A CrmDbInfo JAXB element containing database connectivity information, or null if default values are to be used. Note that only attributes present within the CrmDbInfo object are processed. If attributes are missing from the object, then default values are used in their place.
Method Detail

run

public void run()
The execution loop of the CrmDb object.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

connect

public static boolean connect()
Attempt to establish a connection with the database defined in the class variables. NOTE: The current CrmDb is implemented within PostgreSQL and hence the connect method calls the method which connects to that DB

Returns:
Returns true if the connection was established, false otherwise.

getConnection

public static java.sql.Connection getConnection()
Returns the CrmDb Connection for any queries requiring to connect.

Returns:
The current Connection to the CrmDb.

getStatement

public static java.sql.Statement getStatement()
                                       throws java.sql.SQLException
Returns a Statement for any query requiring a Statement.

Throws:
java.sql.SQLException
Returns:
A Statement object for the CrmDb.

getReadOnlyStatement

public static java.sql.Statement getReadOnlyStatement()
                                               throws java.sql.SQLException
Returns a read-only statement for any query requiring a Statement.

Throws:
java.sql.SQLException
Returns:
A read-only Statement object for the CrmDb.

close

public static void close()
Attempt to close a connection to the DB


halt

public static void halt()
Closes the current CrmDb Connection and sets the running variable to false, allowing the execution loop of this Thread to stop upon being interrupted.


getCrmDbInfo

public static ca.nrc.widar.jaxb.crm.CrmDbInfo getCrmDbInfo()
Returns a CrmDbInfo object with the current CrmDb parameters, including a string version of the URL. This is nominally used for display of information to the CrmGui as the password for connection is not included.

Returns:
A CrmDbInfo object.

getHost

public static java.lang.String getHost()
Returns the Host name

Returns:
The host name String.

isDriverLoaded

public static boolean isDriverLoaded()
Return the status of the DB Driver

Returns:
True if the driver is loaded, false otherwise

isConnected

public static boolean isConnected()
Return the status of the DB connection

Returns:
True if the connection is active, false otherwise

isRunning

public static boolean isRunning()
Return the status of the Db Server

Returns:
True if the Db server is running, false otherwise

addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
Adds a listener to the action listener list within this class.

Parameters:
listener - The class being added to the listener list.

removeActionListener

public void removeActionListener(java.awt.event.ActionListener listener)
Removes a listener from the action listener list within this class.

Parameters:
listener - The class being removed from the listener list.

fireActionEvent

protected void fireActionEvent(java.lang.String value)
Generates an action event for each class listed in the listener list, and calls the actionPerformed method in that class.

Parameters:
value - A string value that is to be fired as the action in a newly created ActionEvent

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Receives an ActionEvent, determines the source and performs instructions accordingly. This is the action event handling method.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
event - The incoming action event.

NRAO/DRAO

National Radio Astronomy Observatory