com.metamatrix.jdbc
Class MMStatement

java.lang.Object
  extended by com.metamatrix.jdbc.WrapperImpl
      extended by com.metamatrix.jdbc.MMStatement
All Implemented Interfaces:
java.sql.Statement, java.sql.Wrapper
Direct Known Subclasses:
MMPreparedStatement

public class MMStatement
extends WrapperImpl
implements Statement

This object is used to execute queries and updates against the MetaMatrix server. This object submits queries to MetaMatrix server by sending request messages. The query execution gives a MMXResultSet object that can be used to navigate the results. An update can be executed to return the number of rows affected. The MMXStatement object can be used by multiple threads, the MMXResultSet objects for each object is added to a hashtable so that we could have a ResultSet object open for each executing thread. When the statement object is closed all the ResultSet objects on any given statement are closed.


Field Summary
protected static int CANCELLED
           
protected  int commandStatus
           
protected  long currentRequestID
           
protected static int NO_TIMEOUT
           
protected  java.util.Map outParamIndexMap
           
protected  int queryTimeout
           
protected  MMResultSet resultSet
           
protected static int TIMED_OUT
           
protected  int[] updateCounts
          Array of update counts as returned by executeBatch()
 
Fields inherited from interface java.sql.Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO
 
Method Summary
protected  void accumulateWarnings(java.util.List<java.lang.Exception> serverWarnings)
           
 void addBatch(java.lang.String sql)
          Adds sql to this statement object's current list of commands.
 void attachStylesheet(java.io.Reader reader)
           This method sets a style sheet to this object.
 void cancel()
          This method can be used by one thread to cancel a statement that is being executed by another thread.
protected  void cancelRequest()
           
protected  void checkStatement()
           This utility method checks if the jdbc statement is closed and throws an exception if it is closed.
 void clearBatch()
          Makes the set of commands in the current batch empty.
 void clearStylesheet()
           This method removes any existing style sheet on this object.
 void clearWarnings()
          Warning could be schema validation errors or partial results warnings.
 void close()
          In many cases, it is desirable to immediately release a Statements's database and JDBC resources instead of waiting for this to happen when it is automatically closed; the close method provides this immediate release.
protected  void copyPropertiesToRequest(RequestMessage res, java.util.Properties props)
          Helper method for copy the connection properties to request message.
protected  RequestMessage createRequestMessage(java.lang.String[] commands, boolean isBatchedCommand, java.lang.Boolean requiresResultSet)
           
protected  void createResultSet(ResultsMessage resultsMsg)
           
 boolean execute(java.lang.String sql)
           
 boolean execute(java.lang.String sql, int autoGeneratedKeys)
           
 boolean execute(java.lang.String sql, int[] columnIndexes)
           
 boolean execute(java.lang.String sql, java.lang.String[] columnNames)
           
 int[] executeBatch()
           
 java.sql.ResultSet executeQuery(java.lang.String sql)
           
protected  void executeSql(java.lang.String[] commands, boolean isBatchedCommand, java.lang.Boolean requiresResultSet)
           
 int executeUpdate(java.lang.String sql)
           
 int executeUpdate(java.lang.String sql, int autoGeneratedKeys)
           
 int executeUpdate(java.lang.String sql, int[] columnIndexes)
           
 int executeUpdate(java.lang.String sql, java.lang.String[] columnNames)
           
 java.util.Collection getAnnotations()
          Get annotations
 java.sql.Connection getConnection()
           
protected  java.util.Properties getConnectionProperties()
           
 java.lang.String getDebugLog()
          Get query planner debug log.
protected  ClientSideDQP getDQP()
           
 java.lang.String getExecutionProperty(java.lang.String name)
          Get the MetaMatrix-specific execution property value.
 int getFetchDirection()
          Retreives the fetch direction this Statement object set as a performance hint to the driver.
 int getFetchSize()
          Retreives the fetch size this Statement object set as a performance hint to the driver.
 java.sql.ResultSet getGeneratedKeys()
           
 int getMaxFieldSize()
          Retreives the maximum number of bytes that a result set column may contain.
 int getMaxRows()
          Retrives the maximum number of rows that a ResultSet object may contain.
