org.apache.derby.impl.sql
Class GenericPreparedStatement

java.lang.Object
  extended byorg.apache.derby.impl.sql.GenericPreparedStatement
All Implemented Interfaces:
Dependable, Dependent, ExecPreparedStatement, PreparedStatement, Provider
Direct Known Subclasses:
GenericStorablePreparedStatement

public class GenericPreparedStatement
extends java.lang.Object
implements ExecPreparedStatement

Basic implementation of prepared statement. relies on implementation of ResultDescription and Statement that are also in this package.

These are both dependents (of the schema objects and prepared statements they depend on) and providers. Prepared statements that are providers are cursors that end up being used in positioned delete and update statements (at present).

This is impl with the regular prepared statements; they will never have the cursor info fields set.

Stored prepared statements extend this implementation

Author:
ames

Field Summary
protected  GeneratedClass activationClass
           
protected  java.sql.Timestamp beginCompileTimestamp
           
protected  long bindTime
           
private  Cacheable cacheHolder
          If non-null then this object is the cacheable that holds us in the cache.
protected  long compileTime
           
(package private)  boolean compilingStatement
           
protected  java.sql.Timestamp endCompileTimestamp
           
private  java.lang.String execSchemaName
           
private  java.lang.String execStmtName
           
protected  ConstantAction executionConstants
           
protected  long generateTime
           
private  int inUseCount
           
protected  boolean isAtomic
           
protected  boolean isValid
           
private  boolean needsSavepoint
           
protected  long optimizeTime
           
private  ParameterValueSet params
           
protected  DataTypeDescriptor[] paramTypeDescriptors
           
protected  long parseTime
           
private  boolean referencesSessionSchema
           
protected  ResultDescription resultDesc
           
protected  java.lang.Object[] savedObjects
           
protected  java.lang.String sourceTxt
           
protected  boolean spsAction
           
private  java.lang.String spsName
           
 Statement statement
           
protected  ResultColumnDescriptor[] targetColumns
           
protected  ExecCursorTableReference targetTable
           
protected  java.lang.String[] updateColumns
           
protected  int updateMode
           
protected  java.lang.String UUIDString
           
protected  UUID UUIDValue
           
private  java.sql.SQLWarning warnings
           
 
Fields inherited from interface org.apache.derby.catalog.Dependable
ALIAS, COLUMNS_IN_TABLE, CONGLOMERATE, CONSTRAINT, DEFAULT, FILE, HEAP, INDEX, PREPARED_STATEMENT, SCHEMA, STORED_PREPARED_STATEMENT, TABLE, TRIGGER, VIEW
 
Constructor Summary
protected GenericPreparedStatement()
           
  GenericPreparedStatement(Statement st)
           
 
Method Summary
(package private)  boolean completeCompile(QueryTreeNode qt)
          Makes the prepared statement valid, assigning values for its query tree, generated class, and associated information.
 ResultSet execute(Activation activation, boolean executeQuery, boolean executeUpdate, boolean rollbackParentContext)
          The guts of execution.
 ResultSet execute(LanguageConnectionContext lcc, boolean rollbackParentContext)
          Simple form of execute().
 void finish(LanguageConnectionContext lcc)
          Finish marks a statement as totally unusable.
 Activation getActivation(LanguageConnectionContext lcc, boolean scrollable)
          Get a new activation instance.
 GeneratedClass getActivationClass()
          Get the class generated for this prepared statement.
 java.sql.Timestamp getBeginCompileTimestamp()
          Get the timestamp for the beginning of compilation
 long getBindTimeInMillis()
          Get the bind time for the associated query in milliseconds.
