planetj.database
Class SQLContext

java.lang.Object
  extended byplanetj.dataengine.AbstractContext
      extended byplanetj.database.SQLContext
All Implemented Interfaces:
java.lang.Cloneable, IContext, INavigationObject, java.io.Serializable
Direct Known Subclasses:
ApplicationSQLContext

public class SQLContext
extends AbstractContext
implements java.io.Serializable, java.lang.Cloneable

Contains information about an SQL command, including parameters on how to run the command, the command itself, and how to organize the command's results.

See Also:
Serialized Form

Field Summary
static int ALL_ROWS
           
static int CACHE_EXPIRATION_TIME_1_DAY
           
static int CACHE_EXPIRATION_TIME_1_HOUR
           
static int CACHE_EXPIRATION_TIME_1_WEEK
           
static int CACHE_EXPIRATION_TIME_15_MINUTES
           
static int CACHE_EXPIRATION_TIME_30_MINUTES
           
static int CACHE_EXPIRATION_TIME_NEVER
           
static int CACHING_CHECK
          This SQLContext should check the cache instead of going to the DB if possible, but any results retrieved from the DB should not be stored in the cache
static int CACHING_CHECK_AND_STORE
          This SQLContext should check the cache instead of going to the DB if possible, and should store any data from the DB in the cache if possible.
static int CACHING_NONE
          This SQLContext should not use caching
static int CACHING_STORE
          This SQLContext should not check the cache, but if possible should store any data retrieved from the DB in the cache
static java.lang.String className
           
static short LIBRARY_AS_SPECIFIED
          This statment already has the libraries it is going against specified
static short LIBRARY_SYSTEM
          This statement is again the system library
static short LIBRARY_UNKNOWN
          It is not known if this statement is against the user or system library.
static short LIBRARY_USER
          This statement is against the user library
 
Fields inherited from class planetj.dataengine.AbstractContext
DEFAULT_TYPE, mCode, mLocked, mParameterized, mParameterNames, mParameterSource, mParameterValues, PARAM_ESCAPE_NUMBERED, PARAM_ESCAPE_TABLE, PARAM_ESCAPE_USAGE_ID, PARAM_ESCAPE_USER, PARAM_ESCAPE_USER_USAGE_ID, PARAM_NUMBERED, PARAM_TABLE, PARAM_USAGE_ID, PARAM_USER, PARAM_USER_USAGE_ID, TYPE_TABLE_PARAMETER
 
Constructor Summary
SQLContext()
          SQLContext constructor
SQLContext(java.lang.String pSystemAlias)
          SQLContext constructor
SQLContext(java.lang.String pSystemAlias, ExecutingContext ec)
          SQLContext constructor
SQLContext(java.lang.String pSystemAlias, IUser user)
          Deprecated. replaced with SQLContext(String, ExecutingContext)
 
Method Summary
 void addListener(IDataEngineListener listener)
          Adds a listener to this SQLContext.
 void addTable(Table newTable)
          Adds a table to this query.
protected  java.lang.StringBuffer appendProperties(java.lang.StringBuffer info)
          Gets a String representation of this context.
 void clear()
          Wipes out the info in this SQLContext, restoring the default values.
 void clearTables()
          Clears the tables to this query.
 java.lang.Object clone()
          Creates an unlocked copy of this SQLContext
 SQLContext cloneContext()
          Creates an unlocked copy of this SQLContext
 SQLContext cloneContext(boolean clearExecutingContext)
          Creates an unlocked copy of this SQLContext
 boolean equals(java.lang.Object o)
           
 java.lang.Object execute()
          Executes the SQL statement contained in this context and returns the results.
 java.lang.Object execute(boolean informOperation)
          Executes the SQL statement contained in this context and returns the results.
protected  void finalize()
           
 int getCachingLevel()
          Gets the current caching level, describing whether the cache should be checked, and whether results should be stored in the cache.
 long getCachingTimeMillis()
          Gets the amount of time in milliseconds this context's results are to be cached.
 java.sql.Connection getConnection()
          Gets theCconnection that should be used for queries which use thix QuerContext.
 java.sql.Connection getConnection(boolean pCreate)
          Gets the connection that should be used for DataEngine operations which use this SQLContext
 java.lang.String getConnectionAlias()
          Deprecated. Just use getSystemAlias() instead
 java.lang.Object getConnectionOwner()
          If the Connection contained in this object was created in this SQLContext, then this object is returned.
 int getExecutionRule()
          Gets the execution rule for this context.
 int getFirstRowIndex()
          Insert the method's description here.
protected static int getHashcode(java.lang.Object o)
           
 SQLContext getKeyContext()
          Gets the SQLContext to be used as a key in the cache.
protected  java.util.List getListeners()
          Gets the List of listeners.
 java.util.List getLogicalFieldNames()
          Gets a List of the names of logical Fields in this SQLContext.
 java.lang.String getMetaDataAlias()
           
 int getMode()
          Gets a constant (such as Row.MODE_UPDATE or ROW.MODE_INSERT) describing the type of action this SQLContext is performing
 int getNumberOfTables()
          Gets the number of tables being queried.
protected  java.lang.Class getParameterClass(java.lang.String parameterToken)
          Returns the appropriate class for creating a parameter based on the parameter token.
 PropertyGroupList getPropertyGroups()
          Get all the property groups stored in this RowCollection's attributes.
