org.lateralnz.c3d
Class DatabaseEngine

java.lang.Object
  extended by org.lateralnz.c3d.DatabaseEngine
All Implemented Interfaces:
Constants, MessageListener

public class DatabaseEngine
extends java.lang.Object
implements Constants, MessageListener

core 'database' functionality -- basically this is the interceptor for all SQL statements so we can cache resultsets, refresh the cache and so on.


Field Summary
 
Fields inherited from interface org.lateralnz.common.util.Constants
AMPERSAND, AND, APPLICATION_X_WWW_FORM_URLENCODED, ASTERISK, AT, BACK_SLASH, CHAR_LEFT_CHEV, CHAR_RIGHT_CHEV, COLON, COMMA, CRLF, DASH, DELETE, DOLLAR, DOT, DOT_CLASS, DOT_JAVA, EIGHT, EMPTY, EQUALS, FALSE, FILE_SEPARATOR, FIVE, FORWARD_SLASH, FOUR, FULLSTOP, HASH, HAT, INSERT, LEFT_BRACE, LEFT_BRACKET, LEFT_CHEV, MAX_LEN_APPCODE, MAX_LEN_APPGROUP, MAX_LEN_MSGCODE, MAX_LEN_MSGTEXT, MINUS_ONE, N, NEWLINE, NINE, NO, NULL_STRING, OFF, ON, ONE, ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_WEEK, PATH_SEPARATOR, PERCENT, PIPE, PLUS, QUESTION_MARK, QUOTE, REQUIRED, REQUIRES_NEW, RETURN, RIGHT_BRACE, RIGHT_BRACKET, RIGHT_CHEV, SELECT, SEMICOLON, SEVEN, SINGLE_QUOTE, SIX, SPACE, SQ_LEFT_BRACKET, SQ_RIGHT_BRACKET, SUPPORTS, TEXT_HTML, TEXT_PLAIN, TEXT_XML, THREE, TRUE, TWO, UNDERSCORE, UPDATE, UTF_8, Y, YES, ZERO
 
Method Summary
protected  void commit(DCConnection conn)
           
protected  ResultWrapper execute(DCStatement st)
           
 java.sql.ResultSet getCachedResultSet(java.lang.String cacheName, java.lang.String sql)
           
 java.util.List getCachedResultsetNames(java.lang.String cacheName)
           
 java.util.List getCacheNames()
           
static DatabaseEngine getInstance(java.lang.String dbname, java.util.Properties props)
           
protected  java.lang.String[] getKeyColumnData(int[] keyColumns, java.sql.ResultSet rs)
          return the column data based on an array of primary key columns.
protected  int[] getPrimaryKeyColumns(java.lang.String cacheName, java.sql.ResultSetMetaData meta)
           
protected  java.lang.String getProperty(java.lang.String name)
           
 void handle(Message msg)
           
protected  void rollback(DCConnection conn)
          rollback a connection (get rid of operations list)
protected  void setCachedResultSet(java.lang.String cacheName, java.lang.String sql, java.sql.ResultSet rs)
          add a resultset to the cache
protected  void setKeyToResultSetLink(java.lang.String cacheName, java.lang.String[] rsKeys, java.lang.String sql)
          link a key to a resultset
 void triggerCacheChanges(java.util.ArrayList ll)
           
protected  boolean validate(java.lang.String user, java.lang.String password)
          validate user access to this 'database'
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static final DatabaseEngine getInstance(java.lang.String dbname,
                                               java.util.Properties props)
                                        throws java.sql.SQLException
Throws:
java.sql.SQLException

commit

protected void commit(DCConnection conn)
               throws java.sql.SQLException
Throws:
java.sql.SQLException

execute

protected ResultWrapper execute(DCStatement st)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

getCacheNames

public java.util.List getCacheNames()

getCachedResultsetNames

public java.util.List getCachedResultsetNames(java.lang.String cacheName)
                                       throws java.sql.SQLException
Throws:
java.sql.SQLException

getKeyColumnData

protected final java.lang.String[] getKeyColumnData(int[] keyColumns,
                                                    java.sql.ResultSet rs)
                                             throws java.sql.SQLException
return the column data based on an array of primary key columns. For example, if the primary keys are in columns 1, 5 and 6 of the resultset, this will return the data in those columns as a 3 element array.

Throws:
java.sql.SQLException

getPrimaryKeyColumns

protected int[] getPrimaryKeyColumns(java.lang.String cacheName,
                                     java.sql.ResultSetMetaData meta)
                              throws java.sql.SQLException
Throws:
java.sql.SQLException

getCachedResultSet

public java.sql.ResultSet getCachedResultSet(java.lang.String cacheName,
                                             java.lang.String sql)
                                      throws java.sql.SQLException
Throws:
java.sql.SQLException

getProperty

protected java.lang.String getProperty(java.lang.String name)

handle

public void handle(Message msg)
Specified by:
handle in interface MessageListener

triggerCacheChanges

public void triggerCacheChanges(java.util.ArrayList ll)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

rollback

protected void rollback(DCConnection conn)
rollback a connection (get rid of operations list)


setKeyToResultSetLink

protected void setKeyToResultSetLink(java.lang.String cacheName,
                                     java.lang.String[] rsKeys,
                                     java.lang.String sql)
                              throws java.sql.SQLException
link a key to a resultset

Parameters:
cacheName - the cache we're linking in
rsKeys - the primary key data to use as key
sql - the sql query used to generate the resultset
Throws:
java.sql.SQLException

setCachedResultSet

protected void setCachedResultSet(java.lang.String cacheName,
                                  java.lang.String sql,
                                  java.sql.ResultSet rs)
                           throws java.sql.SQLException
add a resultset to the cache

Throws:
java.sql.SQLException

validate

protected boolean validate(java.lang.String user,
                           java.lang.String password)
validate user access to this 'database'