Package org.postgresql.core.v3
Class SimpleParameterList
- java.lang.Object
-
- org.postgresql.core.v3.SimpleParameterList
-
- All Implemented Interfaces:
ParameterList
,V3ParameterList
class SimpleParameterList extends java.lang.Object implements V3ParameterList
Parameter list for a single-statement V3 query.
-
-
Field Summary
Fields Modifier and Type Field Description private static byte
BINARY
private byte[][]
encoded
private byte[]
flags
private static byte
IN
private static byte
INOUT
private static java.lang.Object
NULL_OBJECT
Marker object representing NULL; this distinguishes "parameter never set" from "parameter set to null".private static byte
OUT
private int[]
paramTypes
private java.lang.Object[]
paramValues
private int
pos
private static byte
TEXT
private TypeTransferModeRegistry
transferModeRegistry
-
Constructor Summary
Constructors Constructor Description SimpleParameterList(int paramCount, TypeTransferModeRegistry transferModeRegistry)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendAll(ParameterList list)
Use this operation to append more parameters to the current list.private void
bind(int index, java.lang.Object value, int oid, byte binary)
void
checkAllParametersSet()
Ensure that all parameters in this list have been assigned values.void
clear()
Unbind all parameter values bound in this list.void
convertFunctionOutParameters()
Convert any function output parameters to the correct type (void) and set an ignorable value for it.ParameterList
copy()
Perform a shallow copy of this ParameterList, returning a new instance (still suitable for passing to the owning Query).private byte
direction(int index)
byte[][]
getEncoding()
Return the encoding for each parameter.byte[]
getFlags()
Return the flags for each parameter.int
getInParameterCount()
Get the number of IN parameters in this list.int
getOutParameterCount()
Get the number of OUT parameters in this list.int
getParameterCount()
Get the number of parameters in this list.int[]
getParamTypes()
Return the parameter type information.SimpleParameterList[]
getSubparams()
Return a list of the SimpleParameterList objects that make up this parameter list.(package private) int
getTypeOID(int index)
int[]
getTypeOIDs()
Return the oids of the parameters in this list.(package private) int
getV3Length(int index)
java.lang.Object[]
getValues()
Returns the bound parameter values.(package private) boolean
hasUnresolvedTypes()
(package private) boolean
isBinary(int index)
(package private) boolean
isNull(int index)
void
registerOutParameter(int index, int sqlType)
void
setBinaryParameter(int index, byte[] value, int oid)
Binds given byte[] value to a parameter.void
setBytea(int index, byte[] data, int offset, int length)
Binds a binary bytea value stored as a bytearray to a parameter.void
setBytea(int index, java.io.InputStream stream)
Binds a binary bytea value stored as an InputStream.void
setBytea(int index, java.io.InputStream stream, int length)
Binds a binary bytea value stored as an InputStream.void
setBytea(int index, ByteStreamWriter writer)
Binds a binary bytea value stored as a ByteStreamWriter.void
setIntParameter(int index, int value)
Binds an integer value to a parameter.void
setLiteralParameter(int index, java.lang.String value, int oid)
Binds a String value that is an unquoted literal to the server's query parser (for example, a bare integer) to a parameter.void
setNull(int index, int oid)
Binds a SQL NULL value to a parameter.(package private) void
setResolvedType(int index, int oid)
void
setStringParameter(int index, java.lang.String value, int oid)
Binds a String value that needs to be quoted for the server's parser to understand (for example, a timestamp) to a parameter.void
setText(int index, java.io.InputStream stream)
Binds a text value stored as an InputStream that is a valid UTF-8 byte stream.private static void
streamBytea(PGStream pgStream, ByteStreamWriter writer)
private static void
streamBytea(PGStream pgStream, StreamWrapper wrapper)
java.lang.String
toString()
Useful implementation of toString.java.lang.String
toString(int index, boolean standardConformingStrings)
Return a human-readable representation of a particular parameter in this ParameterList.(package private) void
writeV3Value(int index, PGStream pgStream)
-
-
-
Field Detail
-
IN
private static final byte IN
- See Also:
- Constant Field Values
-
OUT
private static final byte OUT
- See Also:
- Constant Field Values
-
INOUT
private static final byte INOUT
- See Also:
- Constant Field Values
-
TEXT
private static final byte TEXT
- See Also:
- Constant Field Values
-
BINARY
private static final byte BINARY
- See Also:
- Constant Field Values
-
paramValues
private final java.lang.Object[] paramValues
-
paramTypes
private final int[] paramTypes
-
flags
private final byte[] flags
-
encoded
private final byte[][] encoded
-
transferModeRegistry
private final TypeTransferModeRegistry transferModeRegistry
-
NULL_OBJECT
private static final java.lang.Object NULL_OBJECT
Marker object representing NULL; this distinguishes "parameter never set" from "parameter set to null".
-
pos
private int pos
-
-
Constructor Detail
-
SimpleParameterList
SimpleParameterList(int paramCount, TypeTransferModeRegistry transferModeRegistry)
-
-
Method Detail
-
registerOutParameter
public void registerOutParameter(int index, int sqlType) throws java.sql.SQLException
- Specified by:
registerOutParameter
in interfaceParameterList
- Throws:
java.sql.SQLException
-
bind
private void bind(int index, java.lang.Object value, int oid, byte binary) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
getParameterCount
public int getParameterCount()
Description copied from interface:ParameterList
Get the number of parameters in this list. This value never changes for a particular instance, and might be zero.- Specified by:
getParameterCount
in interfaceParameterList
- Returns:
- the number of parameters in this list.
-
getOutParameterCount
public int getOutParameterCount()
Description copied from interface:ParameterList
Get the number of OUT parameters in this list.- Specified by:
getOutParameterCount
in interfaceParameterList
- Returns:
- the number of OUT parameters in this list
-
getInParameterCount
public int getInParameterCount()
Description copied from interface:ParameterList
Get the number of IN parameters in this list.- Specified by:
getInParameterCount
in interfaceParameterList
- Returns:
- the number of IN parameters in this list
-
setIntParameter
public void setIntParameter(int index, int value) throws java.sql.SQLException
Description copied from interface:ParameterList
Binds an integer value to a parameter. The type of the parameter is implicitly 'int4'.- Specified by:
setIntParameter
in interfaceParameterList
- Parameters:
index
- the 1-based parameter index to bind.value
- the integer value to use.- Throws:
java.sql.SQLException
- on error or ifindex
is out of range
-
setLiteralParameter
public void setLiteralParameter(int index, java.lang.String value, int oid) throws java.sql.SQLException
Description copied from interface:ParameterList
Binds a String value that is an unquoted literal to the server's query parser (for example, a bare integer) to a parameter. Associated with the parameter is a typename for the parameter that should correspond to an entry in pg_types.- Specified by:
setLiteralParameter
in interfaceParameterList
- Parameters:
index
- the 1-based parameter index to bind.value
- the unquoted literal string to use.oid
- the type OID of the parameter, or0
to infer the type.- Throws:
java.sql.SQLException
- on error or ifindex
is out of range
-
setStringParameter
public void setStringParameter(int index, java.lang.String value, int oid) throws java.sql.SQLException
Description copied from interface:ParameterList
Binds a String value that needs to be quoted for the server's parser to understand (for example, a timestamp) to a parameter. Associated with the parameter is a typename for the parameter that should correspond to an entry in pg_types.- Specified by:
setStringParameter
in interfaceParameterList
- Parameters:
index
- the 1-based parameter index to bind.value
- the quoted string to use.oid
- the type OID of the parameter, or0
to infer the type.- Throws:
java.sql.SQLException
- on error or ifindex
is out of range
-
setBinaryParameter
public void setBinaryParameter(int index, byte[] value, int oid) throws java.sql.SQLException
Description copied from interface:ParameterList
Binds given byte[] value to a parameter. The bytes must already be in correct format matching the OID.- Specified by:
setBinaryParameter
in interfaceParameterList
- Parameters:
index
- the 1-based parameter index to bind.value
- the bytes to send.oid
- the type OID of the parameter.- Throws:
java.sql.SQLException
- on error or ifindex
is out of range
-
setBytea
public void setBytea(int index, byte[] data, int offset, int length) throws java.sql.SQLException
Description copied from interface:ParameterList
Binds a binary bytea value stored as a bytearray to a parameter. The parameter's type is implicitly set to 'bytea'. The bytearray's contains should remain unchanged until query execution has completed.- Specified by:
setBytea
in interfaceParameterList
- Parameters:
index
- the 1-based parameter index to bind.data
- an array containing the raw data valueoffset
- the offset withindata
of the start of the parameter data.length
- the number of bytes of parameter data withindata
to use.- Throws:
java.sql.SQLException
- on error or ifindex
is out of range
-
setBytea
public void setBytea(int index, java.io.InputStream stream, int length) throws java.sql.SQLException
Description copied from interface:ParameterList
Binds a binary bytea value stored as an InputStream. The parameter's type is implicitly set to 'bytea'. The stream should remain valid until query execution has completed.- Specified by:
setBytea
in interfaceParameterList
- Parameters:
index
- the 1-based parameter index to bind.stream
- a stream containing the parameter data.length
- the number of bytes of parameter data to read fromstream
.- Throws:
java.sql.SQLException
- on error or ifindex
is out of range
-
setBytea
public void setBytea(int index, java.io.InputStream stream) throws java.sql.SQLException
Description copied from interface:ParameterList
Binds a binary bytea value stored as an InputStream. The parameter's type is implicitly set to 'bytea'. The stream should remain valid until query execution has completed.- Specified by:
setBytea
in interfaceParameterList
- Parameters:
index
- the 1-based parameter index to bind.stream
- a stream containing the parameter data.- Throws:
java.sql.SQLException
- on error or ifindex
is out of range
-
setBytea
public void setBytea(int index, ByteStreamWriter writer) throws java.sql.SQLException
Description copied from interface:ParameterList
Binds a binary bytea value stored as a ByteStreamWriter. The parameter's type is implicitly set to 'bytea'. The stream should remain valid until query execution has completed.- Specified by:
setBytea
in interfaceParameterList
- Parameters:
index
- the 1-based parameter index to bind.writer
- a writer that can write the bytes for the parameter- Throws:
java.sql.SQLException
- on error or ifindex
is out of range
-
setText
public void setText(int index, java.io.InputStream stream) throws java.sql.SQLException
Description copied from interface:ParameterList
Binds a text value stored as an InputStream that is a valid UTF-8 byte stream. Any byte-order marks (BOM) in the stream are passed to the backend. The parameter's type is implicitly set to 'text'. The stream should remain valid until query execution has completed.- Specified by:
setText
in interfaceParameterList
- Parameters:
index
- the 1-based parameter index to bind.stream
- a stream containing the parameter data.- Throws:
java.sql.SQLException
- on error or ifindex
is out of range
-
setNull
public void setNull(int index, int oid) throws java.sql.SQLException
Description copied from interface:ParameterList
Binds a SQL NULL value to a parameter. Associated with the parameter is a typename for the parameter that should correspond to an entry in pg_types.- Specified by:
setNull
in interfaceParameterList
- Parameters:
index
- the 1-based parameter index to bind.oid
- the type OID of the parameter, or0
to infer the type.- Throws:
java.sql.SQLException
- on error or ifindex
is out of range
-
toString
public java.lang.String toString(int index, boolean standardConformingStrings)
Description copied from interface:ParameterList
Return a human-readable representation of a particular parameter in this ParameterList. If the parameter is not bound, returns "?".- Specified by:
toString
in interfaceParameterList
- Parameters:
index
- the 1-based parameter index to bind.standardConformingStrings
- true if \ is not an escape character in strings literals- Returns:
- a string representation of the parameter.
-
checkAllParametersSet
public void checkAllParametersSet() throws java.sql.SQLException
Description copied from interface:V3ParameterList
Ensure that all parameters in this list have been assigned values. Return silently if all is well, otherwise throw an appropriate exception.- Specified by:
checkAllParametersSet
in interfaceV3ParameterList
- Throws:
java.sql.SQLException
- if not all parameters are set.
-
convertFunctionOutParameters
public void convertFunctionOutParameters()
Description copied from interface:V3ParameterList
Convert any function output parameters to the correct type (void) and set an ignorable value for it.- Specified by:
convertFunctionOutParameters
in interfaceV3ParameterList
-
streamBytea
private static void streamBytea(PGStream pgStream, StreamWrapper wrapper) throws java.io.IOException
- Throws:
java.io.IOException
-
streamBytea
private static void streamBytea(PGStream pgStream, ByteStreamWriter writer) throws java.io.IOException
- Throws:
java.io.IOException
-
getTypeOIDs
public int[] getTypeOIDs()
Description copied from interface:ParameterList
Return the oids of the parameters in this list. May be null for a ParameterList that does not support typing of parameters.- Specified by:
getTypeOIDs
in interfaceParameterList
- Returns:
- oids of the parameters
-
getTypeOID
int getTypeOID(int index)
-
hasUnresolvedTypes
boolean hasUnresolvedTypes()
-
setResolvedType
void setResolvedType(int index, int oid)
-
isNull
boolean isNull(int index)
-
isBinary
boolean isBinary(int index)
-
direction
private byte direction(int index)
-
getV3Length
int getV3Length(int index)
-
writeV3Value
void writeV3Value(int index, PGStream pgStream) throws java.io.IOException
- Throws:
java.io.IOException
-
copy
public ParameterList copy()
Description copied from interface:ParameterList
Perform a shallow copy of this ParameterList, returning a new instance (still suitable for passing to the owning Query). If this ParameterList is immutable, copy() may return the same immutable object.- Specified by:
copy
in interfaceParameterList
- Returns:
- a new ParameterList instance
-
clear
public void clear()
Description copied from interface:ParameterList
Unbind all parameter values bound in this list.- Specified by:
clear
in interfaceParameterList
-
getSubparams
public SimpleParameterList[] getSubparams()
Description copied from interface:V3ParameterList
Return a list of the SimpleParameterList objects that make up this parameter list. If this object is already a SimpleParameterList, returns null (avoids an extra array construction in the common case).- Specified by:
getSubparams
in interfaceV3ParameterList
- Returns:
- an array of single-statement parameter lists, or
null
if this object is already a single-statement parameter list.
-
getValues
public java.lang.Object[] getValues()
Description copied from interface:ParameterList
Returns the bound parameter values.- Specified by:
getValues
in interfaceParameterList
- Returns:
- Object array containing the parameter values.
-
getParamTypes
public int[] getParamTypes()
Description copied from interface:V3ParameterList
Return the parameter type information.- Specified by:
getParamTypes
in interfaceV3ParameterList
- Returns:
- an array of
Oid
type information
-
getFlags
public byte[] getFlags()
Description copied from interface:V3ParameterList
Return the flags for each parameter.- Specified by:
getFlags
in interfaceV3ParameterList
- Returns:
- an array of bytes used to store flags.
-
getEncoding
public byte[][] getEncoding()
Description copied from interface:V3ParameterList
Return the encoding for each parameter.- Specified by:
getEncoding
in interfaceV3ParameterList
- Returns:
- nested byte array of bytes with encoding information.
-
appendAll
public void appendAll(ParameterList list) throws java.sql.SQLException
Description copied from interface:ParameterList
Use this operation to append more parameters to the current list.- Specified by:
appendAll
in interfaceParameterList
- Parameters:
list
- of parameters to append with.- Throws:
java.sql.SQLException
- fault raised if driver or back end throw an exception
-
toString
public java.lang.String toString()
Useful implementation of toString.- Overrides:
toString
in classjava.lang.Object
- Returns:
- String representation of the list values
-
-