Enum Class SqlJdbcUtil.FieldType
- All Implemented Interfaces:
Serializable,Comparable<SqlJdbcUtil.FieldType>,Constable
- Enclosing class:
- SqlJdbcUtil
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
- Since:
- 1.1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe database field is aBLOBor whatever the nearest equivalent is.The database field can hold a boolean value.The database field holds arbitrary binary data.The database field is aCLOBor whatever the nearest equivalent is.The database field type maps toDate.The database field has a floating-point decimal type with sufficient precision to holddoublevalues.The database field has a floating-point decimal type with sufficient precision to holdfloatvalues.The database field has an integer type with sufficient precision to holdintvalues.The database field has an integer type with sufficient precision to holdlongvalues.The database field holds serialized Object data.The underlying field type is something like VARCHAR or TEXT that can hold variable-length character data.The database field type maps toTime.The database field type maps toTimestamp. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the old hardcoded type number that is associated with this field type, such as5forINTEGER.booleanReturnstrueif the specified java type corresponds to this field type.static SqlJdbcUtil.FieldTypeReturns the enum constant of this class with the specified name.static SqlJdbcUtil.FieldType[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
STRING
The underlying field type is something like VARCHAR or TEXT that can hold variable-length character data. -
TIMESTAMP
The database field type maps toTimestamp. -
TIME
The database field type maps toTime. -
DATE
The database field type maps toDate. -
INTEGER
The database field has an integer type with sufficient precision to holdintvalues. -
LONG
The database field has an integer type with sufficient precision to holdlongvalues. -
FLOAT
The database field has a floating-point decimal type with sufficient precision to holdfloatvalues. -
DOUBLE
The database field has a floating-point decimal type with sufficient precision to holddoublevalues. -
BOOLEAN
The database field can hold a boolean value. On most databases that just means it is aBOOLEANcolumn, but some databases do not have this type and emulate it with something else, such as aTINYINTon MySQL. -
OBJECT
The database field holds serialized Object data. The underlying database type is a BLOB on most databases; however, it isBYTEAfor Postgres andIMAGEfor 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 ofObjectInputStream.resolveClass(ObjectStreamClass), and no mechanism is exposed for changing this behaviour. If your field requires any kind of customized serialization, thenBYTE_ARRAYshould be preferred. -
CLOB
The database field is aCLOBor whatever the nearest equivalent is. -
BLOB
The database field is aBLOBor whatever the nearest equivalent is. BLOB field support is untested and probably incomplete. -
BYTE_ARRAY
The database field holds arbitrary binary data. The underlying database type is a BLOB on most databases; however, it isBYTEAfor Postgres andIMAGEfor SqlServer. UnlikeOBJECT, this type does not perform any implicit serialization or deserialization of its data.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getOldTypeNumber
public int getOldTypeNumber()Returns the old hardcoded type number that is associated with this field type, such as5forINTEGER.The use of magic numbers to communicate this information is error-prone and heavily discouraged. Stick with the
FieldTypeenum itself wherever possible.- Returns:
- the old hardcoded type number that is associated with this field type.
-
matches
Returnstrueif the specified java type corresponds to this field type. CallingfieldType.matches(javaType)is equivalent tofieldType == getFieldType(javaType), except that it does not throw an exception whenjavaTypeisnullor unrecognized.- Parameters:
javaType- the proposed java type- Returns:
trueif the specified java type corresponds to this field type;falseotherwise.
-