TYPE
- The Java type represented by the column.public class GenericColumn<TYPE> extends Object
For the type it represents this class encapsulates
java.sql.PreparedStatement
java.sql.ResultSet
java.sql.Types
In addition to creating their own instances, users can access a number of implementations of this class that are provided as public static variables.
For example, to create a column for Integer
, do the following:
GenericColumn<Integer> integerColumn = new GenericColumn<>(
PreparedStatement::setInt,
ResultSet::getInt,
java.sql.Types.Integer);
Note that GenericColumn.Integer
is essentially that and can
simply be used directly.
Using a custom GenericColumn
is easy, as shown in the example above,
but greater care must be taken when using hrorm's facilities for validation (Validator
)
or schema generation (Schema
). For example, users may wish to create multiple instances of
this class that all support float
member variables, if there are a variety
of sizes of columns in their database, all represented by different SQL variable types.
Modifier and Type | Field and Description |
---|---|
static GenericColumn<BigDecimal> |
BIG_DECIMAL
An instance that supports
BigDecimal data elements. |
static GenericColumn<Boolean> |
BOOLEAN
An instance that supports
Boolean or boolean data elements. |
static GenericColumn<Byte> |
BYTE
An instance that supports
Byte or byte data elements. |
static GenericColumn<Double> |
DOUBLE
An instance that supports
Double or double data elements. |
static GenericColumn<Float> |
FLOAT
An instance that supports
Float or float data elements. |
static GenericColumn<Integer> |
INTEGER
An instance that supports
Integer or int data elements. |
static GenericColumn<Long> |
LONG
An instance that supports
Long or long data elements. |
static GenericColumn<String> |
STRING
An instance that supports
String data elements. |
static GenericColumn<Timestamp> |
TIMESTAMP
An instance that supports
Timestamp data elements. |
Constructor and Description |
---|
GenericColumn(org.hrorm.PreparedStatementSetter<TYPE> preparedStatementSetter,
ResultSetReader<TYPE> resultReader,
int sqlType)
Create a generic column instance to support the
TYPE . |
GenericColumn(org.hrorm.PreparedStatementSetter<TYPE> preparedStatementSetter,
ResultSetReader<TYPE> resultReader,
int sqlType,
String sqlTypeName)
Create a generic column instance to support the
TYPE . |
GenericColumn(org.hrorm.PreparedStatementSetter<TYPE> preparedStatementSetter,
ResultSetReader<TYPE> resultReader,
int sqlType,
String sqlTypeName,
Set<Integer> supportedTypes)
Create a generic column instance to support the
TYPE . |
Modifier and Type | Method and Description |
---|---|
TYPE |
fromResultSet(ResultSet resultSet,
String columnName) |
String |
getSqlTypeName() |
Set<Integer> |
getSupportedTypes() |
void |
setPreparedStatement(PreparedStatement preparedStatement,
int index,
TYPE value) |
int |
sqlType() |
GenericColumn<TYPE> |
withTypeName(String sqlTypeName)
Create a new instance with a new SQL type name to be used in a generated
schema.
|
public static GenericColumn<Long> LONG
Long
or long
data elements.public static GenericColumn<BigDecimal> BIG_DECIMAL
BigDecimal
data elements.public static GenericColumn<Boolean> BOOLEAN
Boolean
or boolean
data elements.public static GenericColumn<String> STRING
String
data elements.public static GenericColumn<Timestamp> TIMESTAMP
Timestamp
data elements.public static GenericColumn<Integer> INTEGER
Integer
or int
data elements.public static GenericColumn<Byte> BYTE
Byte
or byte
data elements.public static GenericColumn<Float> FLOAT
Float
or float
data elements.public static GenericColumn<Double> DOUBLE
Double
or double
data elements.public GenericColumn(org.hrorm.PreparedStatementSetter<TYPE> preparedStatementSetter, ResultSetReader<TYPE> resultReader, int sqlType)
TYPE
.preparedStatementSetter
- The method used to set the type onto a prepared statement.resultReader
- The method used to read the value out of a result set.sqlType
- The kind of this column type, as defined in java.sql.Types
public GenericColumn(org.hrorm.PreparedStatementSetter<TYPE> preparedStatementSetter, ResultSetReader<TYPE> resultReader, int sqlType, String sqlTypeName)
TYPE
.preparedStatementSetter
- The method used to set the type onto a prepared statement.resultReader
- The method used to read the value out of a result set.sqlType
- The kind of this column type, as defined in java.sql.Types
sqlTypeName
- The name of the type in the SQL schema. This optional value can be set
if you wish to generate your schema using a Schema
object.public GenericColumn(org.hrorm.PreparedStatementSetter<TYPE> preparedStatementSetter, ResultSetReader<TYPE> resultReader, int sqlType, String sqlTypeName, Set<Integer> supportedTypes)
TYPE
.preparedStatementSetter
- The method used to set the type onto a prepared statement.resultReader
- The method used to read the value out of a result set.sqlType
- The kind of this column type, as defined in java.sql.Types
sqlTypeName
- The name of the type in the SQL schema. This optional value can be set
if you wish to generate your schema using a Schema
object.supportedTypes
- All the database types, as defined in java.sql.Types
that this column can support.public GenericColumn<TYPE> withTypeName(String sqlTypeName)
sqlTypeName
- The name of this column type as represented in the
table create statement.public TYPE fromResultSet(ResultSet resultSet, String columnName) throws SQLException
SQLException
public void setPreparedStatement(PreparedStatement preparedStatement, int index, TYPE value) throws SQLException
SQLException
public int sqlType()
public String getSqlTypeName()
Copyright © 2019. All rights reserved.