public static enum SqlJdbcUtil.FieldType extends Enum<SqlJdbcUtil.FieldType>
Each field type expresses the type of data that the get and
GenericEntity.set(String, Object) methods will expect to work with. For example, if
the field type is TIMESTAMP, then it expects java.sql.Timestamp values to be
provided to set and will use ResultSet.getTimestamp(int) to obtain the values
when reading them from the database.
Exactly how these map to actual database types is defined by the field types XML for that
particular database. In short, the mapping process is that entitymodel.xml defines
the field and specifies its model type, which is something like "long-varchar".
The fieldtype-mydbtype.xml file then maps this to a Java type and database type.
For example:
<!-- From entitymodel.xml -->
<field name="lowerUserName" col-name="lower_user_name" type="long-varchar" />
<!-- From fieldtype-mysql.xml -->
<field-type-def type="long-varchar" sql-type="VARCHAR(255)" java-type="String" />
So the field "lowerUserName" on this entity maps to the "long-varchar" ModelFieldType.
That returns "VARCHAR(255)" for ModelFieldType.getSqlType() and this is what gets used in
the database schema. It returns "String" for ModelFieldType.getJavaType(), and
SqlJdbcUtil.getFieldType(String) maps that to STRING. This is what tells GenericEntity
and SQLProcessor to use ResultSet.getString(int) and
PreparedStatement.setString(int, String) to interact with the database storage and to use
String objects internally.
It's convoluted, especially when you realize that there are four different things you can mean when talking about a field's "type", but it mostly works. :P
| Enum Constant and Description |
|---|
BLOB
The database field is a
BLOB or whatever the nearest equivalent is. |
BOOLEAN
The database field can hold a boolean value.
|
BYTE_ARRAY
The database field holds arbitrary binary data.
|
CLOB
The database field is a
CLOB or whatever the nearest equivalent is. |
DATE
The database field type maps to
Date. |
DOUBLE
The database field has a floating-point decimal type with sufficient precision to hold
double values. |
FLOAT
The database field has a floating-point decimal type with sufficient precision to hold
float values. |
INTEGER
The database field has an integer type with sufficient precision to hold
int values. |
LONG
The database field has an integer type with sufficient precision to hold
long values. |
OBJECT
The database field holds serialized Object data.
|
STRING
The underlying field type is something like VARCHAR or TEXT that can hold variable-length
character data.
|
TIME
The database field type maps to
Time. |
TIMESTAMP
The database field type maps to
Timestamp. |
| Modifier and Type | Method and Description |
|---|---|
int |
getOldTypeNumber()
Returns the old hardcoded type number that is associated with this field type, such as
5 for
INTEGER. |
boolean |
matches(String javaType)
Returns
true if the specified java type corresponds to this field type. |
static SqlJdbcUtil.FieldType |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static SqlJdbcUtil.FieldType[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final SqlJdbcUtil.FieldType STRING
public static final SqlJdbcUtil.FieldType TIMESTAMP
Timestamp.public static final SqlJdbcUtil.FieldType TIME
Time.public static final SqlJdbcUtil.FieldType DATE
Date.public static final SqlJdbcUtil.FieldType INTEGER
int values.public static final SqlJdbcUtil.FieldType LONG
long values.public static final SqlJdbcUtil.FieldType FLOAT
float values.public static final SqlJdbcUtil.FieldType DOUBLE
double values.public static final SqlJdbcUtil.FieldType BOOLEAN
BOOLEAN
column, but some databases do not have this type and emulate it with something else, such as a
TINYINT on MySQL.public static final SqlJdbcUtil.FieldType OBJECT
BYTEA for Postgres and IMAGE for SqlServer. The bytes
stored are the serialized form of the object assigned to the field, and the value is implicitly
deserialized when the value is read back in. Classes are loaded using the default behaviour of
ObjectInputStream.resolveClass(ObjectStreamClass), and no mechanism is exposed for changing
this behaviour. If your field requires any kind of customized serialization, then BYTE_ARRAY
should be preferred.public static final SqlJdbcUtil.FieldType CLOB
CLOB or whatever the nearest equivalent is.public static final SqlJdbcUtil.FieldType BLOB
BLOB or whatever the nearest equivalent is. BLOB field support
is untested and probably incomplete.public static final SqlJdbcUtil.FieldType BYTE_ARRAY
BYTEA for Postgres and IMAGE for SqlServer. Unlike
OBJECT, this type does not perform any implicit serialization or deserialization of
its data.public static SqlJdbcUtil.FieldType[] values()
for (SqlJdbcUtil.FieldType c : SqlJdbcUtil.FieldType.values()) System.out.println(c);
public static SqlJdbcUtil.FieldType valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic int getOldTypeNumber()
5 for
INTEGER.
The use of magic numbers to communicate this information is error-prone and heavily discouraged. Stick
with the FieldType enum itself wherever possible.
public boolean matches(String javaType)
true if the specified java type corresponds to this field type.
Calling fieldType.matches(javaType) is equivalent to fieldType == getFieldType(javaType),
except that it does not throw an exception when javaType is null or unrecognized.javaType - the proposed java typetrue if the specified java type corresponds to this field type; false otherwise.Copyright © 2016 Atlassian. All rights reserved.