Class BeanRecordProxy<T>

java.lang.Object
org.apache.empire.data.bean.BeanRecordProxy<T>
Type Parameters:
T - the type of the class proxied by this BeanRecordProxy
All Implemented Interfaces:
Record, RecordData

public class BeanRecordProxy<T> extends Object implements Record
BeanRecordProxy This class defines proxy that allows any POJO to behave like a record object.
Author:
Rainer
  • Field Details

    • log

      protected static final org.slf4j.Logger log
    • entity

      protected final Entity entity
    • columns

      protected final List<Column> columns
    • keyColumns

      protected final Column[] keyColumns
    • data

      protected T data
    • modified

      protected boolean[] modified
  • Constructor Details

    • BeanRecordProxy

      public BeanRecordProxy(T data, List<Column> columns, Column[] keyColumns, Entity entity)
    • BeanRecordProxy

      public BeanRecordProxy(List<Column> columns, Column[] keyColumns, Entity entity)
    • BeanRecordProxy

      public BeanRecordProxy(T data, BeanClass beanClass)
    • BeanRecordProxy

      public BeanRecordProxy(BeanClass beanClass)
  • Method Details

    • getBean

      public T getBean()
    • setBean

      public void setBean(T data)
    • getColumn

      public Column getColumn(int index)
      Description copied from interface: Record
      Overridden to change return type from ColumnExpr to Column
      Specified by:
      getColumn in interface Record
      Specified by:
      getColumn in interface RecordData
      Parameters:
      index - field index of the column expression
      Returns:
      the column expression object or null if the index is out of range
    • getKeyColumns

      public Column[] getKeyColumns()
      Description copied from interface: Record
      returns an array of key columns which uniquely identify the record.
      Specified by:
      getKeyColumns in interface Record
      Returns:
      the array of key columns if any
    • getKey

      public Object[] getKey()
      Returns the array of primary key columns.
      Specified by:
      getKey in interface Record
      Returns:
      the array of primary key columns
    • getFieldCount

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

      public 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 int getFieldIndex(String columnName)
      Description copied from interface: RecordData
      returns the index of the column expression with the given name
      Specified by:
      getFieldIndex in interface RecordData
      Parameters:
      columnName - the name of the column for which to return the index
      Returns:
      the field index of the given column
    • getFieldOptions

      public Options getFieldOptions(Column column)
      Description copied from interface: Record
      returns the Options list for the given record field.
      Specified by:
      getFieldOptions in interface Record
      Parameters:
      column - the column to check for visibility
      Returns:
      an options collection containing all allowed field values
    • isFieldVisible

      public boolean isFieldVisible(Column column)
      Description copied from interface: Record
      returns true if the field is visible to the client.
      Specified by:
      isFieldVisible in interface Record
      Parameters:
      column - the column to check for visibility
      Returns:
      true if the field is visible to the client
    • isFieldReadOnly

      public boolean isFieldReadOnly(Column column)
      Description copied from interface: Record
      returns true if the field is read-only.
      Specified by:
      isFieldReadOnly in interface Record
      Parameters:
      column - the requested column
      Returns:
      true if the field is read-only
    • isFieldRequired

      public boolean isFieldRequired(Column column)
      Description copied from interface: Record
      returns true if the field is required.
      Specified by:
      isFieldRequired in interface Record
      Parameters:
      column - the requested column
      Returns:
      true if the field is required
    • isModified

      public boolean isModified()
      Description copied from interface: Record
      returns true if the record has been modified.
      Specified by:
      isModified in interface Record
      Returns:
      true if the record has been modified or false otherwise
    • isNew

      public boolean isNew()
      Description copied from interface: Record
      returns true if this record is a new record.
      Specified by:
      isNew in interface Record
      Returns:
      true if this record is a new record
    • getEntity

      public Entity getEntity()
      Description copied from interface: Record
      Returns the entity this Record belongs to
      Specified by:
      getEntity in interface Record
      Returns:
      the entity
    • isValid

      public boolean isValid()
      Description copied from interface: Record
      returns true if the record is valid.
      Specified by:
      isValid in interface Record
      Returns:
      true if the record is valid
    • isReadOnly

      public boolean isReadOnly()
      Description copied from interface: Record
      returns true if this record is readOnly.
      Specified by:
      isReadOnly in interface Record
      Returns:
      true if this record is readOnly
    • getValue

      public final Object getValue(int index)
      Description copied from interface: RecordData
      Returns the raw field value based on the field index. Indexed operations provide better performance for bulk processing compared to get(ColumnExpr)
      Specified by:
      getValue in interface RecordData
      Parameters:
      index - the field index
      Returns:
      the raw field value
    • getValue

      public final <V> V getValue(int index, Class<V> valueType)
      Description copied from interface: RecordData
      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 <V> V get(ColumnExpr column, Class<V> valueType)
      Description copied from interface: RecordData
      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 final Object get(ColumnExpr column)
      Description copied from interface: RecordData
      returns the record value for a particular column
      Specified by:
      get in interface RecordData
      Parameters:
      column - the column for which to return the value
      Returns:
      the record value for the given column
    • isNull

      public boolean isNull(ColumnExpr column)
      Description copied from interface: RecordData
      checks if the record contains no value (null) for the given column
      Specified by:
      isNull in interface RecordData
      Parameters:
      column - the column
      Returns:
      true if the value for the column is null or false otherwise
    • isNull

      public boolean isNull(int index)
      Description copied from interface: RecordData
      checks if the field at the given index position contains no value (null) Indexed operations provide better performance for bulk processing compared to isNull(ColumnExpr)
      Specified by:
      isNull in interface RecordData
      Parameters:
      index - the field index
      Returns:
      true if the field value is null or false otherwise
    • validateValue

      public Object validateValue(Column column, Object value)
      Validates a value before it is set in the record.
      Specified by:
      validateValue in interface Record
      Parameters:
      column - the column
      value - the value to validate
      Returns:
      the value
    • set

      public BeanRecordProxy<T> set(Column column, Object value)
      sets the value of a field.
      Specified by:
      set in interface Record
      Parameters:
      column - the requested column
      value - the new record value for the given column
      Returns:
      the record (this)
    • setValue

      public final void setValue(int i, Object value)
      sets the value of a field.
      Specified by:
      setValue in interface Record
      Parameters:
      i - index of the field for which to set the value
      value - the new field value
    • wasModified

      public boolean wasModified(Column column)
      Detects whether or not a particular field has been modified.
      Specified by:
      wasModified in interface Record
      Parameters:
      column - the requested column
      Returns:
      Returns true if a column has been modified
    • clearModified

      public void clearModified()
      clears the modification status of the object and all fields.
    • getText

      public final 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
    • setBeanProperties

      public int setBeanProperties(Object bean)
    • setBeanProperties

      public int setBeanProperties(Object bean, Collection<? extends ColumnExpr> ignoreList)
      Description copied from interface: RecordData
      copies all field values into a static Java Bean. In order to map column names to property names 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:
      number of fields that have been copied
    • setRecordValues

      public int setRecordValues(Object bean, Collection<Column> ignoreList)
      Description copied from interface: Record
      sets all record values from a particular bean.

      The bean must provide corresponding getter functions for all desired column.

      In order to map column names to property names the property name is detected by ColumnExpr.getBeanPropertyName()

      Specified by:
      setRecordValues in interface Record
      Parameters:
      bean - the Java Bean from which to read the value from
      ignoreList - list of column to ignore
      Returns:
      the number of fields that have been set
    • setRecordValues

      public int setRecordValues(Object bean)
      Description copied from interface: Record
      sets all record values from a particular bean.

      The bean must provide corresponding getter functions for all desired column.

      Specified by:
      setRecordValues in interface Record
      Parameters:
      bean - the Java Bean from which to read the value from
      Returns:
      the number of fields that have been set
    • getBeanProperty

      protected final Object getBeanProperty(Object bean, ColumnExpr column)
    • getBeanProperty

      protected Object getBeanProperty(Object bean, String property)
    • setBeanProperty

      protected void setBeanProperty(Object bean, Column column, Object 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