protected  MMConnection getMMConnection()
           
 boolean getMoreResults()
          Moves to this Statement object's next result, returns true if it is a ResultSet object, and implicitly closes any current ResultSet object(s) obtained with the method #getResultSet.
 boolean getMoreResults(int current)
          Moves to this Statement object's next result, deals with any current ResultSet object(s) according to the instructions specified by the given flag, and returns true if the next result is a ResultSet object.
 PlanNode getPlanDescription()
          Get Query plan description.
 int getQueryTimeout()
          Return the number of seconds the driver will wait for a statement object to execute
 java.lang.String getRequestIdentifier()
          Get ID for last execution which can be used for matching up executions on the client side with executions in the server logs and MetaMatrix console.
 java.sql.ResultSet getResultSet()
          Returns a ResultSet object that was produced by a call to the method execute.
 int getResultSetConcurrency()
          Retrieves the concurrency mode for the ResultSet objects generated from queries that this Statement object executes.
 int getResultSetHoldability()
           
 int getResultSetType()
          Retrieves the type of the ResultSet objects generated from queries that this statement executes.
protected  java.util.TimeZone getServerTimeZone()
           
 int getUpdateCount()
          This method returns the number of rows affected by a statement modifying a table.
 java.sql.SQLWarning getWarnings()
          This method returns warnings returned by server.
protected  boolean hasResultSet()
           
 boolean isClosed()
          Check is the statement is closed.
 boolean isPoolable()
           
protected  void resetExecutionState()
          Reset all per-execution state - this should be done before executing a new command.
protected  ResultsMessage sendRequestMessageAndWait(RequestMessage reqMsg)
          Send out request message with necessary states.
protected  void setAnalysisInfo(ResultsMessage resultsMsg)
           
 void setCursorName(java.lang.String name)
           
 void setEscapeProcessing(boolean enable)
          This method enbles/disables escape processing.
 void setExecutionProperty(java.lang.String name, java.lang.String value)
          Set the MetaMatrix-specific execution property value.
 void setFetchDirection(int direction)
          This sets the fetch direction that this Statement object's hint to MetaMatrix to improve performance.
 void setFetchSize(int rows)
          This sets the fetch size that this Statement object's hint to MetaMatrix for improving performance.
 void setMaxFieldSize(int max)
           
 void setMaxRows(int maxRows)
          Sets the limit on the maximum number of rows in a ResultSet object.
 void setPartialResults(boolean isPartialResults)
           
 void setPayload(java.io.Serializable payload)
          Set the per-statement security payload.
 void setPoolable(boolean arg0)
           
 void setQueryTimeout(int seconds)
          This sets to seconds the time limit for the number of seconds for a driver to wait for a statement object to be executed.
protected  void timeoutOccurred()
          Ends the command and sets the status to TIMED_OUT.
 
Methods inherited from class com.metamatrix.jdbc.WrapperImpl
isWrapperFor, unwrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
 

Field Detail

TIMED_OUT

protected static final int TIMED_OUT
See Also:
Constant Field Values

CANCELLED

protected static final int CANCELLED
See Also:
Constant Field Values

NO_TIMEOUT

protected static final int NO_TIMEOUT
See Also:
Constant Field Values

commandStatus

protected int commandStatus

queryTimeout

protected int queryTimeout

currentRequestID

protected long currentRequestID

resultSet

protected MMResultSet resultSet

updateCounts

protected int[] updateCounts
Array of update counts as returned by executeBatch()


outParamIndexMap

protected java.util.Map outParamIndexMap
Method Detail

getDQP

protected ClientSideDQP getDQP()

getMMConnection