(package private)  ByteArray getByteCodeSaver()
          Get the byte code saver for this statement.
 java.lang.String getClassType()
          Get the Dependable's class type.
 ExecPreparedStatement getClone()
          Get a new prepared statement that is a shallow copy of the current one.
 long getCompileTimeInMillis()
          Get the total compile time for the associated query in milliseconds.
 java.sql.SQLWarning getCompileTimeWarnings()
          Return any compile time warnings.
 ConstantAction getConstantAction()
          Get the Execution constants.
 java.lang.Object getCursorInfo()
          Return the cursor info in a single chunk.
 DependableFinder getDependableFinder()
          Get an object which can be written to disk and which, when read from disk, will find or reconstruct this in-memory Dependable.
 java.sql.Timestamp getEndCompileTimestamp()
          Get the timestamp for the end of compilation
 long getGenerateTimeInMillis()
          Get the generate time for the associated query in milliseconds.
 UUID getObjectID()
          Get the Dependable's UUID String.
 java.lang.String getObjectName()
          Return the name of this Dependable.
 long getOptimizeTimeInMillis()
          Get the optimize time for the associated query in milliseconds.
 DataTypeDescriptor[] getParameterTypes()
          Get an array of DataTypeDescriptors describing the types of the parameters of this PreparedStatement.
 long getParseTimeInMillis()
          Get the parse time for the associated query in milliseconds.
 ResultDescription getResultDescription()
          Get the ResultDescription for the statement.
 java.lang.Object getSavedObject(int objectNum)
          Get the specified saved object.
 java.lang.Object[] getSavedObjects()
          Get the saved objects.
 java.lang.String getSource()
          Return the SQL string that this statement is for.
 java.lang.String getSPSName()
          Return the SPS Name for this statement.
 ResultColumnDescriptor[] getTargetColumns()
          the target columns of the cursor as a result column list
 ExecCursorTableReference getTargetTable()
          the target table of the cursor
 java.lang.String[] getUpdateColumns()
          the update columns of the cursor as a update column list
 int getUpdateMode()
          the update mode of the cursor
 boolean isAtomic()
          Returns whether or not this Statement requires should behave atomically -- i.e. whether a user is permitted to do a commit/rollback during the execution of this statement.
 boolean isPersistent()
          Is this dependent persistent?
 boolean isStorable()
           
 boolean isValid()
          Check that all of the dependent's dependencies are valid.
 void makeInvalid(int action, LanguageConnectionContext lcc)
          Mark the dependent as invalid (due to at least one of its dependencies being invalid).
 void makeValid(LanguageConnectionContext lcc)
          Attempt to revalidate the dependent.
 boolean needsSavepoint()
          Does this statement need a savepoint?
 void prepareToInvalidate(Provider p, int action, LanguageConnectionContext lcc)
          Prepare to mark the dependent as invalid (due to at least one of its dependencies being invalid).
 boolean referencesSessionSchema()
          Return true if the query node for this statement references SESSION schema tables.
 void rePrepare(LanguageConnectionContext lcc)
          Re-prepare the statement if it is not up to date or, if requested, simply not optimal.
(package private)  void setActivationClass(GeneratedClass ac)
           
 void setCacheHolder(Cacheable cacheHolder)
           
protected  void setCompileTimeMillis(long parseTime, long bindTime, long optimizeTime, long generateTime, long compileTime, java.sql.Timestamp beginCompileTimestamp, java.sql.Timestamp endCompileTimestamp)
          Set the compile time for this prepared statement.
(package private)  void setCompileTimeWarnings(java.sql.SQLWarning warnings)
           
 void setConstantAction(ConstantAction constantAction)
          Set the Execution constants.
(package private)  void setCursorInfo(CursorInfo cursorInfo)
           
(package private)  void setExecuteStatementNameAndSchema(java.lang.String execStmtName, java.lang.String execSchemaName)
          Set the name of the statement and schema for an "execute statement" command.
(package private)  void setIsAtomic(boolean isAtomic)
          Set the stmts 'isAtomic' state.
(package private)  void setNeedsSavepoint(boolean needsSavepoint)
          Set the stmts 'needsSavepoint' state.
protected  void setParams(ParameterValueSet params)
          Set parameters to be associated with this statement.
 void setSavedObjects(java.lang.Object[] objects)
          Set the saved objects.
 void setSource(java.lang.String text)
          set the statement text
 void setSPSAction()
          Indicate this prepared statement is an SPS action, currently used by GenericTriggerExecutor.
 void setSPSName(java.lang.String name)
           
 void setValid()
          set this prepared statement to be valid, currently used by GenericTriggerExecutor.
 java.lang.String toString()
           
 boolean upToDate()
          Checks whether this PreparedStatement is up to date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

statement