protected  java.lang.String getRectifiedCode()
          Gets the rectified code which has already been passed through the rectifyCode() method but has not had any metadata library alteration performed on it yet
 ReportBreakCollection getReportBreakCollection()
          Gets the ReportBreakCollection defining the reports that will be generated in the RowCollection resulting from queries which use this SQLContext
 int getReRunCount()
          Get the number of times this context was attempted to run.
 java.lang.Class getRowClass()
          Gets the type of Row objects that will be included in the RowCollection resulting from the query.
 RowCollection getRowCollection()
          Gets the RowCollection object into which retrieved rows will be inserted.
 java.lang.Class getRowCollectionClass()
          Gets the type of RowCollection that will contain this query's results.
 int getRowCount()
          Gets the number of rows to add to the RowCollection.
 IRowCreator getRowCreator()
          Gets the object used to create the Rows the query should return.
 java.lang.String getSafeSQL()
          Returns this context's SQL, with all single quotes, double quotes, and backslashes replaced with underscores
 Row getSourceRow()
          If this SQLContext is an update, insert, or delete statement which pertains to one specific row, then this method gets that row.
 java.lang.String getSQL()
          Gets this SQLContext's SQL String.
 DeleteStatement getSQLDeleteStatement()
          Get the context's current delete statement.
 InsertStatement getSQLInsertStatement()
          Get the context's current insert statement.
 java.util.Iterator getSQLParameters()
          Returns an iteration of all the ISQLParameters in this context.
 SelectStatement getSQLSelectStatement()
          Get the context's current select statement.
 SQLStatement getSQLStatement()
          Gets the SQL Statement object for this SQLContext
 UpdateStatement getSQLUpdateStatement()
          Get the context's current update statement.
 java.lang.String getSystemAlias()
          Gets the system alias for the SQL operation.
 Table getTable()
          Gets the table which is being queried.
 Table getTable(int pTableIndex)
          Gets the table being queried with the given index.
 TableCollection getTables()
          Gets the tables being queried.
 long getTimestamp()
          Gets when this SQLContext was last run
 java.lang.String getTitle()
          Gets the title of this SQLContext, which will also be the title of any RowCollections retrieved via this SQLContext
 int getTotalRecords()
          Get the total number or records possible from running SQL.
 int getTotalRecordsFromDB()
          Runs a separate query against the DB to determine the total number of records which match the query in this context
 Row getUsageIdRow()
          Gets the row whose data should be used to replace literal usage id's in the SQL (indicated with a ##?)
 short getUseWOWLibrary()
          Tests which WOW library should be used to execute this context.
 int hashCode()
           
protected static int hashCode(java.util.List l)
          Gets the hashCode of a List.
 boolean hasListeners()
          Tests if there are any objects listening to this SQLContext.
protected  void initializeAndStore(IParameter param, java.lang.String parameterToken)
          Initializes and stores the parameter in this context
 boolean isAlterTableStatement()
          Check if this context contains an alter table statement.
 boolean isAssociatedJoinOperationPresent()
          Tests if the RC returned by this SQLContext has one or more columns whose FD's have an associated join operation
 boolean isAutoRefresh()
          Tests if RowCollections retrieved with this SQLContext should automatically refresh themselves when the DataEngine is used to update the database.
 boolean isAutoStartWOWConnection()
          Tests if WOW Connection retrieved with this SQLContext should automatically start itself when the DataEngine is used to run a WOW operation.
 boolean isBatch()
          Tests if this SQLContext should be executed in batch mode
 boolean isCacheResults()
          Tests if queries resulting from this SQLContext should be cached or not.
 boolean isCallStatement()
          Tests if the SQL for this SQLContext begins with "CALL "
 boolean isCheckCache()
          Tests if queries associated with this SQLContext should check the cache first, before going to the database.
 boolean isCheckFieldDataFileForFDs()
          Return whether or not to check the Field data file when retrieving FieldDescriptors for newly created Fields in each Row.
 boolean isDeleteStatement()
          Return whehter or not this context contains a delete statement.
 boolean isGroupByStatement()
          Check to see if this context's sql contains a group by.
 boolean isInsertStatement()
          Return whehter or not this context contains a select statement.
 boolean isMetaDataQuery()
          Return whether or not this context is a special MetaData query
protected  boolean isParameterTokenEnd(char c)
          Tests if the specified character signals the end of a parameter token
protected  boolean isQuery()
          Deprecated. replaced with isRowCollectionContext
 boolean isReadTotalRecords()
          Check whether or not to read the total number of records.
 boolean isResultSetRetained()
          This tells whether or not the result set for this context should be retained for future accesses.
 boolean isRowCollectionContext()
          Tests if executing this SQLContext will result in a RowCollection
 boolean isRunInBackground()
          Tests if SQL commands using this context should run in a background thread.
 boolean isSelectStatement()
          Return whether or not this context contains a select statement.
 boolean isSourceRowPresent()
          Tests if this SQLContext contains a source row
 boolean isSystemAliasSpecified()
          This tells whether or not the connection alias for this context is specified
 boolean isUnionStatement()
          Check to see if this context's sql contains a union.
protected  boolean isUpdate()
          Check to see if executeUpdate should be run on this context.
 boolean isUpdateStatement()
          Return whehter or not this context contains an update statement.
 boolean isUsePreparedStatement()
          Tests if statements run with this SQLContext should use prepared statements.
protected  boolean isVoid()
          Check to see if execute should be run on this context.
 void loadParameterRequestAndSessionValues()
          When this method is invoked, values are taken from request parameters, request attributes, and session attributes.
protected static int nextShift(int currentShift)
           
 void parameterAltered()
          Callback method so that parameters can inform their context when they are alerted
protected  java.lang.String prepareForExecution()
          This method is invoked just before the context's code is executed.
protected  java.lang.String rectifyCode(java.lang.String sql)
          Converts the SQL statement to mostly uppercase, replaces most slashes with periods, "normalizes" the spacing, and handles its named parameters and logical Fields.
