public class TypeManager
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,java.util.function.BiFunction<java.sql.Connection,byte[],java.sql.Blob>> |
blobCreators
Dialect-specific functions to create a
Blob instance. |
private static java.util.Map<java.lang.String,java.util.function.BiFunction<java.sql.Connection,java.lang.String,java.sql.Clob>> |
clobCreators
Dialect-specific functions to create a
Clob instance. |
private static java.util.Map<java.lang.Class<?>,ParameterSetter> |
paramSetters
The registry with all known parameter type handlers.
|
private static java.util.Map<java.lang.Class<? extends BaseDataType>,DataHandler> |
typeHelpers
The registry with all known converters.
|
Constructor and Description |
---|
TypeManager() |
Modifier and Type | Method and Description |
---|---|
static void |
addBlobCreator(java.lang.String url,
java.util.function.BiFunction<java.sql.Connection,byte[],java.sql.Blob> blobCreator)
Add a dialect-specific function to create a
Blob instance. |
static void |
addClobCreator(java.lang.String url,
java.util.function.BiFunction<java.sql.Connection,java.lang.String,java.sql.Clob> clobCreator)
Add a dialect-specific function to create a
Clob instance. |
static DataHandler |
getDataHandler(java.lang.Class<? extends BaseDataType> type)
Gets a converter for a specific target
BaseDataType . |
static ParameterSetter |
getTypeHandler(java.lang.Class<?> type)
Gets a parameter handler for a specific type.
|
private static java.lang.String |
prepareUrl(java.lang.String url)
String the JDBC URL's options.
|
(package private) static int |
setBigDecimalParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
BigDecimal to a parameter in a PreparedStatement . |
(package private) static int |
setBlobParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
Blob to a parameter in a PreparedStatement . |
(package private) static int |
setBooleanParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
Boolean to a parameter in a PreparedStatement . |
(package private) static int |
setByteArrayParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
byte array to a parameter in a PreparedStatement . |
(package private) static int |
setClobParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
Clob to a parameter in a PreparedStatement . |
(package private) static int |
setDateParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
java.util.Date to a parameter in a
PreparedStatement . |
(package private) static int |
setDoubleParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
Double to a parameter in a PreparedStatement . |
(package private) static int |
setFloatParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
Float to a parameter in a PreparedStatement . |
private static int |
setFwdBlobParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
blob object and use it to initialize a parameter of type
blob in a SQL prepared query. |
private static int |
setFwdCharacterParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
character object and use it to initialize a parameter of
type char in a SQL prepared query. |
private static int |
setFwdClobParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
clob object and use it to initialize a parameter of type
clob in a SQL prepared query. |
private static int |
setFwdComhandleParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
comhandle object and use it to initialize a parameter of
type comhandle in a SQL prepared query. |
private static int |
setFwdDateParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
date object and use it to initialize a parameter of type
date in a SQL prepared query. |
private static int |
setFwdDatetimeParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
datetime object and use it to initialize a parameter of
type datetime in a SQL prepared query. |
private static int |
setFwdDatetimetzParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
datetimetz object and use it to initialize a parameter of
type datetimetz in a SQL prepared query. |
private static int |
setFwdDecimalParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
decimal object and use it to initialize a parameter of type
decimal in a SQL prepared query. |
private static int |
setFwdHandleParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
handle object and use it to initialize a parameter of type
handle in a SQL prepared query. |
private static int |
setFwdInt64Parameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from an
int64 object and use it to initialize a parameter of type
int64 in a SQL prepared query. |
private static int |
setFwdIntegerParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from an
integer object and use it to initialize a parameter of type
integer in a SQL prepared query. |
private static int |
setFwdLogicalParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
logical object and use it to initialize a parameter of type
logical in a SQL prepared query. |
private static int |
setFwdObjectParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from an
object object and use it to initialize a parameter of type
object in a SQL prepared query. |
private static int |
setFwdRawParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
raw object and use it to initialize a parameter of type
raw in a SQL prepared query. |
private static int |
setFwdRecidParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
recid object and use it to initialize a parameter of type
recid in a SQL prepared query. |
private static int |
setFwdRowidParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Extracts the data from a
rowid object and use it to initialize a parameter of type
rowid in a SQL prepared query. |
(package private) static int |
setIntegerParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
Integer to a parameter in a PreparedStatement . |
(package private) static int |
setLongParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
Long to a parameter in a PreparedStatement . |
(package private) static int |
setOffsetDateTimeParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
OffsetDateTime to a parameter in a
PreparedStatement . |
(package private) static int |
setSqlDateParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
java.sql.Date to a parameter in a
PreparedStatement . |
(package private) static int |
setStringParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
String to a parameter in a PreparedStatement . |
(package private) static int |
setTimestampParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
Timestamp to a parameter in a PreparedStatement . |
(package private) static int |
setUtilDateParameter(java.sql.PreparedStatement stmt,
int index,
java.lang.Object val)
Sets a value assumed of type
java.util.Date to a parameter in a
PreparedStatement . |
private static final java.util.Map<java.lang.Class<? extends BaseDataType>,DataHandler> typeHelpers
Converter
and ParameterSetter
, they will act in both direction, converting pieces of data
coming from SQL to BDT values and vice-versa.private static final java.util.Map<java.lang.Class<?>,ParameterSetter> paramSetters
ParameterSetter
implementations allow the converted value to be set as parameter to a provided
PreparedStatement
.private static final java.util.Map<java.lang.String,java.util.function.BiFunction<java.sql.Connection,byte[],java.sql.Blob>> blobCreators
Blob
instance.private static final java.util.Map<java.lang.String,java.util.function.BiFunction<java.sql.Connection,java.lang.String,java.sql.Clob>> clobCreators
Clob
instance.public static ParameterSetter getTypeHandler(java.lang.Class<?> type)
ParameterSetter
expects a
BaseDataType
of type
type to be passed as the 3rd argument to its
setParameter
when the method is invoked.type
- The type of the argument that needs to be set in a PreparedStatement
.public static DataHandler getDataHandler(java.lang.Class<? extends BaseDataType> type)
BaseDataType
.type
- The the class to which the conversion needs to be performed.Converter
that will handle conversion to the requested type.public static void addBlobCreator(java.lang.String url, java.util.function.BiFunction<java.sql.Connection,byte[],java.sql.Blob> blobCreator)
Blob
instance.url
- The JDBC URL for the database connection.blobCreator
- The dialect-specific function to create a Blob
instance.public static void addClobCreator(java.lang.String url, java.util.function.BiFunction<java.sql.Connection,java.lang.String,java.sql.Clob> clobCreator)
Clob
instance.url
- The JDBC URL for the database connection.clobCreator
- The dialect-specific function to create a Clob
instance.static int setIntegerParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
Integer
to a parameter in a PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type Integer
.java.sql.SQLException
- when an error is encountered.static int setLongParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
Long
to a parameter in a PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type Long
.java.sql.SQLException
- when an error is encountered.static int setStringParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
String
to a parameter in a PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type String
.java.sql.SQLException
- when an error is encountered.static int setBooleanParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
Boolean
to a parameter in a PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type Boolean
.java.sql.SQLException
- when an error is encountered.static int setDoubleParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
Double
to a parameter in a PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type Double
.java.sql.SQLException
- when an error is encountered.static int setFloatParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
Float
to a parameter in a PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type Float
.java.sql.SQLException
- when an error is encountered.static int setBlobParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
Blob
to a parameter in a PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type Blob
.java.sql.SQLException
- when an error is encountered.static int setClobParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
Clob
to a parameter in a PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type Clob
.java.sql.SQLException
- when an error is encountered.static int setDateParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
java.util.Date
to a parameter in a
PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type java.util.Date
.java.sql.SQLException
- when an error is encountered.static int setBigDecimalParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
BigDecimal
to a parameter in a PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type BigDecimal
.java.sql.SQLException
- when an error is encountered.static int setByteArrayParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
byte
array to a parameter in a PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type byte
array.java.sql.SQLException
- when an error is encountered.static int setUtilDateParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
java.util.Date
to a parameter in a
PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type java.util.Date
.java.sql.SQLException
- when an error is encountered.static int setTimestampParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
Timestamp
to a parameter in a PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type Timestamp
.java.sql.SQLException
- when an error is encountered.static int setSqlDateParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
java.sql.Date
to a parameter in a
PreparedStatement
.stmt
- The PreparedStatement
to receive the parameter.index
- The position of the parameter in the statement.val
- The value to be set, assumed to be of type java.sql.Date
.java.sql.SQLException
- when an error is encountered.static int setOffsetDateTimeParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
OffsetDateTime
to a parameter in a
PreparedStatement
.
Note:DataHandler
is the only one that fills in two parameters in a
prepared statement.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameters.val
- The value of the parameter. Must be a OffsetDateTime
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdRawParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
raw
object and use it to initialize a parameter of type
raw in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a raw
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdObjectParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
object
object and use it to initialize a parameter of type
object in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a object
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdLogicalParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
logical
object and use it to initialize a parameter of type
logical in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a logical
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdIntegerParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
integer
object and use it to initialize a parameter of type
integer in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a integer
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdInt64Parameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
int64
object and use it to initialize a parameter of type
int64 in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a int64
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdHandleParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
handle
object and use it to initialize a parameter of type
handle in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a handle
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdDecimalParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
decimal
object and use it to initialize a parameter of type
decimal in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a decimal
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdDateParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
date
object and use it to initialize a parameter of type
date in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a date
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdDatetimeParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
datetime
object and use it to initialize a parameter of
type datetime in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a datetime
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdDatetimetzParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
datetimetz
object and use it to initialize a parameter of
type datetimetz in a SQL prepared query.
Note:
This implementation of DataHandler
is the only one that fills in two parameters in a
prepared statement.
stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameters.val
- The value of the parameter. Must be a datetimetz
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdComhandleParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
comhandle
object and use it to initialize a parameter of
type comhandle in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a comhandle
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdClobParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
clob
object and use it to initialize a parameter of type
clob in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a clob
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdCharacterParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
character
object and use it to initialize a parameter of
type char in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a character
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdBlobParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
blob
object and use it to initialize a parameter of type
blob in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a blob
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdRecidParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
recid
object and use it to initialize a parameter of type
recid in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a recid
.java.sql.SQLException
- when an error is encountered while setting the value.private static int setFwdRowidParameter(java.sql.PreparedStatement stmt, int index, java.lang.Object val) throws java.sql.SQLException
rowid
object and use it to initialize a parameter of type
rowid in a SQL prepared query.stmt
- The prepared statement whose the parameter is to be set.index
- The index/position of the parameter.val
- The value of the parameter. Must be a rowid
.java.sql.SQLException
- when an error is encountered while setting the value.private static java.lang.String prepareUrl(java.lang.String url)
url
- The JDBC URL.