public Statement statement

activationClass

protected GeneratedClass activationClass

resultDesc

protected ResultDescription resultDesc

paramTypeDescriptors

protected DataTypeDescriptor[] paramTypeDescriptors

spsName

private java.lang.String spsName

warnings

private java.sql.SQLWarning warnings

referencesSessionSchema

private boolean referencesSessionSchema

targetTable

protected ExecCursorTableReference targetTable

targetColumns

protected ResultColumnDescriptor[] targetColumns

updateColumns

protected java.lang.String[] updateColumns

updateMode

protected int updateMode

executionConstants

protected ConstantAction executionConstants

savedObjects

protected java.lang.Object[] savedObjects

UUIDString

protected java.lang.String UUIDString

UUIDValue

protected UUID UUIDValue

params

private ParameterValueSet params

needsSavepoint

private boolean needsSavepoint

execStmtName

private java.lang.String execStmtName

execSchemaName

private java.lang.String execSchemaName

isAtomic

protected boolean isAtomic

sourceTxt

protected java.lang.String sourceTxt

inUseCount

private int inUseCount

compilingStatement

boolean compilingStatement

parseTime

protected long parseTime

bindTime

protected long bindTime

optimizeTime

protected long optimizeTime

generateTime

protected long generateTime

compileTime

protected long compileTime

beginCompileTimestamp

protected java.sql.Timestamp beginCompileTimestamp

endCompileTimestamp

protected java.sql.Timestamp endCompileTimestamp

isValid

protected boolean isValid

spsAction

protected boolean spsAction

cacheHolder

private Cacheable cacheHolder
If non-null then this object is the cacheable that holds us in the cache.

Constructor Detail

GenericPreparedStatement

protected GenericPreparedStatement()

GenericPreparedStatement

public GenericPreparedStatement(Statement st)
Method Detail

upToDate

public boolean upToDate()
                 throws StandardException
Description copied from interface: PreparedStatement
Checks whether this PreparedStatement is up to date. A PreparedStatement can become out of date if any of several things happen: A schema used by the statement is dropped A table used by the statement is dropped A table used by the statement, or a column in such a table, is altered in one of several ways: a column is dropped, a privilege is dropped, a constraint is added or dropped, an index is dropped. A view used by the statement is dropped. In general, anything that happened since the plan was generated that might cause the plan to fail, or to generate incorrect results, will cause this method to return FALSE.

Specified by:
upToDate in interface PreparedStatement
Returns:
TRUE if the PreparedStatement is up to date, FALSE if it is not up to date
Throws:
StandardException

rePrepare

public void rePrepare(LanguageConnectionContext lcc)
               throws StandardException
Description copied from interface: PreparedStatement
Re-prepare the statement if it is not up to date or, if requested, simply not optimal. If there are open cursors using this prepared statement, then we will not be able to recompile the statement.

Specified by:
rePrepare in interface PreparedStatement
Parameters:
lcc - The LanguageConnectionContext.
Throws:
StandardException - thrown if unable to perform

getActivation

public Activation getActivation(LanguageConnectionContext lcc,
                                boolean scrollable)
                         throws StandardException
Get a new activation instance.

Specified by:
getActivation in interface PreparedStatement
Parameters:
lcc - The LanguageConnectionContext.
Returns:
The new activation.
Throws:
StandardException - thrown if finished.

execute

public ResultSet execute(LanguageConnectionContext lcc,
                         boolean rollbackParentContext)
                  throws StandardException
Description copied from interface: PreparedStatement
Simple form of execute(). Creates a new single use activation and executes it, but also passes rollbackParentContext parameter (see above).

Specified by:
execute in interface PreparedStatement
Throws:
StandardException

execute

public ResultSet execute(Activation activation,
                         boolean executeQuery,
                         boolean executeUpdate,
                         boolean rollbackParentContext)
                  throws StandardException
The guts of execution.

Specified by:
execute in interface PreparedStatement
Parameters:
activation - the activation to run.
executeQuery - Called via executeQuery
executeUpdate - Called via executeUpdate
rollbackParentContext - True if 1) the statement context is NOT a top-level context, AND 2) in the event of a statement-level exception, the parent context needs to be rolled back, too.
Returns:
the result set to be pawed through
Throws:
StandardException - thrown on error

