Package org.apache.empire.db
Class DBRecord
java.lang.Object
org.apache.empire.db.DBObject
org.apache.empire.db.DBRecordData
org.apache.empire.db.DBRecordBase
org.apache.empire.db.DBRecord
- All Implemented Interfaces:
Serializable,Cloneable,Record,RecordData,DBContextAware
- Direct Known Subclasses:
TRecord
This class represents a record from a database table, view or query
The class provides methods to create, read, update and delete records
If an Idendity-column (AUTOINC) is defined, the value will be set upon creation by the dbms to the next value
If a Timestamp-column is defined the value will be automatically set and concurrent changes of the record will be detected
If changes to the record are made, but a rollback on the connection is performed, the changes will be reverted (Rollback-Handling)
The record is Serializable either if the provided DBContext is serializable, or if the Context is provided on deserialization in a derived class.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.empire.db.DBRecordBase
DBRecordBase.DBRecordRollbackHandler, DBRecordBase.State -
Field Summary
FieldsFields inherited from class org.apache.empire.db.DBRecordBase
allowReadOnlyUpdate, validateFieldValues -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreate()Creates a new recordCreates a new recordvoiddelete()This helper function calls the DBRowset.deleteRecord method to delete the record.Returns the current ContextlongReturns 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() methodReturns the DBRowSet object.booleanReturns whether or not RollbackHandling is enabled for this recordstatic Object[]varArgs to ArrayReads a record from the database This method can only be used for tables with a single primary keyReads a record from the databaseread(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.read(DBCompareExpr whereConstraints) Reads a record from the databaseprotected DBContextreadContext(ObjectInputStream strm) protected DBRowSetreadRowSet(ObjectInputStream strm) Overridden to change return type from DBCommandExpr to DBCommandvoidsetRollbackHandlingEnabled(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 disabledvoidupdate()Updates the record and saves all changes in the database.protected voidprotected voidMethods inherited from class org.apache.empire.db.DBRecordBase
addXmlData, addXmlMeta, allowFieldChange, assignParentIdentities, changeState, checkUpdateable, checkValid, checkValid, clone, close, createRollbackHandler, getColumn, getDatabase, getEntity, getFieldCount, getFieldIndex, getFieldIndex, getFieldOptions, getFieldOptions, getFields, getKey, getKeyColumns, getState, getValue, getXmlDictionary, getXmlDocument, initData, initData, isColumn, isExists, isFieldReadOnly, isFieldRequired, isFieldVisible, isModified, isNew, isReadOnly, isSame, isValid, isValidateFieldValues, isValueValid, modifyValue, onFieldChanged, onRecordChanged, setFieldModified, setParentRecord, setRecordValue, setRecordValues, setRecordValues, setValidateFieldValues, setValue, setValue, updateComplete, validateAllValues, validateValue, wasAnyModified, wasModified, wasModifiedMethods inherited from class org.apache.empire.db.DBRecordData
formatValue, get, get, getArray, getBoolean, getBoolean, getDate, getDate, getDateTime, getDateTime, getDecimal, getDecimal, getDouble, getDouble, getEnum, getEnum, getEnum, getInt, getInt, getLocalDate, getLocalDate, getLocalDateTime, getLocalDateTime, getLong, getLong, getString, getString, getText, getText, getTimestamp, getTimestamp, getValue, isNull, isNull, isZero, setBeanProperties, setBeanProperties, setBeanPropertyMethods inherited from class org.apache.empire.db.DBObject
checkParamNullMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.empire.data.RecordData
get, get, getValue, isNull, isNull, setBeanProperties
-
Field Details
-
context
-
rowset
-
-
Constructor Details
-
DBRecord
Internal constructor for DBRecord May be used by derived classes to provide special behaviour- Parameters:
context- the database contextrowset- the rowset to which this record belongsenableRollbackHandling- flag whether to enable rollback handling
-
DBRecord
Constructs a new DBRecord.- Parameters:
context- the DBContext for this recordrowset- the corresponding RowSet(Table, View, Query, etc.)
-
-
Method Details
-
key
varArgs to Array- Parameters:
values- the key values- Returns:
- the key
-
writeContext
- Throws:
IOException
-
writeRowSet
- Throws:
IOException
-
readContext
- Throws:
IOExceptionClassNotFoundException
-
readRowSet
- Throws:
IOExceptionClassNotFoundException
-
getContext
Returns the current Context- Returns:
- the database context
-
getRowSet
Returns the DBRowSet object.- Specified by:
getRowSetin classDBRecordBase- Returns:
- the DBRowSet object
-
isRollbackHandlingEnabled
public boolean isRollbackHandlingEnabled()Returns whether or not RollbackHandling is enabled for this record- Specified by:
isRollbackHandlingEnabledin classDBRecordBase- 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 keyNotSupportedException- if the primary key is not a single column of if the column is not numeric
-
create
Creates a new record- Parameters:
initalKey- the record key- Returns:
- returns self (this)
-
create
Creates a new record- Returns:
- returns self (this)
-
read
Reads a record from the database- Parameters:
key- an array of the primary key values- Returns:
- returns self (this)
- Throws:
NoPrimaryKeyException- if the associated RowSet has no primary keyInvalidKeyException- if the key does not match the key columns of the associated RowSet
-
read
Reads a record from the database This method can only be used for tables with a single primary key- Parameters:
id- the primary key of the record- Returns:
- returns self (this)
- Throws:
NoPrimaryKeyException- if the associated RowSet has no primary keyInvalidKeyException- if the associated RowSet does not have a single column primary key
-
read
Reads a record from the database- Parameters:
whereConstraints- the compare expression for querying this record- Returns:
- returns self (this)
-
read
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:
key- the primary key valuesmode- flag whether to include only the given columns or whether to add all but the given columnscolumns- the columns to include or exclude (depending on mode)- Returns:
- returns self (this)
-
set
Overridden to change return type from DBCommandExpr to DBCommand- Specified by:
setin interfaceRecord- Overrides:
setin classDBRecordBase- Parameters:
column- a DBColumn objectvalue- the value- Returns:
- returns self (this)
-
update
public void update()Updates the record and saves all changes in the database. -
delete
public void delete()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
-