protected static java.lang.String removeFieldDescriptorIds(java.lang.String sql)
          Strips out the FD ID's from the sql
 void removeListener(IDataEngineListener listener)
          Removes a listener from this SQLContext.
 void removeTable(Table pTable)
          Adds a table to this query.
 void returnConnection()
          Frees the connection, but only if this SQLContext orginally retrieved the connection.
 void setAssociatedJoinOperationPresent(boolean ajoin)
          Sets if the RC returned by this SQLContext has one or more columns whose FD's have an associated join operation.
 SQLContext setAutoRefresh(boolean newAutoRefresh)
          Sets if RowCollections retrieved with this SQLContext should automatically refresh themselves when the DataEngine is used to update the database.
 SQLContext setAutoStartWOWConnection(boolean newAutoStartWOWConnection)
          Sets if WOW Connection retrieved with this SQLContext should automatically start itself when the DataEngine is used to run a WOW operation.
 void setBatch(boolean newBatch)
          Sets if this SQLContext should be executed in batch mode
 SQLContext setCacheResults(boolean newResultsCached)
          Sets whether or not results from a query based on this context should be cached.
 SQLContext setCachingLevel(int newCachingLevel)
          Sets the current caching level, describing whether the cache should be checked, and whether results should be stored in the cache.
 SQLContext setCachingTimeMillis(long milliseconds)
          Sets the time in milliseconds the results from executing this context are to be cached.
 SQLContext setCheckCache(boolean newCacheChecked)
          Sets whether or not queries resulting from this SQLContext should check the cache first, or go directly to the database.
 SQLContext setCheckFieldDataFileForFDs(boolean pCheckFieldDataFileForFDs)
          Sets whether or not to check the Field data file when retrieving FieldDescriptors for newly created Fields in each Row.
 void setCode(java.lang.String code)
          Sets this context's code string.
 void setCode(java.lang.String code, boolean shadowize)
          Sets this context's code string.
 SQLContext setConnection(java.sql.Connection newConnection)
          Sets the connection for this SQLContext.
protected  void setConnectionInternal(java.sql.Connection newConnection)
          Sets the connection for this SQLContext.
 void setExecutionRule(int erule)
          Sets the execution rule for this context.
 SQLContext setFirstRowIndex(int newFirstRow)
          Insert the method's description here.
protected  SQLContext setKeyContext(SQLContext newKeyContext)
          Sets the SQLContext to be used as a key in the cache.
 void setParameterValue(int position, java.lang.Object value, int dataType)
          Provides a value to a parameter for this context's code string.
 void setReadTotalRecords(boolean readTotalRecords)
          Set whether or not to read in the total number of records the SQL can return
protected  void setRectifiedCode(java.lang.String newRectifiedCode)
          Sets the rectified code which has already been passed through the rectifyCode() method but has not had any metadata library alteration performed on it yet
 SQLContext setReportBreakCollection(PropertyGroupList pProperties)
          Sets the ReportBreakCollection defining the reports that will be generated in the RowCollection resulting from queries which use this SQLContext
 SQLContext setReportBreakCollection(ReportBreakCollection newReportBreakCollection)
          Sets the ReportBreakCollection defining the reports that will be generated in the RowCollection resulting from queries which use this SQLContext
 void setReRunCount(int reRunCount)
          Set the number of times this context was attempted to run.
 SQLContext setResultSetRetained(boolean value)
          Sets whether or not the result set for this context should be retained for future accesses.
 SQLContext setRowClass(java.lang.Class newRowClass)
          Sets the type of Row objects that will be included in the RowCollection resulting from the query.
 SQLContext setRowCollection(RowCollection newRowCollection)
          Sets the RowCollection object into which retrieved rows will be inserted.
 SQLContext setRowCollectionClass(java.lang.Class newRowCollectionClass)
          Sets the type of RowCollection that will contain this query's results.
 SQLContext setRowCount(int rows)
          Sets the number of rows to include in the RowCollection.
 SQLContext setRowCreator(IRowCreator newRowCreator)
          Sets the object used to create the Rows the query should return.
 void setRowValues(Row source, Row target)
          Provides values for all of this context's named parameters.
 SQLContext setRunInBackground(boolean newRunInBackground)
          Sets if SQL commands using this context should run in a background thread.
 void setSourceRow(Row newSourceRow)
          If this SQLContext is an update, insert, or delete statement which pertains to one specific row, then this method sets that row
 SQLContext setSQL(java.lang.String newSQL)
          Sets the sql statement for this query.
 SQLContext setSQL(java.lang.String newSQL, boolean shadowize)
          Sets the sql statement for this query.
protected  SQLContext setSQLInternal(java.lang.String newSQL)
          Deprecated. This method has a misleading name (JE 8/5/2004)
 SQLContext setSystemAlias(java.lang.String pAlias)
          Sets the system alias for the SQL operation.
 SQLContext setTables(java.util.List pTables)
          Deprecated. Pass in a TableCollection instead
 SQLContext setTables(TableCollection pTables)
          Sets the tables to this query.
 SQLContext setTitle(java.lang.String pTitle)
          Sets the title of this SQLContext, which will also be the title of any RowCollections retrieved via this SQLContext
 void setTotalRecords(int records)
          Sets the total number of records running the SQL can return
 void setUsageIdRow(Row row)
          Sets the row whose data should be used to replace literal usage id's in the SQL (indicated with a ##?)
 SQLContext setUsePreparedStatement(boolean usePS)
          Sets if statements run with this SQLContext should use prepared statements.
 void setUseWOWLibrary(short newWOWSystemLibrary)
          Sets which WOW library should be used to execute this context.
 java.lang.String toString()
          Gets a String representation of this context
 
Methods inherited from class planetj.dataengine.AbstractContext
appendParameters, clearParameterValues, createParameter, equals, getCode, getCreationSource, getDataTimestamp, getDisplayParameters, getExecutingContext, getFirstDisplayParameter, getFirstParameterForInput, getNavigationKey, getNavigationListKey, getOriginalCode, getParameter, getParameter, getParameterCollection, getParameterCount, getParameterCount, getParameterDisplayFields, getParameterDisplayFields, getParameterRow, getParameters, getParameters, getParameterSource, getParameterValidationExceptions, getParameterValuesType, getPrimaryContext, getPropertyGroup, getPropertyGroups, getRowParameters, handleParameter, isCloneNeeded, isContainsDisplayParameters, isContainsParameters, isLocked, isParameterized, isParameterTokenEnd, isRefreshing, isSecondaryContext, loadGlobalValues, loadSQLTextReplacementValues, loadUserAndExecutingContextValues, lock, removeNavigationKey, setCodeInternal, setCreationSource, setDataTimestamp, setExecutingContext, setNavigationKey, setParameterCollection, setParameterDisplayValues, setParameterValue, setParameterValue, setParameterValues, setParameterValues, setParameterValuesType, setPrimaryContext, setRefreshing
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CACHING_NONE