getResultDescription

public ResultDescription getResultDescription()
Description copied from interface: PreparedStatement
Get the ResultDescription for the statement. The ResultDescription describes what the results look like: what are the rows and columns?

This is available here and on the ResultSet so that users can see the shape of the result before they execute.

Specified by:
getResultDescription in interface PreparedStatement
Returns:
A ResultDescription describing the results.

getParameterTypes

public DataTypeDescriptor[] getParameterTypes()
Description copied from interface: PreparedStatement
Get an array of DataTypeDescriptors describing the types of the parameters of this PreparedStatement. The Nth element of the array describes the Nth parameter.

Specified by:
getParameterTypes in interface PreparedStatement
Returns:
An array of DataTypeDescriptors telling the type, length, precision, scale, etc. of each parameter of this PreparedStatement.

getSource

public java.lang.String getSource()
Description copied from interface: PreparedStatement
Return the SQL string that this statement is for.

Specified by:
getSource in interface PreparedStatement
Returns:
the SQL string this statement is for.

setSource

public void setSource(java.lang.String text)
Description copied from interface: ExecPreparedStatement
set the statement text

Specified by:
setSource in interface ExecPreparedStatement
Parameters:
text - the source text

setSPSName

public final void setSPSName(java.lang.String name)

getSPSName

public java.lang.String getSPSName()
Description copied from interface: PreparedStatement
Return the SPS Name for this statement.

Specified by:
getSPSName in interface PreparedStatement
Returns:
the SPS Name for this statement

getCompileTimeInMillis

public long getCompileTimeInMillis()
Get the total compile time for the associated query in milliseconds. Compile time can be divided into parse, bind, optimize and generate times.

Specified by:
getCompileTimeInMillis in interface PreparedStatement
Returns:
long The total compile time for the associated query in milliseconds.

getParseTimeInMillis

public long getParseTimeInMillis()
Get the parse time for the associated query in milliseconds.

Specified by:
getParseTimeInMillis in interface PreparedStatement
Returns:
long The parse time for the associated query in milliseconds.

getBindTimeInMillis

public long getBindTimeInMillis()
Get the bind time for the associated query in milliseconds.

Specified by:
getBindTimeInMillis in interface PreparedStatement
Returns:
long The bind time for the associated query in milliseconds.

getOptimizeTimeInMillis

public long getOptimizeTimeInMillis()
Get the optimize time for the associated query in milliseconds.

Specified by:
getOptimizeTimeInMillis in interface PreparedStatement
Returns:
long The optimize time for the associated query in milliseconds.

getGenerateTimeInMillis

public long getGenerateTimeInMillis()
Get the generate time for the associated query in milliseconds.

Specified by:
getGenerateTimeInMillis in interface PreparedStatement
Returns:
long The generate time for the associated query in milliseconds.

getBeginCompileTimestamp

public java.sql.Timestamp getBeginCompileTimestamp()
Get the timestamp for the beginning of compilation

Specified by:
getBeginCompileTimestamp in interface PreparedStatement
Returns:
Timestamp The timestamp for the beginning of compilation.

getEndCompileTimestamp

public java.sql.Timestamp getEndCompileTimestamp()
Get the timestamp for the end of compilation

Specified by:
getEndCompileTimestamp in interface PreparedStatement
Returns:
Timestamp The timestamp for the end of compilation.

setCompileTimeWarnings

void setCompileTimeWarnings(java.sql.SQLWarning warnings)

getCompileTimeWarnings

public final java.sql.SQLWarning getCompileTimeWarnings()
Description copied from interface: PreparedStatement
Return any compile time warnings. Null if no warnings exist.

Specified by:
getCompileTimeWarnings in interface PreparedStatement

setCompileTimeMillis

protected void setCompileTimeMillis(long parseTime,
                                    long bindTime,
                                    long optimizeTime,
                                    long generateTime,
                                    long compileTime,
                                    java.sql.Timestamp beginCompileTimestamp,
                                    java.sql.Timestamp endCompileTimestamp)
Set the compile time for this prepared statement.

Parameters:
compileTime - The compile time
Returns:
Nothing.

