Class JdbcValueHandler<T>

java.lang.Object
org.apache.ofbiz.entity.jdbc.JdbcValueHandler<T>
Direct Known Subclasses:
JdbcValueHandler.ArrayJdbcValueHandler, JdbcValueHandler.BigDecimalJdbcValueHandler, JdbcValueHandler.BlobJdbcValueHandler, JdbcValueHandler.BooleanJdbcValueHandler, JdbcValueHandler.ByteArrayJdbcValueHandler, JdbcValueHandler.ClobJdbcValueHandler, JdbcValueHandler.DateJdbcValueHandler, JdbcValueHandler.DoubleJdbcValueHandler, JdbcValueHandler.FloatJdbcValueHandler, JdbcValueHandler.IntegerJdbcValueHandler, JdbcValueHandler.LongJdbcValueHandler, JdbcValueHandler.ObjectJdbcValueHandler, JdbcValueHandler.RowIdJdbcValueHandler, JdbcValueHandler.ShortJdbcValueHandler, JdbcValueHandler.StringJdbcValueHandler, JdbcValueHandler.TimeJdbcValueHandler, JdbcValueHandler.TimestampJdbcValueHandler

public abstract class JdbcValueHandler<T> extends Object
An object that handles getting/setting column values in JDBC PreparedStatement and ResultSet objects.
  • Constructor Details

    • JdbcValueHandler

      protected JdbcValueHandler(int sqlType)
  • Method Details

    • getInstance

      public static JdbcValueHandler<?> getInstance(String javaType, String sqlType)
      Returns the JdbcValueHandler that corresponds to a field type.
      Parameters:
      javaType - The Java type specified in fieldtype*.xml
      sqlType - The SQL type specified in fieldtype*.xml
      Returns:
      A JdbcValueHandler instance
    • parseSqlType

      protected static String parseSqlType(String sqlType)
    • serializeObject

      protected static byte[] serializeObject(Object obj) throws SQLException
      Throws:
      SQLException
    • castAndSetValue

      protected abstract void castAndSetValue(PreparedStatement ps, int parameterIndex, T obj) throws SQLException
      Sets a value in a PreparedStatement. The obj argument is converted to the correct data type. Subclasses override this method to cast obj to the correct data type and call the appropriate PreparedStatement.setXxx method.
      Parameters:
      ps -
      parameterIndex -
      obj -
      Throws:
      SQLException
    • create

      protected JdbcValueHandler<T> create(int sqlType)
      Create jdbc value handler.
      Parameters:
      sqlType - the sql type
      Returns:
      the jdbc value handler
    • getSqlType

      public int getSqlType()
      Returns the SQL type for this handler.
      Returns:
      return the SQL type
      See Also:
      • java.sql.Types
    • getValue

      public abstract T getValue(ResultSet rs, int columnIndex) throws SQLException
      Returns a value from a ResultSet. The returned object is converted to the Java data type specified in the fieldtype file.
      Parameters:
      rs - the ResultSet object
      columnIndex - the column index
      Returns:
      get value from result set
      Throws:
      SQLException
    • newInstance

      protected abstract JdbcValueHandler<T> newInstance(int sqlType)
      Returns a new instance of the object - initialized with the specified SQL type.
      Parameters:
      sqlType - the sql type
      Returns:
      returns a new instance
    • getJavaClass

      public abstract Class<T> getJavaClass()
    • setValue

      public void setValue(PreparedStatement ps, int parameterIndex, T obj) throws SQLException
      Sets a value in a PreparedStatement. The obj argument is converted to the correct data type.
      Parameters:
      ps -
      parameterIndex -
      obj -
      Throws:
      SQLException