public static final int CACHING_NONE
This SQLContext should not use caching

See Also:
Constant Field Values

CACHING_CHECK

public static final int CACHING_CHECK
This SQLContext should check the cache instead of going to the DB if possible, but any results retrieved from the DB should not be stored in the cache

See Also:
Constant Field Values

CACHING_STORE

public static final int CACHING_STORE
This SQLContext should not check the cache, but if possible should store any data retrieved from the DB in the cache

See Also:
Constant Field Values

CACHING_CHECK_AND_STORE

public static final int CACHING_CHECK_AND_STORE
This SQLContext should check the cache instead of going to the DB if possible, and should store any data from the DB in the cache if possible. This is the logical OR of the CACHING_CHECK and CACHING_STORE constants

See Also:
Constant Field Values

className

public static final java.lang.String className

ALL_ROWS

public static final int ALL_ROWS
See Also:
Constant Field Values

CACHE_EXPIRATION_TIME_NEVER

public static final int CACHE_EXPIRATION_TIME_NEVER
See Also:
Constant Field Values

CACHE_EXPIRATION_TIME_15_MINUTES

public static final int CACHE_EXPIRATION_TIME_15_MINUTES
See Also:
Constant Field Values

CACHE_EXPIRATION_TIME_30_MINUTES

public static final int CACHE_EXPIRATION_TIME_30_MINUTES
See Also:
Constant Field Values

CACHE_EXPIRATION_TIME_1_HOUR

public static final int CACHE_EXPIRATION_TIME_1_HOUR
See Also:
Constant Field Values

CACHE_EXPIRATION_TIME_1_DAY

public static final int CACHE_EXPIRATION_TIME_1_DAY
See Also:
Constant Field Values

CACHE_EXPIRATION_TIME_1_WEEK

public static final int CACHE_EXPIRATION_TIME_1_WEEK
See Also:
Constant Field Values

LIBRARY_SYSTEM

public static final short LIBRARY_SYSTEM
This statement is again the system library

See Also:
Constant Field Values

LIBRARY_USER

public static final short LIBRARY_USER
This statement is against the user library

See Also:
Constant Field Values

LIBRARY_UNKNOWN

public static final short LIBRARY_UNKNOWN
It is not known if this statement is against the user or system library. The DataEngine will decide

See Also:
Constant Field Values

LIBRARY_AS_SPECIFIED

public static final short LIBRARY_AS_SPECIFIED
This statment already has the libraries it is going against specified

See Also:
Constant Field Values
Constructor Detail

SQLContext

public SQLContext()
SQLContext constructor


SQLContext

public SQLContext(java.lang.String pSystemAlias)
SQLContext constructor

Parameters:
pSystemAlias - The system alias for this SQLContext

SQLContext

public SQLContext(java.lang.String pSystemAlias,
                  IUser user)
Deprecated. replaced with SQLContext(String, ExecutingContext)

SQLContext constructor

Parameters:
pSystemAlias - The system alias for this SQLContext

SQLContext

public SQLContext(java.lang.String pSystemAlias,
                  ExecutingContext ec)
SQLContext constructor

Parameters:
pSystemAlias - The system alias for this SQLContext
Method Detail

addListener

public void addListener(IDataEngineListener listener)
Adds a listener to this SQLContext. The listener will be informed when this SQLContext is used to run a SQL statement. Usually, listeners are used when the statement is being run in the background. If the statement is not run in the background, then the listeners are all informed of the result before the DataEngine method which caused the statement to run returns.


addTable

public void addTable(Table newTable)
Adds a table to this query. Use this method to indicate which tables are being accessed by this operation.


appendProperties

protected java.lang.StringBuffer appendProperties(java.lang.StringBuffer info)
Gets a String representation of this context. This method is called by the toString() method. If any subclass wishes to have certain properties displayed besides the code, they can override this method. Note: parameter values are also outputed from toString().

Overrides:
appendProperties in class AbstractContext

clear

public void clear()
           throws DataEngineException
Wipes out the info in this SQLContext, restoring the default values.

Overrides:
clear in class AbstractContext
Returns:
This object.
Throws:
DataEngineException

clearTables

public void clearTables()
Clears the tables to this query.


clone

public java.lang.Object clone()
Creates an unlocked copy of this SQLContext

Specified by:
clone in interface INavigationObject
Overrides:
clone in class AbstractContext

cloneContext

public SQLContext cloneContext()
Creates an unlocked copy of this SQLContext


cloneContext

public SQLContext cloneContext(boolean clearExecutingContext)
Creates an unlocked copy of this SQLContext


equals

public boolean equals(java.lang.Object o)

execute

public java.lang.Object execute()
                         throws CMException
Executes the SQL statement contained in this context and returns the results.

Specified by:
execute in class AbstractContext
Throws:
CMException

execute

public java.lang.Object execute(boolean informOperation)
                         throws CMException
Executes the SQL statement contained in this context and returns the results.

Throws:
CMException

finalize

protected void finalize()
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

getCachingLevel

public int getCachingLevel()
Gets the current caching level, describing whether the cache should be checked, and whether results should be stored in the cache. The default is CACHING_NONE.


getCachingTimeMillis

public long getCachingTimeMillis()
Gets the amount of time in milliseconds this context's results are to be cached.

Returns:
milliseconds results are cached