protected MMConnection getMMConnection()

getServerTimeZone

protected java.util.TimeZone getServerTimeZone()
                                        throws java.sql.SQLException
Throws:
java.sql.SQLException

resetExecutionState

protected void resetExecutionState()
                            throws java.sql.SQLException
Reset all per-execution state - this should be done before executing a new command.

Throws:
java.sql.SQLException

addBatch

public void addBatch(java.lang.String sql)
              throws java.sql.SQLException
Adds sql to this statement object's current list of commands.

Specified by:
addBatch in interface java.sql.Statement
Parameters:
sql - statement to be added to the batch
Throws:
java.sql.SQLException

cancel

public void cancel()
            throws java.sql.SQLException
This method can be used by one thread to cancel a statement that is being executed by another thread.

Specified by:
cancel in interface java.sql.Statement
Throws:
java.sql.SQLException - should never occur.

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Warning could be schema validation errors or partial results warnings.

Specified by:
clearWarnings in interface java.sql.Statement
Throws:
java.sql.SQLException - should never occur.

clearBatch

public void clearBatch()
                throws java.sql.SQLException
Makes the set of commands in the current batch empty.

Specified by:
clearBatch in interface java.sql.Statement
Throws:
java.sql.SQLException - if a database access error occurs or the driver does not support batch statements

close

public void close()
           throws java.sql.SQLException
In many cases, it is desirable to immediately release a Statements's database and JDBC resources instead of waiting for this to happen when it is automatically closed; the close method provides this immediate release.

Specified by:
close in interface java.sql.Statement
Throws:
java.sql.SQLException - should never occur.

checkStatement

protected void checkStatement()
                       throws java.sql.SQLException

This utility method checks if the jdbc statement is closed and throws an exception if it is closed.

Throws:
java.sql.SQLException - if the statement object is closed.

execute

public boolean execute(java.lang.String sql)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement
Throws:
java.sql.SQLException

executeBatch

public int[] executeBatch()
                   throws java.sql.SQLException
Specified by:
executeBatch in interface java.sql.Statement
Throws:
java.sql.SQLException

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sql)
                                throws java.sql.SQLException
Specified by:
executeQuery in interface java.sql.Statement
Throws:
java.sql.SQLException

executeUpdate

public int executeUpdate(java.lang.String sql)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement
Throws:
java.sql.SQLException

hasResultSet

protected boolean hasResultSet()
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

createResultSet

protected void createResultSet(ResultsMessage resultsMsg)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

executeSql

protected void executeSql(java.lang.String[] commands,
                          boolean isBatchedCommand,
                          java.lang.Boolean requiresResultSet)
                   throws java.sql.SQLException,
                          MMSQLException
Throws:
java.sql.SQLException
MMSQLException

createRequestMessage

protected RequestMessage createRequestMessage(java.lang.String[] commands,
                                              boolean isBatchedCommand,
                                              java.lang.Boolean requiresResultSet)
                                       throws MMSQLException
Throws:
MMSQLException

getFetchDirection

public int getFetchDirection()
                      throws java.sql.SQLException
Retreives the fetch direction this Statement object set as a performance hint to the driver. The int returned will be one of the following constants from the ResultSet interface: FETCH_FORWARD, FETCH_REVERSE, or FETCH_UNKNOWN.

Specified by:
getFetchDirection in interface java.sql.Statement
Returns:
int value indicating the direction in which results need to be fetched
Throws:
java.sql.SQLException - should never occur.

getFetchSize

public int getFetchSize()
                 throws java.sql.SQLException
Retreives the fetch size this Statement object set as a performance hint to the driver. This is the number of rows the server fetches at a time when the result set needs more rows.

Specified by:
getFetchSize in interface java.sql.Statement
Returns:
int value indicating the number of rows the server fetches
Throws:
java.sql.SQLException - should never occur.

getMaxFieldSize

public int getMaxFieldSize()
                    throws java.sql.SQLException