finish

public void finish(LanguageConnectionContext lcc)
Finish marks a statement as totally unusable.

Specified by:
finish in interface ExecPreparedStatement

setConstantAction

public final void setConstantAction(ConstantAction constantAction)
Set the Execution constants. This routine is called as we Prepare the statement.


getConstantAction

public final ConstantAction getConstantAction()
Get the Execution constants. This routine is called at Execution time.

Specified by:
getConstantAction in interface ExecPreparedStatement
Returns:
ConstantAction The big structure enclosing the Execution constants.

setSavedObjects

public final void setSavedObjects(java.lang.Object[] objects)
Set the saved objects. Called when compilation completes.

Parameters:
objects - The objects to save from compilation

getSavedObject

public final java.lang.Object getSavedObject(int objectNum)
Get the specified saved object.

Specified by:
getSavedObject in interface ExecPreparedStatement
Parameters:
objectNum - The object to get.
Returns:
the requested saved object.

getSavedObjects

public final java.lang.Object[] getSavedObjects()
Get the saved objects.

Specified by:
getSavedObjects in interface ExecPreparedStatement
Returns:
all the saved objects

isValid

public boolean isValid()
Check that all of the dependent's dependencies are valid.

Specified by:
isValid in interface Dependent
Returns:
true if the dependent is currently valid

setValid

public void setValid()
set this prepared statement to be valid, currently used by GenericTriggerExecutor.

Specified by:
setValid in interface ExecPreparedStatement

setSPSAction

public void setSPSAction()
Indicate this prepared statement is an SPS action, currently used by GenericTriggerExecutor.

Specified by:
setSPSAction in interface ExecPreparedStatement

prepareToInvalidate

public void prepareToInvalidate(Provider p,
                                int action,
                                LanguageConnectionContext lcc)
                         throws StandardException
Prepare to mark the dependent as invalid (due to at least one of its dependencies being invalid).

Specified by:
prepareToInvalidate in interface Dependent
Parameters:
action - The action causing the invalidation
p - the provider
lcc - The LanguageConnectionContext
Throws:
StandardException - thrown if unable to make it invalid

makeInvalid

public void makeInvalid(int action,
                        LanguageConnectionContext lcc)
                 throws StandardException
Mark the dependent as invalid (due to at least one of its dependencies being invalid).

Specified by:
makeInvalid in interface Dependent
Parameters:
action - The action causing the invalidation
lcc - The LanguageConnectionContext
Throws:
StandardException - Standard Cloudscape error policy.

makeValid

public void makeValid(LanguageConnectionContext lcc)
               throws StandardException
Attempt to revalidate the dependent. For prepared statements, this could go through its dependencies and check that they are up to date; if not, it would recompile the statement. Any failure during this attempt should throw StandardException.unableToRevalidate().

Specified by:
makeValid in interface Dependent
Parameters:
lcc - The LanguageConnectionContext
Throws:
StandardException - thrown if unable to make it valid

isPersistent

public boolean isPersistent()
Is this dependent persistent? A stored dependency will be required if both the dependent and provider are persistent.

Specified by:
isPersistent in interface Dependable
Returns:
boolean Whether or not this dependent is persistent.

getDependableFinder

public DependableFinder getDependableFinder()
Description copied from interface: Dependable
Get an object which can be written to disk and which, when read from disk, will find or reconstruct this in-memory Dependable.

Specified by:
getDependableFinder in interface Dependable
Returns:
the stored form of this Dependable
See Also:
Dependable.getDependableFinder()

getObjectName

public java.lang.String getObjectName()
Return the name of this Dependable. (Useful for errors.)

Specified by:
getObjectName in interface Dependable
Returns:
String The name of this Dependable..

getObjectID

public UUID getObjectID()
Get the Dependable's UUID String.

Specified by:
getObjectID in interface Dependable
Returns:
String The Dependable's UUID String.

getClassType

public java.lang.String getClassType()
Get the Dependable's class type.

Specified by:
getClassType in interface Dependable
Returns:
String Classname that this Dependable belongs to.

referencesSessionSchema

public boolean referencesSessionSchema()
Return true if the query node for this statement references SESSION schema tables.