getConnection

public java.sql.Connection getConnection()
                                  throws DataEngineException
Gets theCconnection that should be used for queries which use thix QuerContext. If no Connection has been set then a new one is taken from the pool and returned. After the caller is done using the Connection, the returnConnection() method should be invoked to free the connection. Do NOT invoke the DataBaseManager.freeConnection() method directly, as the Connection may have been set in this object in another section of code, with the expectation that the Connection will still be useable.

Throws:
DataEngineException

getConnection

public java.sql.Connection getConnection(boolean pCreate)
                                  throws DataEngineException
Gets the connection that should be used for DataEngine operations which use this SQLContext

Parameters:
pCreate - If this is false and no connection exists, null is returned. If this is true and no Connection has been set then a new one is taken from the pool and returned. After the caller is done using the Connection, the returnConnection() method should be invoked to free the connection. Do NOT invoke the DataBaseManager.freeConnection() method directly, as the Connection may have been set in this object in another section of code, with the expectation that the Connection will still be useable.
Throws:
DataEngineException

getConnectionAlias

public java.lang.String getConnectionAlias()
Deprecated. Just use getSystemAlias() instead


getConnectionOwner

public java.lang.Object getConnectionOwner()
If the Connection contained in this object was created in this SQLContext, then this object is returned. Otherwise, null is returned.


getExecutionRule

public int getExecutionRule()
Gets the execution rule for this context. Constants are defined in IOperation


getFirstRowIndex

public int getFirstRowIndex()
Insert the method's description here. Creation date: (12/5/01 2:57:15 PM)

Returns:
int

getHashcode

protected static final int getHashcode(java.lang.Object o)

getKeyContext

public SQLContext getKeyContext()
                         throws DataEngineException
Gets the SQLContext to be used as a key in the cache. This is an internal method, and should only be invoked by the caching subsystem. The idea is to return either this same object, or a clone of this object depending on who the "owner" of this object is.

Throws:
DataEngineException

getListeners

protected java.util.List getListeners()
Gets the List of listeners.


getLogicalFieldNames

public java.util.List getLogicalFieldNames()
Gets a List of the names of logical Fields in this SQLContext. A logical Field is a field whose value is not a single value stored in the database, but is instead the result of some operation. To specify that a logical Field should be retrieved you must prefix its name with two exclaimation points in an SQL statement. For example, the SQL:
SELECT FNAME, LNAME, !!ORDERS FROM PLANETJ.CUSTOMERS
would select three fields from the CUSTOMERS table. The ORDERS field is an logical Field, FNAME and LNAME are physical database fields. The actual SQL sent to the database would not include the orders field.

Returns:
A List containing Field.FieldLocation objects specifying the names of the logical fields in this context (or an empty List if there are no logical fields).

getMetaDataAlias

public java.lang.String getMetaDataAlias()

getMode

public int getMode()
Gets a constant (such as Row.MODE_UPDATE or ROW.MODE_INSERT) describing the type of action this SQLContext is performing


getNumberOfTables

public int getNumberOfTables()
Gets the number of tables being queried.

Returns:
the number of tables being queried.

getParameterClass

protected java.lang.Class getParameterClass(java.lang.String parameterToken)
Returns the appropriate class for creating a parameter based on the parameter token. Subclasses may override this method if they wish, but the returned class must implement IParameter. Null is returned if there is no matching class

Overrides:
getParameterClass in class AbstractContext
Parameters:
parameterToken - The token such as "?", "??MY_COLUMN", or "???^22" which indicates what type of parameter should be created

getPropertyGroups

public PropertyGroupList getPropertyGroups()
Get all the property groups stored in this RowCollection's attributes.

Specified by:
getPropertyGroups in interface IContext
Specified by:
getPropertyGroups in class AbstractContext

getRectifiedCode

protected java.lang.String getRectifiedCode()
Gets the rectified code which has already been passed through the rectifyCode() method but has not had any metadata library alteration performed on it yet


getReRunCount

public int getReRunCount()
Get the number of times this context was attempted to run. Every time a context is run and an error occurs, the run count increases until it runs successful.


getReportBreakCollection

public ReportBreakCollection getReportBreakCollection()
Gets the ReportBreakCollection defining the reports that will be generated in the RowCollection resulting from queries which use this SQLContext


getRowClass

public java.lang.Class getRowClass()
Gets the type of Row objects that will be included in the RowCollection resulting from the query. If the Row type can't be determined until after the query has been run, set a Row creator instead of a Row class.

Returns:
The Class object for the rows in the query results.

getRowCollection

public RowCollection getRowCollection()
Gets the RowCollection object into which retrieved rows will be inserted. If this is null (which is the default) then a new RowCollection object is created to hold the rows.


getRowCollectionClass

public java.lang.Class getRowCollectionClass()
Gets the type of RowCollection that will contain this query's results.

Returns:
The Class object for the collection of rows in the query results.

getRowCount

public int getRowCount()
Gets the number of rows to add to the RowCollection. By default, all the rows are retrieved.


getRowCreator

public IRowCreator getRowCreator()
Gets the object used to create the Rows the query should return. By default this is blank, only change it if the type of Row that should be returned can't be determined until after the query has run.


getSafeSQL

public java.lang.String getSafeSQL()
Returns this context's SQL, with all single quotes, double quotes, and backslashes replaced with underscores


getSourceRow

public Row getSourceRow()
If this SQLContext is an update, insert, or delete statement which pertains to one specific row, then this method gets that row. Otherwise null is returned.


getSQL

public java.lang.String getSQL()
Gets this SQLContext's SQL String.


getSQLDeleteStatement

public DeleteStatement getSQLDeleteStatement()
Get the context's current delete statement. If the context's SQLStatement is not a delete statement, null is returned.


getSQLInsertStatement

public InsertStatement getSQLInsertStatement()
Get the context's current insert statement. If the context's SQLStatement is not an insert statement, null is returned.