Retreives the maximum number of bytes that a result set column may contain.

Specified by:
getMaxFieldSize in interface java.sql.Statement
Returns:
int value giving the maximum size of a field
Throws:
java.sql.SQLException - should never occur.

getMaxRows

public int getMaxRows()
               throws java.sql.SQLException
Retrives the maximum number of rows that a ResultSet object may contain. If the limit is exceeded the excess rows are dropped.

Specified by:
getMaxRows in interface java.sql.Statement
Returns:
Max limit on rows on ResultSet.
Throws:
java.sql.SQLException - should never iccure.

getMoreResults

public boolean getMoreResults()
                       throws java.sql.SQLException
Moves to this Statement object's next result, returns true if it is a ResultSet object, and implicitly closes any current ResultSet object(s) obtained with the method #getResultSet.

Specified by:
getMoreResults in interface java.sql.Statement
Returns:
true if the next result is a ResultSet object; false if it is an update count or there are no more results
Throws:
java.sql.SQLException - if there is an error in database.

getMoreResults

public boolean getMoreResults(int current)
                       throws java.sql.SQLException
Moves to this Statement object's next result, deals with any current ResultSet object(s) according to the instructions specified by the given flag, and returns true if the next result is a ResultSet object.

Specified by:
getMoreResults in interface java.sql.Statement
Parameters:
current - flag that gives instruction on what should happen to current ResultSet objects obtained using the method getResultSet( CLOSE_CURRENT_RESULT, KEEP_CURRENT_RESULT, or CLOSE_ALL_RESULTS).
Returns:
true if the next result is a ResultSet object; false if it is an update count or there are no more results
Throws:
java.sql.SQLException - if there is an error in database.

getQueryTimeout

public int getQueryTimeout()
                    throws java.sql.SQLException
Return the number of seconds the driver will wait for a statement object to execute

Specified by:
getQueryTimeout in interface java.sql.Statement
Returns:
int value giving the query timeout in seconds
Throws:
java.sql.SQLException - should never occur

getResultSet

public java.sql.ResultSet getResultSet()
                                throws java.sql.SQLException
Returns a ResultSet object that was produced by a call to the method execute. We currently do not support execute method which could return multiple result sets.

Specified by:
getResultSet in interface java.sql.Statement
Returns:
ResultSet object giving the next available ResultSet
Throws:
java.sql.SQLException - should never occur

getResultSetConcurrency

public int getResultSetConcurrency()
                            throws java.sql.SQLException
Retrieves the concurrency mode for the ResultSet objects generated from queries that this Statement object executes. All ResultSets are currently read only.

Specified by:
getResultSetConcurrency in interface java.sql.Statement
Returns:
intvalue giving the ResultSet concurrency
Throws:
java.sql.SQLException - should never occur

getResultSetType

public int getResultSetType()
Retrieves the type of the ResultSet objects generated from queries that this statement executes.

Specified by:
getResultSetType in interface java.sql.Statement
Returns:
int value indicating the type of the ResultSet
Throws:
java.sql.SQLException - should never occur

getUpdateCount

public int getUpdateCount()
                   throws java.sql.SQLException
This method returns the number of rows affected by a statement modifying a table.

Specified by:
getUpdateCount in interface java.sql.Statement
Returns:
Number of rows affected.
Throws:
java.sql.SQLException - should never occur

accumulateWarnings

protected void accumulateWarnings(java.util.List<java.lang.Exception> serverWarnings)

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
This method returns warnings returned by server.

Specified by:
getWarnings in interface java.sql.Statement
Returns:
null value as there are no warnings
Throws:
java.sql.SQLException - should never occur

setEscapeProcessing

public void setEscapeProcessing(boolean enable)
                         throws java.sql.SQLException
This method enbles/disables escape processing. When escape processing is enabled the driver will scan any escape syntax and do escape substitution before sending the escaped sql statement to the server

