public final class Binders extends java.lang.Object
DefaultBinderConfiguration
uses binders
returned by this class, based on the type of the parameter.Modifier and Type | Method and Description |
---|---|
static Binder |
dateBinder()
Returns a binder suitable for columns of type DATE.
|
static Binder |
decimalBinder()
Returns a binder suitable for numeric, decimal columns.
|
static Binder |
defaultBinder()
Returns the default binder.
|
static Binder |
integerBinder()
Returns a binder suitable for numeric, integer columns.
|
static Binder |
stringBinder()
Returns a binder suitable for columns of type CHAR and VARCHAR.
|
static Binder |
timeBinder()
Returns a binder suitable for columns of type TIME or TIME_WITH_TIMEZONE.
|
static Binder |
timestampBinder()
Returns a binder suitable for columns of type TIMESTAMP and TIMESTAMP_WITH_TIMEZONE.
|
public static Binder defaultBinder()
stmt.setObject()
to bind the parameter, except if the value being bound is of some
some well-known type not handled by JDBC:
enum
: the name of the enum is boundjava.util.Date
: the date is transformed to a java.sql.Timestamp
java.util.Calendar
: the calendar is transformed to a java.sql.Timestamp
,
and is passed as third argument of
PreparedStatement.setTimestamp()
to pass the timezonejava.time.LocalDate
: transformed to a java.sql.Date
java.time.LocalTime
: transformed to a java.sql.Time
java.time.LocalDateTime
: transformed to a java.sql.Timestamp
java.time.Instant
: transformed to a java.sql.Timestamp
java.time.ZonedDateTime
and OffsetDateTime
: transformed to a
java.sql.Timestamp
. The time zone is also used to create a Calendar
passed as
third argument of PreparedStatement.setTimestamp()
to pass the timezonejava.time.OffsetTime
: transformed to a
java.sql.Time
. The time zone is also used to create a Calendar
passed as third
argument of PreparedStatement.setTime()
to pass the timezonepublic static Binder stringBinder()
String
enum
: the name of the enum is used as bound valueObject
: the toString()
of the object is used as bound valuepublic static Binder dateBinder()
java.sql.Date
java.util.Date
: the milliseconds of the date are used to construct a
java.sql.Date
.java.util.Calendar
: the milliseconds of the calendar are used to construct a
java.sql.Date
, and the calendar is passed as third argument of
PreparedStatement.setDate()
to pass the timezone
String
: the string is transformed to a java.sql.Date using the Date.valueOf()
methodjava.time.LocalDate
: transformed to a java.sql.Date
using
Date.valueOf()
java.time.LocalDateTime
: transformed to a LocalDate (and thus ignoring the time),
and then transformed to a java.sql.Date
using Date.valueOf()
java.time.Instant
the milliseconds of the instant are used to construct a
java.sql.Date
.java.time.ZonedDateTime
and java.time.OffsetDateTime
: transformed to an Instant
and then to a java.sql.Date
. The time zone is also used to create a Calendar
passed as third argument of PreparedStatement.setDate()
to pass the timezonestmt.setObject()
is used to bind the value.public static Binder timestampBinder()
java.sql.Timestamp
java.util.Date
: the milliseconds of the date are used to construct a
java.sql.Timestamp
java.util.Calendar
: the milliseconds of the calendar are used to construct a
java.sql.Timestamp
, and the calendar is passed as third argument of
PreparedStatement.setTimestamp()
to pass the timezoneString
: the string is transformed to a java.sql.Timestamp
using the
Timestamp.valueOf()
method, or using the java.sql.Date.valueOf()
method if the
string has less than 19 charactersjava.time.LocalDateTime
: transformed to a java.sql.Timestamp
using
Timestamp.valueOf()
java.time.LocalDate
: transformed to a LocalDateTime with the time at start of day,
and then transformed to a java.sql.Timestamp
using Timestamp.valueOf()
java.time.Instant
: transformed to a java.sql.Timestamp
using
Timestamp.from()
java.time.ZonedDateTime
and java.time.OffsetDateTime
: transformed to an Instant
and then to a java.sql.Timestamp
using Timestamp.from()
. The time zone is also
used to create a Calendar
passed as third argument of
PreparedStatement.setTimestamp()
to pass the timezonestmt.setObject()
is used to bind the value.public static Binder timeBinder()
java.sql.Time
java.util.Date
: the milliseconds of the date are used to construct a
java.sql.Time
java.util.Calendar
: the milliseconds of the calendar are used to construct a
java.sql.Time
, and the calendar is passed as third argument of
PreparedStatement.setTimestamp()
to pass the timezone
String
: the string is transformed to a java.sql.Time using the
Time.valueOf()
methodjava.time.LocalTime
: transformed to a java.sql.Time
using
Time.valueOf()
java.time.OffsetTime
: transformed to a LocalTime
and then to a
java.sql.Time
using Time.valueOf()
. The time zone is also
used to create a Calendar
passed as third argument of
PreparedStatement.setTime()
to pass the timezonestmt.setObject()
is used to bind the value.public static Binder decimalBinder()
String
: the string is transformed to a java.math.BigDecimal using its constructorstmt.setObject()
is used to bind the value.public static Binder integerBinder()
BigInteger
: the object is transformed to a String and bound using
stmt.setObject()
, with BIGINT
as target type.
enum
: the enum is transformed into an integer by taking its ordinalString
: the string is bound using stmt.setObject()
, with BIGINT
as
target type.
stmt.setObject()
is used to bind the value.