getSQLParameters

public java.util.Iterator getSQLParameters()
Returns an iteration of all the ISQLParameters in this context. The Iterator cannot not be altered.


getSQLSelectStatement

public SelectStatement getSQLSelectStatement()
Get the context's current select statement. If the context's SQLStatement is not a select statement, null is returned.


getSQLStatement

public SQLStatement getSQLStatement()
Gets the SQL Statement object for this SQLContext


getSQLUpdateStatement

public UpdateStatement getSQLUpdateStatement()
Get the context's current update statement. If the context's SQLStatement is not a update statement, null is returned.


getSystemAlias

public java.lang.String getSystemAlias()
Gets the system alias for the SQL operation.


getTable

public Table getTable()
Gets the table which is being queried.

Returns:
A table which is being queried. If there is more than one such table, there is no guarantee which table will be returned.

getTable

public Table getTable(int pTableIndex)
Gets the table being queried with the given index.

Returns:
A table which is being queried.

getTables

public TableCollection getTables()
Gets the tables being queried.

Returns:
A list of tables being queried.

getTimestamp

public long getTimestamp()
Gets when this SQLContext was last run


getTitle

public java.lang.String getTitle()
Gets the title of this SQLContext, which will also be the title of any RowCollections retrieved via this SQLContext


getTotalRecords

public int getTotalRecords()
Get the total number or records possible from running SQL. This value is set when this context is first run, and may not reflect the lastest DB changes


getTotalRecordsFromDB

public int getTotalRecordsFromDB()
                          throws CMException
Runs a separate query against the DB to determine the total number of records which match the query in this context

Returns:
The total number of records in the DB which match this query, or -1 if this context's SQL was too complex to perform the query
Throws:
CMException

getUsageIdRow

public Row getUsageIdRow()
Gets the row whose data should be used to replace literal usage id's in the SQL (indicated with a ##?)


getUseWOWLibrary

public short getUseWOWLibrary()
Tests which WOW library should be used to execute this context. The value is one of the constants defined in this class


hashCode

public int hashCode()

hashCode

protected static final int hashCode(java.util.List l)
Gets the hashCode of a List. Null Lists are assumed to have a hashCode of 0


hasListeners

public boolean hasListeners()
Tests if there are any objects listening to this SQLContext.


initializeAndStore

protected void initializeAndStore(IParameter param,
                                  java.lang.String parameterToken)
                           throws CMException
Initializes and stores the parameter in this context

Overrides:
initializeAndStore in class AbstractContext
Throws:
CMException

isAlterTableStatement

public boolean isAlterTableStatement()
Check if this context contains an alter table statement.

Returns:
true if this context contains an alter table statement; false otherwise.

isAssociatedJoinOperationPresent

public boolean isAssociatedJoinOperationPresent()
Tests if the RC returned by this SQLContext has one or more columns whose FD's have an associated join operation


isAutoRefresh

public boolean isAutoRefresh()
Tests if RowCollections retrieved with this SQLContext should automatically refresh themselves when the DataEngine is used to update the database. This property is true by default. Currently this refresh occurs only before the RowCollection is displayed to the user.


isAutoStartWOWConnection

public boolean isAutoStartWOWConnection()
Tests if WOW Connection retrieved with this SQLContext should automatically start itself when the DataEngine is used to run a WOW operation. This property is true by default.


isBatch

public boolean isBatch()
Tests if this SQLContext should be executed in batch mode


isCacheResults

public boolean isCacheResults()
Tests if queries resulting from this SQLContext should be cached or not. The default is false.


isCallStatement

public boolean isCallStatement()
Tests if the SQL for this SQLContext begins with "CALL "


isCheckCache

public boolean isCheckCache()
Tests if queries associated with this SQLContext should check the cache first, before going to the database. The default is false.


isCheckFieldDataFileForFDs

public boolean isCheckFieldDataFileForFDs()
Return whether or not to check the Field data file when retrieving FieldDescriptors for newly created Fields in each Row.

Returns:
boolean.

isDeleteStatement

public boolean isDeleteStatement()
Return whehter or not this context contains a delete statement.

Returns:
boolean

isGroupByStatement

public boolean isGroupByStatement()
Check to see if this context's sql contains a group by.

Returns:
boolean

isInsertStatement

public boolean isInsertStatement()
Return whehter or not this context contains a select statement.

Returns:
boolean

isParameterTokenEnd

protected boolean isParameterTokenEnd(char c)
Tests if the specified character signals the end of a parameter token

Specified by:
isParameterTokenEnd in class AbstractContext

isQuery

protected boolean isQuery()
Deprecated. replaced with isRowCollectionContext

Check to see if executeQuery should be run on this context.


isReadTotalRecords

public boolean isReadTotalRecords()
Check whether or not to read the total number of records.


isResultSetRetained

public boolean isResultSetRetained()
This tells whether or not the result set for this context should be retained for future accesses.

Returns:
boolean

isRowCollectionContext

public boolean isRowCollectionContext()
Tests if executing this SQLContext will result in a RowCollection


isRunInBackground

public boolean isRunInBackground()
Tests if SQL commands using this context should run in a background thread. If a query is set to run in the background, then all of the DataEngine.getRows() methods will return null immediately, and run the query in the background. Any of this SQLContext's listeners will be informed when the query has completed.

The DataEngine.update() methods work in a similar fashion.


isSelectStatement

public boolean isSelectStatement()
Return whether or not this context contains a select statement.

Returns:
boolean

isMetaDataQuery

public boolean isMetaDataQuery()
Return whether or not this context is a special MetaData query

Returns:
boolean

isSourceRowPresent

public boolean isSourceRowPresent()
Tests if this SQLContext contains a source row


isSystemAliasSpecified

public boolean isSystemAliasSpecified()
This tells whether or not the connection alias for this context is specified

Returns:
boolean

isUnionStatement