Specified by:
setEscapeProcessing in interface java.sql.Statement
Parameters:
enable - boolean value indicating if the escape processing should be turned on
Throws:
java.sql.SQLException - should never occur

setFetchDirection

public void setFetchDirection(int direction)
                       throws java.sql.SQLException
This sets the fetch direction that this Statement object's hint to MetaMatrix to improve performance.

Specified by:
setFetchDirection in interface java.sql.Statement
Parameters:
direction - value indicating the direction in which results need to be fetched.
Throws:
java.sql.SQLException - as this method is not currently supported

setFetchSize

public void setFetchSize(int rows)
                  throws java.sql.SQLException
This sets the fetch size that this Statement object's hint to MetaMatrix for improving performance.

Specified by:
setFetchSize in interface java.sql.Statement
Parameters:
rows - Number of rows to fetch at a time
Throws:
java.sql.SQLException - If an invalid fetch size is set.

setMaxRows

public void setMaxRows(int maxRows)
                throws java.sql.SQLException
Sets the limit on the maximum number of rows in a ResultSet object. This method is currently implemented to throw an exception as it is not possible to limit the number of rows.

Specified by:
setMaxRows in interface java.sql.Statement
Parameters:
maxRows - int value indicating maximum rows that can be returned in a ResultSet
Throws:
java.sql.SQLException

setQueryTimeout

public void setQueryTimeout(int seconds)
                     throws java.sql.SQLException
This sets to seconds the time limit for the number of seconds for a driver to wait for a statement object to be executed.

Specified by:
setQueryTimeout in interface java.sql.Statement
Parameters:
seconds - Maximum number of seconds for a statement object to execute. throws SQLException, should never occur
Throws:
java.sql.SQLException

getConnectionProperties

protected java.util.Properties getConnectionProperties()

copyPropertiesToRequest

protected void copyPropertiesToRequest(RequestMessage res,
                                       java.util.Properties props)
                                throws MMSQLException
Helper method for copy the connection properties to request message.

Parameters:
res - Request message that these properties to be copied to.
props - Connection properties.
Throws:
MMSQLException

timeoutOccurred

protected void timeoutOccurred()
Ends the command and sets the status to TIMED_OUT.


cancelRequest

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

setPayload

public void setPayload(java.io.Serializable payload)
Set the per-statement security payload. This optional payload will accompany each request to the data source(s) so that the connector will have access to it.
Once the payload is set, it will be used for each statment execution until it is set to null, a new payload is set on the statement or the statement is closed.

To remove an existing payload from a statement, call this method with a null argument.

Parameters:
payload - The payload that is to accompany requests executed from this statement.
Since:
4.2

setExecutionProperty

public void setExecutionProperty(java.lang.String name,
                                 java.lang.String value)
Description copied from interface: Statement
Set the MetaMatrix-specific execution property value.

Parameters:
name - Execution property name
value - Execution property value

getExecutionProperty

public java.lang.String getExecutionProperty(java.lang.String name)
Description copied from interface: Statement
Get the MetaMatrix-specific execution property value.

Parameters:
name - Execution property name
Returns:
Execution property value or null if not set

sendRequestMessageAndWait

protected ResultsMessage sendRequestMessageAndWait(RequestMessage reqMsg)
                                            throws java.sql.SQLException,
                                                   java.lang.InterruptedException,
                                                   java.util.concurrent.TimeoutException,
                                                   CommunicationException
Send out request message with necessary states.

Parameters:
transaction - UsertTransaction
sql - String of command or prepared string
listener - Message Listener
timeout - Maybe 0
isPreparedStatement - flag indicating whether this statement is a PreparedStatement
isCallableStatement - flag indicating whether this statement is a CallableStatement
params - Parameters values of either PreparedStatement or CallableStatement
isBatchedCommand - flag indicating whether the statements are being executed as a batch
Throws:
java.sql.SQLException
java.util.concurrent.TimeoutException
java.lang.InterruptedException
CommunicationException

