Package org.apache.derby.impl.sql
Class GenericParameterValueSet
- java.lang.Object
-
- org.apache.derby.impl.sql.GenericParameterValueSet
-
- All Implemented Interfaces:
ParameterValueSet
final class GenericParameterValueSet extends java.lang.Object implements ParameterValueSet
Implementation of ParameterValueSet- See Also:
ParameterValueSet
-
-
Field Summary
Fields Modifier and Type Field Description (package private) ClassInspectorciprivate booleanhasReturnOutputParamprivate GenericParameter[]parms
-
Constructor Summary
Constructors Modifier Constructor Description privateGenericParameterValueSet(int numParms, GenericParameterValueSet pvs)(package private)GenericParameterValueSet(ClassInspector ci, int numParms, boolean hasReturnOutputParam)Constructor for a GenericParameterValueSet
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallAreSet()Tells whether all the parameters are set and ready for execution.booleancheckNoDeclaredOutputParameters()Check that there are not output parameters defined by the parameter set.private voidcheckPosition(int position)Check the position number for a parameter and throw an exception if it is out of range.voidclearParameters()Sets all parameters to an uninitialized state.ParameterValueSetgetClone()Clone the ParameterValueSet and its contents.(package private) GenericParametergetGenericParameter(int position)DataValueDescriptorgetParameter(int position)Returns the parameter value at the given position.intgetParameterCount()Returns the number of parameters in this set.DataValueDescriptorgetParameterForGet(int position)Get the DataValueDescriptor for an INOUT or OUT parameter.DataValueDescriptorgetParameterForSet(int position)Returns the parameter at the given position in order to set it.shortgetParameterMode(int parameterIndex)Return the mode of the parameter according to JDBC 3.0 ParameterMetaDataintgetParameterNumber(GenericParameter theParam)Return the parameter number (in jdbc lingo, i.e. 1 based) for the given parameter.intgetPrecision(int parameterIndex)Return the precision of the given parameter index in this pvs.DataValueDescriptorgetReturnValueForSet()Get the value of the return parameter in order to set it.intgetScale(int parameterIndex)Return the scale of the given parameter index in this pvs.booleanhasReturnOutputParameter()Is there a return output parameter in this pvs.voidinitialize(DataTypeDescriptor[] types)Initialize the set by allocating a holder DataValueDescriptor object for each parameter.voidregisterOutParameter(int parameterIndex, int jdbcType, int scale)Mark the parameter as an output parameter.voidsetParameterAsObject(int position, java.lang.Object value)Set the value of this user defined parameter to the passed in Object.voidsetParameterMode(int position, int mode)Set the mode of the parameter, called when setting up static method calls and stored procedures.java.lang.StringtoString()voidtransferDataValues(ParameterValueSet pvstarget)Set the parameter values of the pvstarget to equal those set in this PVS.voidvalidate()Validate the parameters.
-
-
-
Field Detail
-
parms
private final GenericParameter[] parms
-
ci
final ClassInspector ci
-
hasReturnOutputParam
private final boolean hasReturnOutputParam
-
-
Constructor Detail
-
GenericParameterValueSet
GenericParameterValueSet(ClassInspector ci, int numParms, boolean hasReturnOutputParam)
Constructor for a GenericParameterValueSet- Parameters:
numParms- The number of parameters in the new ParameterValueSethasReturnOutputParam- if we have a ? = call syntax. Note that this is NOT the same thing as an output parameter -- return output parameters are special cases of output parameters.
-
GenericParameterValueSet
private GenericParameterValueSet(int numParms, GenericParameterValueSet pvs)
-
-
Method Detail
-
initialize
public void initialize(DataTypeDescriptor[] types) throws StandardException
Initialize the set by allocating a holder DataValueDescriptor object for each parameter.- Specified by:
initializein interfaceParameterValueSet- Parameters:
types- expected to match the number of parameters.- Throws:
StandardException
-
setParameterMode
public void setParameterMode(int position, int mode)Description copied from interface:ParameterValueSetSet the mode of the parameter, called when setting up static method calls and stored procedures. Otherwise the parameter type will default to an IN parameter.- Specified by:
setParameterModein interfaceParameterValueSet
-
clearParameters
public void clearParameters()
Description copied from interface:ParameterValueSetSets all parameters to an uninitialized state. An exception will be thrown if the caller tries to execute a PreparedStatement when one or more parameters is uninitialized (i.e. has not had setParameterValue() called on it.- Specified by:
clearParametersin interfaceParameterValueSet- See Also:
ParameterValueSet.clearParameters()
-
getParameterCount
public int getParameterCount()
Returns the number of parameters in this set.- Specified by:
getParameterCountin interfaceParameterValueSet- Returns:
- The number of parameters in this set.
-
getParameter
public DataValueDescriptor getParameter(int position) throws StandardException
Returns the parameter value at the given position.- Specified by:
getParameterin interfaceParameterValueSet- Returns:
- The parameter at the given position.
- Throws:
StandardException- Thrown on error
-
getParameterForSet
public DataValueDescriptor getParameterForSet(int position) throws StandardException
Description copied from interface:ParameterValueSetReturns the parameter at the given position in order to set it. Setting via an unknown object type must use setParameterAsObject() to ensure correct typing.- Specified by:
getParameterForSetin interfaceParameterValueSet- Returns:
- The parameter at the given position.
- Throws:
StandardException- Thrown on error
-
getParameterForGet
public DataValueDescriptor getParameterForGet(int position) throws StandardException
Description copied from interface:ParameterValueSetGet the DataValueDescriptor for an INOUT or OUT parameter.- Specified by:
getParameterForGetin interfaceParameterValueSet- Parameters:
position- Zero based index of the parameter.- Returns:
- Parameter's value holder.
- Throws:
StandardException- Position out of range or the parameter is not INOUT or OUT.
-
setParameterAsObject
public void setParameterAsObject(int position, java.lang.Object value) throws StandardExceptionDescription copied from interface:ParameterValueSetSet the value of this user defined parameter to the passed in Object.- Specified by:
setParameterAsObjectin interfaceParameterValueSet- Throws:
StandardException- Thrown on error
-
allAreSet
public boolean allAreSet()
Description copied from interface:ParameterValueSetTells whether all the parameters are set and ready for execution. OUT are not required to be set.- Specified by:
allAreSetin interfaceParameterValueSet- Returns:
- true if all parameters are set, false if at least one parameter is not set.
- See Also:
ParameterValueSet.allAreSet()
-
transferDataValues
public void transferDataValues(ParameterValueSet pvstarget) throws StandardException
Description copied from interface:ParameterValueSetSet the parameter values of the pvstarget to equal those set in this PVS. Used to transfer saved SPS parameters to the actual prepared statement parameters once associated parameters have been established. Assumes pvstarget is the same length as this.- Specified by:
transferDataValuesin interfaceParameterValueSet- Parameters:
pvstarget- ParameterValueSet which will recieve the values- Throws:
StandardException- values not compatible- See Also:
ParameterValueSet.transferDataValues(org.apache.derby.iapi.sql.ParameterValueSet)
-
getGenericParameter
GenericParameter getGenericParameter(int position)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
checkPosition
private void checkPosition(int position) throws StandardExceptionCheck the position number for a parameter and throw an exception if it is out of range.- Parameters:
position- The position number to check- Throws:
StandardException- Thrown if position number is out of range.
-
getClone
public ParameterValueSet getClone()
Description copied from interface:ParameterValueSetClone the ParameterValueSet and its contents.- Specified by:
getClonein interfaceParameterValueSet- Returns:
- ParameterValueSet A clone of the ParameterValueSet and its contents.
-
registerOutParameter
public void registerOutParameter(int parameterIndex, int jdbcType, int scale) throws StandardExceptionMark the parameter as an output parameter.- Specified by:
registerOutParameterin interfaceParameterValueSet- Parameters:
parameterIndex- The ordinal parameterIndex of a parameter to set to the given value.jdbcType- A type from java.sql.Typesscale- the scale to use. -1 means ignore scale- Throws:
StandardException- on error
-
validate
public void validate() throws StandardExceptionValidate the parameters. This is done for situations where we cannot validate everything in the setXXX() calls. In particular, before we do an execute() on a CallableStatement, we need to go through the parameters and make sure that all parameters are set up properly. The motivator for this is that setXXX() can be called either before or after registerOutputParamter(), we cannot be sure we have the types correct until we get to execute().- Specified by:
validatein interfaceParameterValueSet- Throws:
StandardException- if the parameters aren't valid
-
getParameterNumber
public int getParameterNumber(GenericParameter theParam)
Return the parameter number (in jdbc lingo, i.e. 1 based) for the given parameter. Linear search.- Returns:
- the parameter number, or 0 if not found
-
checkNoDeclaredOutputParameters
public boolean checkNoDeclaredOutputParameters()
Check that there are not output parameters defined by the parameter set. If there are unknown parameter types they are forced to input types. i.e. Derby static method calls with parameters that are array.- Specified by:
checkNoDeclaredOutputParametersin interfaceParameterValueSet- Returns:
- true if a declared Java Procedure INOUT or OUT parameter is in the set, false otherwise.
-
getParameterMode
public short getParameterMode(int parameterIndex)
Return the mode of the parameter according to JDBC 3.0 ParameterMetaData- Specified by:
getParameterModein interfaceParameterValueSet- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...
-
hasReturnOutputParameter
public boolean hasReturnOutputParameter()
Is there a return output parameter in this pvs. A return parameter is from a CALL statement of the following syntax: ? = CALL myMethod()- Specified by:
hasReturnOutputParameterin interfaceParameterValueSet- Returns:
- true if it has a return parameter
-
getReturnValueForSet
public DataValueDescriptor getReturnValueForSet() throws StandardException
Get the value of the return parameter in order to set it.- Specified by:
getReturnValueForSetin interfaceParameterValueSet- Throws:
StandardException- if a database-access error occurs.
-
getScale
public int getScale(int parameterIndex)
Return the scale of the given parameter index in this pvs.- Specified by:
getScalein interfaceParameterValueSet- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...- Returns:
- scale
-
getPrecision
public int getPrecision(int parameterIndex)
Return the precision of the given parameter index in this pvs.- Specified by:
getPrecisionin interfaceParameterValueSet- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...- Returns:
- precision
-
-