public boolean isUnionStatement()
Check to see if this context's sql contains a union.

Returns:
boolean

isUpdate

protected boolean isUpdate()
Check to see if executeUpdate should be run on this context.


isUpdateStatement

public boolean isUpdateStatement()
Return whehter or not this context contains an update statement.

Returns:
boolean

isUsePreparedStatement

public boolean isUsePreparedStatement()
Tests if statements run with this SQLContext should use prepared statements.


isVoid

protected boolean isVoid()
Check to see if execute should be run on this context.


loadParameterRequestAndSessionValues

public void loadParameterRequestAndSessionValues()
                                          throws DataEngineException
When this method is invoked, values are taken from request parameters, request attributes, and session attributes.

Overrides:
loadParameterRequestAndSessionValues in class AbstractContext
Throws:
DataEngineException

nextShift

protected static final int nextShift(int currentShift)

parameterAltered

public void parameterAltered()
                      throws DataEngineException
Callback method so that parameters can inform their context when they are alerted

Specified by:
parameterAltered in interface IContext
Overrides:
parameterAltered in class AbstractContext
Throws:
DataEngineException

prepareForExecution

protected java.lang.String prepareForExecution()
                                        throws DataEngineException
This method is invoked just before the context's code is executed.

Overrides:
prepareForExecution in class AbstractContext
Returns:
This operation's code, after parameters have been replaced with their values
Throws:
DataEngineException

rectifyCode

