public abstract class JDBCHelper extends Object
Constructor and Description |
---|
JDBCHelper() |
Modifier and Type | Method and Description |
---|---|
static String |
formatIsolationLevel(int isolationLevel)
Format the transaction isolation level constants as a string.
|
static Boolean |
getBoolean(ResultSet rs,
int columnIndex) |
static Boolean |
getBoolean(ResultSet rs,
String columnLabel) |
static Byte |
getByte(ResultSet rs,
int columnIndex) |
static Byte |
getByte(ResultSet rs,
String columnLabel) |
static Double |
getDouble(ResultSet rs,
int columnIndex) |
static Double |
getDouble(ResultSet rs,
String columnLabel) |
static <T extends Enum<T>> |
getEnum(ResultSet rs,
int pos,
Class<T> clazz)
Fetch an enum value from an integer column of a result set interpreted
as the ordinal of the given enum class.
|
static Float |
getFloat(ResultSet rs,
int columnIndex) |
static Float |
getFloat(ResultSet rs,
String columnLabel) |
static org.clazzes.util.aop.i18n.I18nString |
getI18nString(ResultSet resultSet,
int columnIndex)
Returns an I18nString based on the value for the given column in the given ResultSet
(which is expected to be a string).
|
static Integer |
getInt(ResultSet rs,
int columnIndex) |
static Integer |
getInt(ResultSet rs,
String columnLabel) |
static Long |
getLong(ResultSet rs,
int columnIndex) |
static Long |
getLong(ResultSet rs,
String columnLabel) |
static Short |
getShort(ResultSet rs,
int columnIndex) |
static Short |
getShort(ResultSet rs,
String columnLabel) |
static Double |
getUtcSeconds(ResultSet resultSet,
int columnIndex)
Helper function for the case, that utc seconds are stored in Java code in an attribute of type Double,
and mapped to a database column of type e.g. date, datetime or timestamp.
|
static boolean |
isI18nMapString(String s)
Returns wether the given String is a valid I18nString serialization, something like {"de" : "Deutsche Übersetzung", "en" : "English translation" }.
|
static org.clazzes.util.aop.i18n.I18nString |
parseI18nString(String databaseString)
Parses the given databaseString as I18nString.
|
static void |
setBoolean(PreparedStatement ps,
int parameterIndex,
Boolean b)
Call
ps.setBoolean(parameterIndex,b.booleanValue()) or
ps.setNull(parameterIndex,Types.BOOLEAN) when b
is null . |
static void |
setByte(PreparedStatement ps,
int parameterIndex,
Number b)
Call
ps.setByte(parameterIndex,b.byteValue()) or
ps.setNull(parameterIndex,Types.TINYINT) when b
is null . |
static void |
setDouble(PreparedStatement ps,
int parameterIndex,
Number d)
Call
ps.setDouble(parameterIndex,d.doubleValue()) or
ps.setNull(parameterIndex,Types.DOUBLE) when b
is null . |
static <T extends Enum<T>> |
setEnum(PreparedStatement statement,
int pos,
T val)
Set an enum value as an integer parameter to a prepared statement
using the ordinal of an enum value.
|
static void |
setFloat(PreparedStatement ps,
int parameterIndex,
Number f)
Call
ps.setFloat(parameterIndex,f.floatValue()) or
ps.setNull(parameterIndex,Types.FLOAT) when b
is null . |
static void |
setI18nString(PreparedStatement statement,
int parameterIndex,
org.clazzes.util.aop.i18n.I18nString i18nString) |
static void |
setInt(PreparedStatement ps,
int parameterIndex,
Number i)
Call
ps.setInt(parameterIndex,i.intValue()) or
ps.setNull(parameterIndex,Types.INTEGER) when b
is null . |
static void |
setLong(PreparedStatement ps,
int parameterIndex,
Number l)
Call
ps.setLong(parameterIndex,l.longValue()) or
ps.setNull(parameterIndex,Types.BIGINT) when b
is null . |
static void |
setShort(PreparedStatement ps,
int parameterIndex,
Number s)
Call
ps.setShort(parameterIndex,s.shortValue()) or
ps.setNull(parameterIndex,Types.SMALLINT) when b
is null . |
static void |
setUtcSeconds(PreparedStatement statement,
int parameterIndex,
Double utcSeconds)
Helper function for the case, that utc seconds are stored in Java code in an attribute of type Double,
and mapped to a database column of type e.g. date, datetime or timestamp.
|
public static final String formatIsolationLevel(int isolationLevel)
isolationLevel
- A transaction isolation level constant.Connection.TRANSACTION_NONE
,
Connection.TRANSACTION_READ_UNCOMMITTED
,
Connection.TRANSACTION_READ_COMMITTED
,
Connection.TRANSACTION_REPEATABLE_READ
,
Connection.TRANSACTION_SERIALIZABLE
public static Boolean getBoolean(ResultSet rs, int columnIndex) throws SQLException
rs
- A result set.columnIndex
- The column index of the column to get;
the first column has the index 1.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Boolean getBoolean(ResultSet rs, String columnLabel) throws SQLException
rs
- A result set.columnLabel
- The column label of the column to get.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Byte getByte(ResultSet rs, int columnIndex) throws SQLException
rs
- A result set.columnIndex
- The column index of the column to get;
the first column has the index 1.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Byte getByte(ResultSet rs, String columnLabel) throws SQLException
rs
- A result set.columnLabel
- The column label of the column to get.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Short getShort(ResultSet rs, int columnIndex) throws SQLException
rs
- A result set.columnIndex
- The column index of the column to get;
the first column has the index 1.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Short getShort(ResultSet rs, String columnLabel) throws SQLException
rs
- A result set.columnLabel
- The column label of the column to get.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Integer getInt(ResultSet rs, int columnIndex) throws SQLException
rs
- A result set.columnIndex
- The column index of the column to get;
the first column has the index 1.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Integer getInt(ResultSet rs, String columnLabel) throws SQLException
rs
- A result set.columnLabel
- The column label of the column to get.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Long getLong(ResultSet rs, int columnIndex) throws SQLException
rs
- A result set.columnIndex
- The column index of the column to get;
the first column has the index 1.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Long getLong(ResultSet rs, String columnLabel) throws SQLException
rs
- A result set.columnLabel
- The column label of the column to get.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Float getFloat(ResultSet rs, int columnIndex) throws SQLException
rs
- A result set.columnIndex
- The column index of the column to get;
the first column has the index 1.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Float getFloat(ResultSet rs, String columnLabel) throws SQLException
rs
- A result set.columnLabel
- The column label of the column to get.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Double getDouble(ResultSet rs, int columnIndex) throws SQLException
rs
- A result set.columnIndex
- The column index of the column to get;
the first column has the index 1.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Double getDouble(ResultSet rs, String columnLabel) throws SQLException
rs
- A result set.columnLabel
- The column label of the column to get.null
, if
ResultSet.wasNull()
returned true
.SQLException
- Upon errors.public static Double getUtcSeconds(ResultSet resultSet, int columnIndex) throws SQLException
resultSet
- the resultSetcolumnIndex
- the column index of the column to get; the first column has the index 1.SQLException
public static boolean isI18nMapString(String s)
s
- any Stringpublic static org.clazzes.util.aop.i18n.I18nString parseI18nString(String databaseString)
databaseString
- not null, and isI18nMapString(databaseString) returns trueIllegalArgumentException
- if string is malformed (no complete check for each kind of malformedness), or
if some language occurs multiple timespublic static org.clazzes.util.aop.i18n.I18nString getI18nString(ResultSet resultSet, int columnIndex) throws SQLException
resultSet
- ResultSetcolumnIndex
- columnSQLException
- if something goes wrongpublic static void setBoolean(PreparedStatement ps, int parameterIndex, Boolean b) throws SQLException
ps.setBoolean(parameterIndex,b.booleanValue())
or
ps.setNull(parameterIndex,Types.BOOLEAN)
when b
is null
.ps
- A prepared statement.parameterIndex
- The index of the placeholder in the statement to fill;
the first placeholder has the index 1.b
- A Boolean object.SQLException
- Upon errors.public static void setByte(PreparedStatement ps, int parameterIndex, Number b) throws SQLException
ps.setByte(parameterIndex,b.byteValue())
or
ps.setNull(parameterIndex,Types.TINYINT)
when b
is null
.ps
- A prepared statement.parameterIndex
- The index of the placeholder in the statement to fill;
the first placeholder has the index 1.b
- A Byte object.SQLException
- Upon errors.public static void setShort(PreparedStatement ps, int parameterIndex, Number s) throws SQLException
ps.setShort(parameterIndex,s.shortValue())
or
ps.setNull(parameterIndex,Types.SMALLINT)
when b
is null
.ps
- A prepared statement.parameterIndex
- The index of the placeholder in the statement to fill;
the first placeholder has the index 1.s
- A Short object.SQLException
- Upon errors.public static void setInt(PreparedStatement ps, int parameterIndex, Number i) throws SQLException
ps.setInt(parameterIndex,i.intValue())
or
ps.setNull(parameterIndex,Types.INTEGER)
when b
is null
.ps
- A prepared statement.parameterIndex
- The index of the placeholder in the statement to fill;
the first placeholder has the index 1.i
- An Integer object.SQLException
- Upon errors.public static void setLong(PreparedStatement ps, int parameterIndex, Number l) throws SQLException
ps.setLong(parameterIndex,l.longValue())
or
ps.setNull(parameterIndex,Types.BIGINT)
when b
is null
.ps
- A prepared statement.parameterIndex
- The index of the placeholder in the statement to fill;
the first placeholder has the index 1.l
- A Long object.SQLException
- Upon errors.public static void setFloat(PreparedStatement ps, int parameterIndex, Number f) throws SQLException
ps.setFloat(parameterIndex,f.floatValue())
or
ps.setNull(parameterIndex,Types.FLOAT)
when b
is null
.ps
- A prepared statement.parameterIndex
- The index of the placeholder in the statement to fill;
the first placeholder has the index 1.f
- A Float object.SQLException
- Upon errors.public static void setDouble(PreparedStatement ps, int parameterIndex, Number d) throws SQLException
ps.setDouble(parameterIndex,d.doubleValue())
or
ps.setNull(parameterIndex,Types.DOUBLE)
when b
is null
.ps
- A prepared statement.parameterIndex
- The index of the placeholder in the statement to fill;
the first placeholder has the index 1.d
- A Double object.SQLException
- Upon errors.public static void setUtcSeconds(PreparedStatement statement, int parameterIndex, Double utcSeconds) throws SQLException
statement
- statementparameterIndex
- The index of the placeholder in the statement to fill;
the first placeholder has the index 1.utcSeconds
- utc seconds as a Double object, can be nullSQLException
- upon errorspublic static void setI18nString(PreparedStatement statement, int parameterIndex, org.clazzes.util.aop.i18n.I18nString i18nString) throws SQLException
SQLException
public static <T extends Enum<T>> void setEnum(PreparedStatement statement, int pos, T val) throws SQLException
null
,
statement.setNull(pos,Types.INTEGER)
is performed.statement
- A prepared statement.pos
- The parameterIndexval
- The enum value to set.SQLException
- Upon DB errors.public static <T extends Enum<T>> T getEnum(ResultSet rs, int pos, Class<T> clazz) throws SQLException
rs
- The result set to get the enum from.pos
- The index of the value to get.clazz
- The class of the requested enum value.null
, if the column of the result set was null.SQLException
- Upon DB errors.Copyright © 2017 Clazzes.org. All rights reserved.