Class DBRecordBean

All Implemented Interfaces:
Serializable, Cloneable, Record, RecordData, DBContextAware

public class DBRecordBean extends DBRecordBase
This class represents a record from a database table, view or query Other than DBRecord it is not permanently attached to a context or rowset Thus it has a Default constructor and is essentially a dynamic bean
See Also:
  • Field Details

    • tempContext

      protected transient DBContext tempContext
    • rowset

      protected transient DBRowSet rowset
    • enableRollbackHandling

      protected boolean enableRollbackHandling
  • Constructor Details

    • DBRecordBean

      public DBRecordBean(boolean enableRollbackHandling)
      Constructs a new DBRecordBean.
      Parameters:
      enableRollbackHandling - flag whether to enable rollback handing
    • DBRecordBean

      public DBRecordBean()
      Constructs a new DBRecordBean.
  • Method Details

    • key

      public static Object[] key(Object... values)
      varArgs to Array
      Parameters:
      values - the key values
      Returns:
      the record key
    • getContext

      public DBContext getContext()
      Returns the current Context
      Returns:
      the database context
    • getRowSet

      public DBRowSet getRowSet()
      Returns the DBRowSet object.
      Specified by:
      getRowSet in class DBRecordBase
      Returns:
      the DBRowSet object
    • isRollbackHandlingEnabled

      public boolean isRollbackHandlingEnabled()
      Returns whether or not RollbackHandling is enabled for this record
      Specified by:
      isRollbackHandlingEnabled in class DBRecordBase
      Returns:
      true if rollback handling is enabled or false otherwise
    • setRollbackHandlingEnabled

      public void setRollbackHandlingEnabled(boolean enabled)
      Set whether or not RollbackHandling will be performed for this record Since Rollback handling requires additional resources it should only be used if necessary Especially for bulk operations it should be disabled
      Parameters:
      enabled - flag whether to enable or disable RollbackHandling
    • getIdentity

      public long getIdentity()
      Returns the record identity for tables which have a single numeric primary key like AUTOINC This method is provided for convenience in addition to the the getKey() method
      Returns:
      the record id or 0 if the key is null
      Throws:
      NoPrimaryKeyException - if the table has no primary key
      NotSupportedException - if the primary key is not a single column of if the column is not numeric
    • close

      public void close()
      Description copied from class: DBRecordBase
      Closes the record by releasing all resources and resetting the record's state to invalid.
      Overrides:
      close in class DBRecordBase
    • create

      public DBRecordBean create(DBContext context, DBRowSet rowset, Object[] initalKey)
      Creates a new record
      Parameters:
      context - the database context
      rowset - the rowset from which to read the record
      initalKey - the record key
      Returns:
      returns self (this)
    • create

      public DBRecordBean create(DBContext context, DBRowSet rowset)
      Creates a new record
      Parameters:
      context - the database context
      rowset - the rowset from which to read the record
      Returns:
      returns self (this)
    • read

      public DBRecordBean read(DBContext context, DBRowSet rowset, Object[] key)
      Reads a record from the database
      Parameters:
      context - the database context
      rowset - the rowset from which to read the record
      key - an array of the primary key values
      Returns:
      returns self (this)
    • read

      public DBRecordBean read(DBContext context, DBRowSet rowset, Object id)
      Reads a record from the database This method can only be used for tables with a single primary key
      Parameters:
      context - the database context
      rowset - the rowset from which to read the record
      id - the primary key of the record
      Returns:
      returns self (this)
      Throws:
      NoPrimaryKeyException - if the associated RowSet has no primary key
      InvalidKeyException - if the associated RowSet does not have a single column primary key
    • read

      public DBRecordBean read(DBContext context, DBRowSet rowset, DBCompareExpr whereConstraints)
      Reads a record from the database
      Parameters:
      context - the database context
      rowset - the rowset from which to read the record
      whereConstraints - the compare expression for querying the record
      Returns:
      returns self (this)
    • read

      public DBRecordBean read(DBContext context, DBRowSet rowset, Object[] key, DBRowSet.PartialMode mode, DBColumn... columns)
      Reads a record partially i.e. not with all but just some selected fields There are two modes: 1. PartialMode.INCLUDE reads only the fields provided with the column list 2. PartialMode.EXCLUDE reads all but the fields provided with the column list The primary key is always fetched implicitly
      Parameters:
      context - the database context
      rowset - the rowset from which to read the record
      key - the primary key values
      mode - flag whether to include only the given columns or whether to add all but the given columns
      columns - the columns to include or exclude (depending on mode)
      Returns:
      returns self (this)
    • set

      public DBRecordBean set(Column column, Object value)
      Overridden to change return type from DBCommandExpr to DBCommand
      Specified by:
      set in interface Record
      Overrides:
      set in class DBRecordBase
      Parameters:
      column - a DBColumn object
      value - the value
      Returns:
      returns self (this)
    • update

      public void update(DBContext context)
      Updates the record in the database
      Parameters:
      context - the database context
    • delete

      public void delete(DBContext context)
      This helper function calls the DBRowset.deleteRecord method to delete the record. WARING: There is no guarantee that it ist called Implement delete logic in the table's deleteRecord method if possible
      Parameters:
      context - the database context
      See Also: