Enum Class SqlJdbcUtil.FieldType

java.lang.Object
java.lang.Enum<SqlJdbcUtil.FieldType>
org.ofbiz.core.entity.jdbc.SqlJdbcUtil.FieldType
All Implemented Interfaces:
Serializable, Comparable<SqlJdbcUtil.FieldType>, Constable
Enclosing class:
SqlJdbcUtil

public static enum SqlJdbcUtil.FieldType extends Enum<SqlJdbcUtil.FieldType>
An enumeration of the various data types supported by the entity engine.

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 Constants
    Enum Constant
    Description
    The database field is a BLOB or whatever the nearest equivalent is.
    The database field can hold a boolean value.
    The database field holds arbitrary binary data.
    The database field is a CLOB or whatever the nearest equivalent is.
    The database field type maps to Date.
    The database field has a floating-point decimal type with sufficient precision to hold double values.
    The database field has a floating-point decimal type with sufficient precision to hold float values.
    The database field has an integer type with sufficient precision to hold int values.
    The database field has an integer type with sufficient precision to hold long values.
    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 to Time.
    The database field type maps to Timestamp.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    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.
    Returns the enum constant of this class with the specified name.
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • STRING

      public static final SqlJdbcUtil.FieldType STRING
      The underlying field type is something like VARCHAR or TEXT that can hold variable-length character data.
    • TIMESTAMP

      public static final SqlJdbcUtil.FieldType TIMESTAMP
      The database field type maps to Timestamp.
    • TIME

      public static final SqlJdbcUtil.FieldType TIME
      The database field type maps to Time.
    • DATE

      public static final SqlJdbcUtil.FieldType DATE
      The database field type maps to Date.
    • INTEGER

      public static final SqlJdbcUtil.FieldType INTEGER
      The database field has an integer type with sufficient precision to hold int values.
    • LONG

      public static final SqlJdbcUtil.FieldType LONG
      The database field has an integer type with sufficient precision to hold long values.
    • FLOAT

      public static final SqlJdbcUtil.FieldType FLOAT
      The database field has a floating-point decimal type with sufficient precision to hold float values.
    • DOUBLE

      public static final SqlJdbcUtil.FieldType DOUBLE
      The database field has a floating-point decimal type with sufficient precision to hold double values.
    • BOOLEAN

      public static final SqlJdbcUtil.FieldType BOOLEAN
      The database field can hold a boolean value. On most databases that just means it is a BOOLEAN column, but some databases do not have this type and emulate it with something else, such as a TINYINT on MySQL.
    • OBJECT

      public static final SqlJdbcUtil.FieldType OBJECT
      The database field holds serialized Object data. The underlying database type is a BLOB on most databases; however, it is 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.
    • CLOB

      public static final SqlJdbcUtil.FieldType CLOB
      The database field is a CLOB or whatever the nearest equivalent is.
    • BLOB

      public static final SqlJdbcUtil.FieldType BLOB
      The database field is a BLOB or whatever the nearest equivalent is. BLOB field support is untested and probably incomplete.
    • BYTE_ARRAY

      public static final SqlJdbcUtil.FieldType BYTE_ARRAY
      The database field holds arbitrary binary data. The underlying database type is a BLOB on most databases; however, it is BYTEA for Postgres and IMAGE for SqlServer. Unlike OBJECT, this type does not perform any implicit serialization or deserialization of its data.
  • Method Details

    • values

      public static SqlJdbcUtil.FieldType[] 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

      public static SqlJdbcUtil.FieldType valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • getOldTypeNumber

      public int getOldTypeNumber()
      Returns the old hardcoded type number that is associated with this field type, such as 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.

      Returns:
      the old hardcoded type number that is associated with this field type.
    • matches

      public boolean matches(String javaType)
      Returns 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.
      Parameters:
      javaType - the proposed java type
      Returns:
      true if the specified java type corresponds to this field type; false otherwise.