attachStylesheet

public void attachStylesheet(java.io.Reader reader)
                      throws java.io.IOException

This method sets a style sheet to this object. The style sheet is to perform transformations.

Parameters:
reader - The reader object from which the styleSheet is to be read
Throws:
java.io.IOException - if unable to read the style sheet from the Reader object.

clearStylesheet

public void clearStylesheet()

This method removes any existing style sheet on this object.


getPlanDescription

public PlanNode getPlanDescription()
Get Query plan description. If the Statement has a resultSet, we get the plan description from the result set If that plan description is null, though, we return the very first plan description that was created from the resultsMessage in the method: setAnalysisInfo. The plan description from the result set can be null if the resultsMsg stored in the result set hasn't been created when getPlanDescription is called.

Returns:
Query plan description, if it exists, otherwise null

getDebugLog

public java.lang.String getDebugLog()
Get query planner debug log.

Returns:
Query planner debug log, or null if it doesn't exist

getAnnotations

public java.util.Collection getAnnotations()
Get annotations

Returns:
Query planner annotations - Collection of Annotation

setPartialResults

public void setPartialResults(boolean isPartialResults)

getRequestIdentifier

public java.lang.String getRequestIdentifier()
Description copied from interface: Statement
Get ID for last execution which can be used for matching up executions on the client side with executions in the server logs and MetaMatrix console.

Returns:
String identifier for the last execution

isClosed

public boolean isClosed()
Check is the statement is closed. Used primarily by the unit tests.

Specified by:
isClosed in interface java.sql.Statement
Returns:
true if the statement is closed; false otherwise.

setAnalysisInfo

protected void setAnalysisInfo(ResultsMessage resultsMsg)

isPoolable

public boolean isPoolable()
                   throws java.sql.SQLException
Specified by:
isPoolable in interface java.sql.Statement
Throws:
java.sql.SQLException

setPoolable

public void setPoolable(boolean arg0)
                 throws java.sql.SQLException
Specified by:
setPoolable in interface java.sql.Statement
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Specified by:
getConnection in interface java.sql.Statement
Throws:
java.sql.SQLException

execute

public boolean execute(java.lang.String sql,
                       int autoGeneratedKeys)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement
Throws:
java.sql.SQLException

execute

public boolean execute(java.lang.String sql,
                       int[] columnIndexes)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement
Throws:
java.sql.SQLException

execute

public boolean execute(java.lang.String sql,
                       java.lang.String[] columnNames)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement
Throws:
java.sql.SQLException

executeUpdate

public int executeUpdate(java.lang.String sql,
                         int autoGeneratedKeys)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement
Throws:
java.sql.SQLException

executeUpdate

public int executeUpdate(java.lang.String sql,
                         int[] columnIndexes)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement
Throws:
java.sql.SQLException

executeUpdate

public int executeUpdate(java.lang.String sql,
                         java.lang.String[] columnNames)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement
Throws:
java.sql.SQLException

getGeneratedKeys

public java.sql.ResultSet getGeneratedKeys()
                                    throws java.sql.SQLException
Specified by:
getGeneratedKeys in interface java.sql.Statement
Throws:
java.sql.SQLException

getResultSetHoldability

public int getResultSetHoldability()
                            throws java.sql.SQLException
Specified by:
getResultSetHoldability in interface java.sql.Statement
Throws:
java.sql.SQLException

setCursorName

public void setCursorName(java.lang.String name)
                   throws java.sql.SQLException
Specified by:
setCursorName in interface java.sql.Statement
Throws:
java.sql.SQLException

setMaxFieldSize

public void setMaxFieldSize(int max)
                     throws java.sql.SQLException
Specified by:
setMaxFieldSize in interface java.sql.Statement
Throws:
java.sql.SQLException


Copyright © 2009. All Rights Reserved.