protected final java.lang.String rectifyCode(java.lang.String sql)
Converts the SQL statement to mostly uppercase, replaces most slashes with periods, "normalizes" the spacing, and handles its named parameters and logical Fields. (Portions of the SQL contained in quotes aren't altered.)

Specified by:
rectifyCode in class AbstractContext

removeFieldDescriptorIds

protected static java.lang.String removeFieldDescriptorIds(java.lang.String sql)
Strips out the FD ID's from the sql


removeListener

public void removeListener(IDataEngineListener listener)
Removes a listener from this SQLContext. If the listener hasn't been added to this SQLContext, nothing happens.


removeTable

public void removeTable(Table pTable)
Adds a table to this query. Use this method to indicate which tables are being accessed by this operation.


returnConnection

public void returnConnection()
                      throws DataEngineException
Frees the connection, but only if this SQLContext orginally retrieved the connection. If the setConntection() method was explicitly invoked, then it is the invoker's responsibility to return the connection to the pool, and this method does nothing.

Throws:
DataEngineException

setAssociatedJoinOperationPresent

public void setAssociatedJoinOperationPresent(boolean ajoin)
Sets if the RC returned by this SQLContext has one or more columns whose FD's have an associated join operation. Normally this value is determined by the dataengine automatically, but you can use this method to override the default behavior.


setAutoRefresh

public SQLContext setAutoRefresh(boolean newAutoRefresh)
Sets if RowCollections retrieved with this SQLContext should automatically refresh themselves when the DataEngine is used to update the database. This is true by default. Currently this refresh occurs only before the RowCollection is displayed to the user.


setAutoStartWOWConnection

public SQLContext setAutoStartWOWConnection(boolean newAutoStartWOWConnection)
Sets if WOW Connection retrieved with this SQLContext should automatically start itself when the DataEngine is used to run a WOW operation. This property is true by default.


setBatch

public void setBatch(boolean newBatch)
Sets if this SQLContext should be executed in batch mode


setCacheResults

public SQLContext setCacheResults(boolean newResultsCached)
Sets whether or not results from a query based on this context should be cached. The default is false. Using the cache will improve performance, but may give you stale data if the data you are retrieving is frequently updated.


setCachingLevel

public SQLContext setCachingLevel(int newCachingLevel)
Sets the current caching level, describing whether the cache should be checked, and whether results should be stored in the cache. The default is CACHING_NONE.


setCachingTimeMillis

public SQLContext setCachingTimeMillis(long milliseconds)
Sets the time in milliseconds the results from executing this context are to be cached.


setCheckCache

public SQLContext setCheckCache(boolean newCacheChecked)
Sets whether or not queries resulting from this SQLContext should check the cache first, or go directly to the database. The default is not to check the cache. Using the cache will improve performance, but may give you stale data if the data you are retrieving is frequently updated.


setCheckFieldDataFileForFDs

public SQLContext setCheckFieldDataFileForFDs(boolean pCheckFieldDataFileForFDs)
Sets whether or not to check the Field data file when retrieving FieldDescriptors for newly created Fields in each Row.

Parameters:
pCheckFieldDataFileForFDs - boolean.

setCode

public void setCode(java.lang.String code)
Sets this context's code string.

Overrides:
setCode in class AbstractContext

setCode

public void setCode(java.lang.String code,
                    boolean shadowize)
Sets this context's code string.

Overrides:
setCode in class AbstractContext

setConnection

public SQLContext setConnection(java.sql.Connection newConnection)
                         throws DataEngineException
Sets the connection for this SQLContext. Note that you are still responsible for returning this connection to the pool when you are through with it.

Parameters:
newConnection - The connection object for this SQL context
Returns:
this object
Throws:
Thrown - if there is a problem converting the connection to a DataEngineConnection. If you pass in a DataEngineConnection, or null you don't have to worry about an exception being thrown.
DataEngineException

setConnectionInternal

protected void setConnectionInternal(java.sql.Connection newConnection)
Sets the connection for this SQLContext.


setExecutionRule

public void setExecutionRule(int erule)
Sets the execution rule for this context. Constants are defined in IOperation


setFirstRowIndex

public SQLContext setFirstRowIndex(int newFirstRow)
Insert the method's description here. Creation date: (12/5/01 2:57:15 PM)

Parameters:
newFirstRow - int

setKeyContext

protected SQLContext setKeyContext(SQLContext newKeyContext)
Sets the SQLContext to be used as a key in the cache. This is an internal method, and should only be invoked by the caching subsystem. The idea is to set the key context to either this same object, or a clone of this object depending on who the "owner" of this object is.


setParameterValue

public final void setParameterValue(int position,
                                    java.lang.Object value,
                                    int dataType)
                             throws CMException
Provides a value to a parameter for this context's code string. (If this context does not use parameters, then this method is irrelevant.) The object you pass in will be mapped to its proper data type.

Parameters:
position - The index of the parameter whose value is being supplied. The first parameter is 0, the second is 1, etc.
value - The value to give to the parameter. This value may be null. After the value is passed to this method it must never be changed. If it is possible for this value to change, you should clone it and pass a clone which will not change to this method.
dataType - The data type for the parameter whose value is being supplied.
Throws:
CMException

setReadTotalRecords

public void setReadTotalRecords(boolean readTotalRecords)
Set whether or not to read in the total number of records the SQL can return


setRectifiedCode

protected void setRectifiedCode(java.lang.String newRectifiedCode)
Sets the rectified code which has already been passed through the rectifyCode() method but has not had any metadata library alteration performed on it yet


setReportBreakCollection

public SQLContext setReportBreakCollection(ReportBreakCollection newReportBreakCollection)
Sets the ReportBreakCollection defining the reports that will be generated in the RowCollection resulting from queries which use this SQLContext


setReportBreakCollection

public SQLContext setReportBreakCollection(PropertyGroupList pProperties)
                                    throws DataEngineException
Sets the ReportBreakCollection defining the reports that will be generated in the RowCollection resulting from queries which use this SQLContext

Parameters:
pProperties - A PropertyGroupList containing properties which specify a ReportBreakCollection
Throws:
DataEngineException

setResultSetRetained

public SQLContext setResultSetRetained(boolean value)
Sets whether or not the result set for this context should be retained for future accesses.

Parameters:
value - boolean If true, the result set will be retained in the row collection for future access. We will also turn all caching for this context off. If false, the row collection will not be retained.
Returns:
planetj.database.SQLContext

setRowClass

public SQLContext setRowClass(java.lang.Class newRowClass)
Sets the type of Row objects that will be included in the RowCollection resulting from the query. If the Row type can't be determined until after the query has been run, set a Row creator instead of a Row class.

Parameters:
newRowClass - The type of Row objects that will be returned in the result. This class must be a subclass of planetj.database.Row. Do not pass an abstract class.

setRowCollection

public SQLContext setRowCollection(RowCollection newRowCollection)
Sets the RowCollection object into which retrieved rows will be inserted. If this is null (which is the default) then a new RowCollection object is created to hold the rows.


setRowCollectionClass

public SQLContext setRowCollectionClass(java.lang.Class newRowCollectionClass)
Sets the type of RowCollection that will contain this query's results.

Parameters:
newRowCollectionClass - The Class object for the collection of rows in the query results. This class must be a subclass of the RowCollection class.

setRowCount

public SQLContext setRowCount(int rows)
Sets the number of rows to include in the RowCollection. By default, all the rows are retrieved.


setRowCreator

public SQLContext setRowCreator(IRowCreator newRowCreator)
Sets the object used to create the Rows the query should return. By default this is blank, only change it if the type of Row that should be returned can't be determined until after the query has run.


setRowValues

public void setRowValues(Row source,
                         Row target)
                  throws CMException
Provides values for all of this context's named parameters. For each named parameter, if the source Row contains a field with the same name, then the Field's value is used to set the parameter comparison's proper field in the target Row. Unnamed parameters are ignored.

Throws:
CMException

setReRunCount

public void setReRunCount(int reRunCount)
Set the number of times this context was attempted to run. Every time a context is run and an error occurs, the run count increases until it runs successful.


setRunInBackground

public SQLContext setRunInBackground(boolean newRunInBackground)
Sets if SQL commands using this context should run in a background thread. If a query is set to run in the background, then all of the DataEngine.getRows() methods will return null immediately, and run the query in the background. Any listeners will be informed when the query has completed.

The DataEngine.update() methods work in a similar fashion.


setSourceRow

public void setSourceRow(Row newSourceRow)
If this SQLContext is an update, insert, or delete statement which pertains to one specific row, then this method sets that row


setSQL

public SQLContext setSQL(java.lang.String newSQL)
Sets the sql statement for this query.


setSQL

public SQLContext setSQL(java.lang.String newSQL,
                         boolean shadowize)
Sets the sql statement for this query.


setSQLInternal

protected SQLContext setSQLInternal(java.lang.String newSQL)
Deprecated. This method has a misleading name (JE 8/5/2004)

Sets the sql statement for this query.


setSystemAlias

public SQLContext setSystemAlias(java.lang.String pAlias)
Sets the system alias for the SQL operation. You don't need to set this if you set either the table or the statement instead.


setTables

public SQLContext setTables(java.util.List pTables)
Deprecated. Pass in a TableCollection instead

Sets the tables to this query. Use this method to indicate which tables are being accessed by this operation.


setTables

public SQLContext setTables(TableCollection pTables)
Sets the tables to this query. Use this method to indicate which tables are being accessed by this operation.


setTitle

public SQLContext setTitle(java.lang.String pTitle)
Sets the title of this SQLContext, which will also be the title of any RowCollections retrieved via this SQLContext


setTotalRecords

public void setTotalRecords(int records)
Sets the total number of records running the SQL can return


setUsageIdRow

public void setUsageIdRow(Row row)
Sets the row whose data should be used to replace literal usage id's in the SQL (indicated with a ##?)


setUsePreparedStatement

public SQLContext setUsePreparedStatement(boolean usePS)
Sets if statements run with this SQLContext should use prepared statements.


setUseWOWLibrary

public void setUseWOWLibrary(short newWOWSystemLibrary)
Sets which WOW library should be used to execute this context. The value is one of the constants defined in this class.


toString

public java.lang.String toString()
Gets a String representation of this context

Overrides:
toString in class AbstractContext