Class DBRecordData

java.lang.Object
org.apache.empire.db.DBObject
org.apache.empire.db.DBRecordData
All Implemented Interfaces:
RecordData, DBContextAware
Direct Known Subclasses:
DBReader, DBRecordBase

public abstract class DBRecordData extends DBObject implements DBContextAware, RecordData
This class provides access to the fields of one data-row of a table, view or query The fields can be accessed either by Column or by index There are various accessor functions for many data types. The field values are converted to the desired type if possible. The field values can be transferred to a classical Java-bean (aka Pojo)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract int
     
    abstract int
     
    protected String
    formatValue(ColumnExpr column, Object value)
    Convert a non-string value to a string
    get(ColumnExpr column)
    Returns a data value for the desired column .
    final <V> V
    get(ColumnExpr column, Class<V> valueType)
    returns the record value for a particular column
    final Object[]
    getArray(ColumnExpr... columns)
    Returns an array of values for the given column expressions
    final boolean
    getBoolean(int index)
    Returns a data value identified by the column index.
    final boolean
    Returns a data value for the desired column.
    final Date
    getDate(int index)
    Returns the value as as a java.util.Date object The data value is converted to a Date if necessary.
    final Date
    Returns the value as as a java.util.Date object The data value is converted to a Date if necessary.
    final Date
    getDateTime(int index)
    Deprecated.
    final Date
    Deprecated.
    getDecimal(int index)
    Returns a data value identified by the column index.
    Returns a data value for the desired column.
    double
    getDouble(int index)
    Returns a data value identified by the column index.
    final double
    Returns a data value for the desired column.
    final <T extends Enum<?>>
    T
    getEnum(int index, Class<T> enumType)
    Returns the value of a field as an enum For numeric columns the value is assumed to be an ordinal of the enumeration item For non numeric columns the value is assumed to be the name of the enumeration item
    final <T extends Enum<?>>
    T
    getEnum(Column column)
    Returns the value of a field as an enum This assumes that the column attribute "enumType" has been set to an enum type For numeric columns the value is assumed to be an ordinal of the enumeration item
    final <T extends Enum<?>>
    T
    getEnum(ColumnExpr column, Class<T> enumType)
    Returns the value of a field as an enum For numeric columns the value is assumed to be an ordinal of the enumeration item For non numeric columns the value is assumed to be the name of the enumeration item
    abstract int
    returns the number of field available
    abstract int
    returns the index of the column expression with the given name
    abstract int
    returns the index of the given column expression Indexed operations provide better performance for bulk processing
    final int
    getInt(int index)
    Returns a data value identified by the column index.
    final int
    Returns a data value for the desired column.
    final LocalDate
    getLocalDate(int index)
    Returns a data value identified by the column index.
    final LocalDate
    Returns a data value for the desired column.
    getLocalDateTime(int index)
    Returns a data value identified by the column index.
    Returns a data value for the desired column.
    final long
    getLong(int index)
    Returns a data value identified by the column index.
    final long
    Returns a data value for the desired column.
    final String
    getString(int index)
    Returns a data value identified by the column index.
    final String
    Returns a data value for the desired column.
    final String
    Returns the value of a column as a formatted text This converts the value to a string if necessary and performs an options lookup To customize conversion please override convertToString()
    Returns the value of a column as a formatted text This converts the value to a string if necessary and performs an options lookup To customize conversion please override convertToString()
    final Timestamp
    getTimestamp(int index)
    Returns the value as as a java.sql.Timestamp object
    final Timestamp
    Returns the value as as a java.sql.Timestamp object
    abstract Object
    getValue(int index)
    Returns the raw field value based on the field index.
    <V> V
    getValue(int index, Class<V> valueType)
    returns the record value for a particular column
    abstract Document
     
    boolean
    isNull(int index)
    Checks whether or not the value for the given column is null.
    final boolean
    Checks whether or not the value for the given column is null.
    boolean
    Returns true if a numeric value is Zero For numeric columns only!
    final int
    Injects the current field values into a java bean.
    int
    setBeanProperties(Object bean, Collection<? extends ColumnExpr> ignoreList)
    Injects the current field values into a java bean.
    protected void
    setBeanProperty(ColumnExpr column, Object bean, Object value)
    Set a single property value on a java bean object

    Methods inherited from class org.apache.empire.db.DBObject

    checkParamNull, getDatabase

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.empire.db.context.DBContextAware

    getContext

    Methods inherited from interface org.apache.empire.data.RecordData

    getColumn
  • Constructor Details

    • DBRecordData

      public DBRecordData()
  • Method Details

    • getFieldCount

      public abstract int getFieldCount()
      Description copied from interface: RecordData
      returns the number of field available
      Specified by:
      getFieldCount in interface RecordData
      Returns:
      field count
    • getFieldIndex

      public abstract int getFieldIndex(ColumnExpr column)
      Description copied from interface: RecordData
      returns the index of the given column expression Indexed operations provide better performance for bulk processing
      Specified by:
      getFieldIndex in interface RecordData
      Parameters:
      column - the column for which to return the index
      Returns:
      the field index of the given column
    • getFieldIndex

      public abstract int getFieldIndex(String column)
      Description copied from interface: RecordData
      returns the index of the column expression with the given name
      Specified by:
      getFieldIndex in interface RecordData
      Parameters:
      column - the name of the column for which to return the index
      Returns:
      the field index of the given column
    • addXmlMeta

      public abstract int addXmlMeta(Element parent)
    • addXmlData

      public abstract int addXmlData(Element parent)
    • getXmlDocument

      public abstract Document getXmlDocument()
    • getValue

      public abstract Object getValue(int index)
      Returns the raw field value based on the field index.
      Specified by:
      getValue in interface RecordData
      Parameters:
      index - the field index
      Returns:
      the raw field value
    • getValue

      public <V> V getValue(int index, Class<V> valueType)
      returns the record value for a particular column
      Specified by:
      getValue in interface RecordData
      Type Parameters:
      V - the desired return type for the value
      Parameters:
      index - the field index for which to return the value
      valueType - the desired value type
      Returns:
      the record value for the given column
    • get

      public final <V> V get(ColumnExpr column, Class<V> valueType)
      returns the record value for a particular column
      Specified by:
      get in interface RecordData
      Parameters:
      column - the column for which to return the value
      valueType - the desired value type
      Returns:
      the record value for the given column
    • get

      public Object get(ColumnExpr column)
      Returns a data value for the desired column .
      Specified by:
      get in interface RecordData
      Parameters:
      column - the column for which to obtain the value
      Returns:
      the record value
    • isNull

      public boolean isNull(int index)
      Checks whether or not the value for the given column is null.
      Specified by:
      isNull in interface RecordData
      Parameters:
      index - index of the column
      Returns:
      true if the value is null or false otherwise
    • isNull

      public final boolean isNull(ColumnExpr column)
      Checks whether or not the value for the given column is null.
      Specified by:
      isNull in interface RecordData
      Parameters:
      column - identifying the column
      Returns:
      true if the value is null or false otherwise
    • isZero

      public boolean isZero(ColumnExpr column)
      Returns true if a numeric value is Zero For numeric columns only!
      Parameters:
      column - the column
      Returns:
      true if the value is zero or false otherwise
    • getString

      public final String getString(int index)
      Returns a data value identified by the column index. The data value is converted to a string if necessary.
      Parameters:
      index - index of the column
      Returns:
      the value
    • getString

      public final String getString(ColumnExpr column)
      Returns a data value for the desired column. The data value is converted to a string if necessary.
      Parameters:
      column - identifying the column
      Returns:
      the value
    • getInt

      public final int getInt(int index)
      Returns a data value identified by the column index. The value is converted to integer if necessary .
      Parameters:
      index - index of the column
      Returns:
      the record value
    • getInt

      public final int getInt(ColumnExpr column)
      Returns a data value for the desired column. The data value is converted to integer if necessary.
      Parameters:
      column - identifying the column
      Returns:
      the value
    • getLong

      public final long getLong(int index)
      Returns a data value identified by the column index. The data value is converted to a long if necessary.
      Parameters:
      index - index of the column
      Returns:
      the value
    • getLong

      public final long getLong(ColumnExpr column)
      Returns a data value for the desired column. The data value is converted to a long if necessary.
      Parameters:
      column - identifying the column
      Returns:
      the value
    • getDouble

      public double getDouble(int index)
      Returns a data value identified by the column index. The data value is converted to double if necessary.
      Parameters:
      index - index of the column
      Returns:
      the value
    • getDouble

      public final double getDouble(ColumnExpr column)
      Returns a data value for the desired column. The data value is converted to double if necessary.
      Parameters:
      column - identifying the column
      Returns:
      the value
    • getDecimal

      public final BigDecimal getDecimal(int index)
      Returns a data value identified by the column index. The data value is converted to double if necessary.
      Parameters:
      index - index of the column
      Returns:
      the value
    • getDecimal

      public final BigDecimal getDecimal(ColumnExpr column)
      Returns a data value for the desired column. The data value is converted to BigDecimal if necessary.
      Parameters:
      column - identifying the column
      Returns:
      the value
    • getBoolean

      public final boolean getBoolean(int index)
      Returns a data value identified by the column index. The data value is converted to boolean if necessary.
      Parameters:
      index - index of the column
      Returns:
      the value
    • getBoolean

      public final boolean getBoolean(ColumnExpr column)
      Returns a data value for the desired column. The data value is converted to boolean if necessary.
      Parameters:
      column - identifying the column
      Returns:
      the value
    • getDate

      public final Date getDate(int index)
      Returns the value as as a java.util.Date object The data value is converted to a Date if necessary.
      Parameters:
      index - index of the column
      Returns:
      the value
    • getDate

      public final Date getDate(ColumnExpr column)
      Returns the value as as a java.util.Date object The data value is converted to a Date if necessary.
      Parameters:
      column - identifying the column
      Returns:
      the value
    • getDateTime

      @Deprecated public final Date getDateTime(int index)
      Deprecated.
    • getDateTime

      @Deprecated public final Date getDateTime(ColumnExpr column)
      Deprecated.
    • getTimestamp

      public final Timestamp getTimestamp(int index)
      Returns the value as as a java.sql.Timestamp object
      Parameters:
      index - the column index
      Returns:
      the timestamp value
    • getTimestamp

      public final Timestamp getTimestamp(ColumnExpr column)
      Returns the value as as a java.sql.Timestamp object
      Parameters:
      column - the timestamp column
      Returns:
      the timestamp value
    • getLocalDate

      public final LocalDate getLocalDate(int index)
      Returns a data value identified by the column index. The data value is converted to a Date if necessary.
      Parameters:
      index - index of the column
      Returns:
      the value
    • getLocalDate

      public final LocalDate getLocalDate(ColumnExpr column)
      Returns a data value for the desired column. The data value is converted to a Date if necessary.
      Parameters:
      column - identifying the column
      Returns:
      the value
    • getLocalDateTime

      public final LocalDateTime getLocalDateTime(int index)
      Returns a data value identified by the column index. The data value is converted to a Date if necessary.
      Parameters:
      index - index of the column
      Returns:
      the value
    • getLocalDateTime

      public final LocalDateTime getLocalDateTime(ColumnExpr column)
      Returns a data value for the desired column. The data value is converted to a Date if necessary.
      Parameters:
      column - identifying the column
      Returns:
      the value
    • getEnum

      public final <T extends Enum<?>> T getEnum(int index, Class<T> enumType)
      Returns the value of a field as an enum For numeric columns the value is assumed to be an ordinal of the enumeration item For non numeric columns the value is assumed to be the name of the enumeration item
      Type Parameters:
      T - the enum type
      Parameters:
      index - index of the field
      enumType - the enum type class
      Returns:
      the enum value
    • getEnum

      public final <T extends Enum<?>> T getEnum(ColumnExpr column, Class<T> enumType)
      Returns the value of a field as an enum For numeric columns the value is assumed to be an ordinal of the enumeration item For non numeric columns the value is assumed to be the name of the enumeration item
      Type Parameters:
      T - the enum type
      Parameters:
      column - the column for which to retrieve the value
      enumType - the enum type class
      Returns:
      the enum value
    • getEnum

      public final <T extends Enum<?>> T getEnum(Column column)
      Returns the value of a field as an enum This assumes that the column attribute "enumType" has been set to an enum type For numeric columns the value is assumed to be an ordinal of the enumeration item
      Type Parameters:
      T - the enum type
      Parameters:
      column - the column for which to retrieve the value
      Returns:
      the enum value
    • getArray

      public final Object[] getArray(ColumnExpr... columns)
      Returns an array of values for the given column expressions
      Parameters:
      columns - the column expressions
      Returns:
      the corresponding record values
    • getText

      public String getText(ColumnExpr column)
      Returns the value of a column as a formatted text This converts the value to a string if necessary and performs an options lookup To customize conversion please override convertToString()
      Parameters:
      column - the column for which to get the formatted value
      Returns:
      the formatted value
    • getText

      public final String getText(String name)
      Returns the value of a column as a formatted text This converts the value to a string if necessary and performs an options lookup To customize conversion please override convertToString()
      Parameters:
      name - the column for which to get the formatted value
      Returns:
      the formatted value
    • setBeanProperties

      public int setBeanProperties(Object bean, Collection<? extends ColumnExpr> ignoreList)
      Injects the current field values into a java bean. The property name is detected by ColumnExpr.getBeanPropertyName()
      Specified by:
      setBeanProperties in interface RecordData
      Parameters:
      bean - the Java Bean for which to set the properties
      ignoreList - list of columns to skip (optional)
      Returns:
      the number of bean properties set on the supplied bean
    • setBeanProperties

      public final int setBeanProperties(Object bean)
      Injects the current field values into a java bean. The property name is detected by ColumnExpr.getBeanPropertyName()
      Parameters:
      bean - the Java Bean for which to set the properties
      Returns:
      the number of bean properties set on the supplied bean
    • setBeanProperty

      protected void setBeanProperty(ColumnExpr column, Object bean, Object value)
      Set a single property value on a java bean object
      Parameters:
      column - the column expression
      bean - the bean
      value - the value
    • formatValue

      protected String formatValue(ColumnExpr column, Object value)
      Convert a non-string value to a string
      Parameters:
      column - the column expression
      value - the value to format
      Returns:
      the formatted string