Specified by:
referencesSessionSchema in interface PreparedStatement
Returns:
true if references SESSION schema tables, else false

completeCompile

boolean completeCompile(QueryTreeNode qt)
                  throws StandardException
Makes the prepared statement valid, assigning values for its query tree, generated class, and associated information.

Parameters:
qt - the query tree for this statement
Returns:
true if there is a reference to SESSION schema tables, else false
Throws:
StandardException - thrown on failure.

getActivationClass

public GeneratedClass getActivationClass()
                                  throws StandardException
Description copied from interface: ExecPreparedStatement
Get the class generated for this prepared statement. Used to confirm compatability with auxilary structures.

Specified by:
getActivationClass in interface ExecPreparedStatement
Throws:
StandardException - on error obtaining class (probably when a stored prepared statement is loading)

setActivationClass

void setActivationClass(GeneratedClass ac)

getUpdateMode

public int getUpdateMode()
the update mode of the cursor

Specified by:
getUpdateMode in interface ExecPreparedStatement
Returns:
The update mode of the cursor

getTargetTable

public ExecCursorTableReference getTargetTable()
the target table of the cursor

Specified by:
getTargetTable in interface ExecPreparedStatement
Returns:
target table of the cursor

getTargetColumns

public ResultColumnDescriptor[] getTargetColumns()
the target columns of the cursor as a result column list

Specified by:
getTargetColumns in interface ExecPreparedStatement
Returns:
target columns of the cursor as a result column list

getUpdateColumns

public java.lang.String[] getUpdateColumns()
the update columns of the cursor as a update column list

Specified by:
getUpdateColumns in interface ExecPreparedStatement
Returns:
update columns of the cursor as a array of strings

getCursorInfo

public java.lang.Object getCursorInfo()
Return the cursor info in a single chunk. Used by StrorablePreparedStatement

Specified by:
getCursorInfo in interface ExecPreparedStatement
Returns:
Object the cursor info

setCursorInfo

void setCursorInfo(CursorInfo cursorInfo)

getByteCodeSaver

ByteArray getByteCodeSaver()
Get the byte code saver for this statement. Overridden for StorablePreparedStatement. We don't want to save anything

Returns:
a byte code saver (null for us)

setParams

protected void setParams(ParameterValueSet params)
Set parameters to be associated with this statement. Used to process EXECUTE STATMENT USING statements -- the is evaluated and a parameter list is generated. That list is saved using this call. Parameters are set in the activation when it is created (see getActivation).

Parameters:
params - the parameters

needsSavepoint

public boolean needsSavepoint()
Does this statement need a savepoint?

Specified by:
needsSavepoint in interface ExecPreparedStatement
Returns:
true if this statement needs a savepoint.

setNeedsSavepoint

void setNeedsSavepoint(boolean needsSavepoint)
Set the stmts 'needsSavepoint' state. Used by an SPS to convey whether the underlying stmt needs a savepoint or not.

Parameters:
needsSavepoint - true if this statement needs a savepoint.

setIsAtomic

void setIsAtomic(boolean isAtomic)
Set the stmts 'isAtomic' state.

Parameters:
isAtomic - true if this statement must be atomic (i.e. it is not ok to do a commit/rollback in the middle)

isAtomic

public boolean isAtomic()
Returns whether or not this Statement requires should behave atomically -- i.e. whether a user is permitted to do a commit/rollback during the execution of this statement.

Specified by:
isAtomic in interface PreparedStatement
Returns:
boolean Whether or not this Statement is atomic

setExecuteStatementNameAndSchema

void setExecuteStatementNameAndSchema(java.lang.String execStmtName,
                                      java.lang.String execSchemaName)
Set the name of the statement and schema for an "execute statement" command.


getClone

public ExecPreparedStatement getClone()
                               throws StandardException
Get a new prepared statement that is a shallow copy of the current one.

Specified by:
getClone in interface ExecPreparedStatement
Returns:
a new prepared statement
Throws:
StandardException - on error

setCacheHolder

public void setCacheHolder(Cacheable cacheHolder)

toString

public java.lang.String toString()

isStorable

public boolean isStorable()

Built on Tue 2006-10-10 19:23:47+0200, from revision exported

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.