Package org.apache.empire.db
Class DBRecordBase
java.lang.Object
org.apache.empire.db.DBObject
org.apache.empire.db.DBRecordData
org.apache.empire.db.DBRecordBase
- All Implemented Interfaces:
Serializable,Cloneable,Record,RecordData,DBContextAware
- Direct Known Subclasses:
DBRecord,DBRecordBean
This abstract class provides write access to the fields of a record
The class provides methods that are useful for frontend-form development like
- providing information about the allowed values for a field (field options)
- providing information about whether or not a field is visible to the user
- providing information about whether or not a field is required (mandantory)
- providing information about whether or not a field is read-only
- providing information about whether a particular field value is valid
- providing information about whether a field was modified since it was read from the database
- providing information about whether the record was modified
Also, field value changes, can be handled using the onFieldChanged event.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDBRecordRollbackHandlerstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInternal constructor for DBRecord May be used by derived classes to provide special behaviour -
Method Summary
Modifier and TypeMethodDescriptionintaddXmlData(Element parent) Add the values of this record to the specified XML Element object.intaddXmlMeta(Element parent) This function set the field descriptions to the the XML tag.protected booleanallowFieldChange(DBColumn column) Checks whether or not this field can be changed at all.protected voidFor DBMS with IDENTITY-columns the deferred parent-keys are set by this functions The parent records must have been previously set using setParentRecordprotected voidchangeState(DBRecordBase.State newState) changes the state of the recordprotected voidChecks whether the record is updateable If its read-only a RecordReadOnlyException is thrownprotected voidhelper to check if the object is validprotected voidcheckValid(int fieldIndex) helper to check if the object is validclone()voidclose()Closes the record by releasing all resources and resetting the record's state to invalid.protected DBRollbackHandlerFactory function to create createRollbackHandler();getColumn(int index) Implements the Record Interface getColumn method.
Internally calls getDBColumn()Returns the current DBDatabase object.returns true if this record is a new record.intReturns the number of the columns.intgetFieldIndex(String column) Returns the index value by a specified column name.intgetFieldIndex(ColumnExpr column) Returns the index value by a specified DBColumnExpr object.final OptionsgetFieldOptions(Column column) Gets the possbile Options for a field in the context of the current record.
Same as getFieldOptions(DBColumn)getFieldOptions(DBColumn column) Gets the possbile Options for a field in the context of the current record.protected Object[]This function provides direct access to the record fields.
This method is used internally be the RowSet to fill the data.Object[]getKey()Returns a array of key columns by a specified DBRecord object.Column[]returns an array of key columns which uniquely identify the record.abstract DBRowSetReturns the DBRowSet object.getState()Returns the record state.getValue(int index) Returns the value for the given column or null if either the index is out of range or the value is not valid (seeisValueValid(int))protected DBXmlDictionaryreturns the DBXmlDictionary that should used to generate XMLDocumentsReturns a XML document with the field description an values of this record.protected voidinitData(boolean newRecord) This method is used internally by the RowSet to initialize the record's propertiesprotected voidinitData(DBRecordBase other) This method may be used to copy the record in order to preserve its stateprotected booleanhelper function to check if a given field index corresponds to one of the given columnsbooleanisExists()Returns true if this record is a existing record (valid but not new).booleanisFieldReadOnly(Column column) returns whether a field is read only or notbooleanisFieldRequired(Column column) returns whether a field is required or notbooleanisFieldVisible(Column column) returns whether a field is visible to the client or notbooleanReturns true if the record is modified.booleanisNew()Returns true if this record is a new record.booleanReturns true if the record is valid.abstract booleanReturns whether or not RollbackHandling is enabled for this recordbooleanisSame(DBRecordBase other) Compares the record to another onebooleanisValid()Returns true if the record is valid.booleanReturns whether or not values are checked for validity when calling setValue().booleanisValueValid(int index) Returns whether a field value is provided i.e. the value is not DBRowSet.NO_VALUE
This function is only useful in cases where records are partially loaded.protected voidmodifyValue(int index, Object value, boolean fireChangeEvent) Modifies a column value bypassing all checks made by setValue.protected voidonFieldChanged(int i) Override this to get notified when a field value changesprotected voidOverride this to do extra handling when the record changesSets the value of a column in the record.protected voidsetFieldModified(int index, boolean modifiedFlag) Sets a fields modified statusvoidsetParentRecord(DBColumn parentIdColumn, DBRecordBase record) For DBMS with IDENTITY-columns defer setting the parent-id until the record is inserted The parent record must have a one-column primary keyprotected voidsetRecordValue(Column column, Object bean) set a record value from a particular bean property.final intsetRecordValues(Object bean) Sets record values from the suppied java bean.intsetRecordValues(Object bean, Collection<Column> ignoreList) Sets record values from the supplied java bean.voidsetValidateFieldValues(boolean validateFieldValues) Set whether or not values are checked for validity when calling setValue().voidSets the value of a column in the record.Deprecated.protected voidThis method is used internally to indicate that the record update has completed
This will set change the record's state to Validvoidvalidates all modified values of a recordvalidateValue(Column column, Object value) Validates a value before it is set in the record.final booleanwasAnyModified(Column... columns) Returns true if any of the given fields was modified.booleanwasModified(int index) Returns true if the field was modified.final booleanwasModified(Column column) Returns true if the field was modified.Methods 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.db.context.DBContextAware
getContextMethods inherited from interface org.apache.empire.data.RecordData
get, get, getValue, isNull, isNull, setBeanProperties
-
Field Details
-
validateFieldValues
protected boolean validateFieldValues -
allowReadOnlyUpdate
protected boolean allowReadOnlyUpdate
-
-
Constructor Details
-
DBRecordBase
protected DBRecordBase()Internal constructor for DBRecord May be used by derived classes to provide special behaviour
-
-
Method Details
-
checkValid
protected void checkValid()helper to check if the object is valid- Throws:
ObjectNotValidException- if the object is not valid
-
checkValid
protected void checkValid(int fieldIndex) helper to check if the object is valid- Parameters:
fieldIndex- the field index- Throws:
ObjectNotValidException- if the object is not valid
-
close
public void close()Closes the record by releasing all resources and resetting the record's state to invalid. -
clone
-
getRowSet
Returns the DBRowSet object.- Returns:
- the DBRowSet object
-
isRollbackHandlingEnabled
public abstract boolean isRollbackHandlingEnabled()Returns whether or not RollbackHandling is enabled for this record- Returns:
- true if rollback handling is enabled or false otherwise
-
getEntity
returns true if this record is a new record. -
getDatabase
Returns the current DBDatabase object.- Specified by:
getDatabasein classDBObject- Returns:
- the current DBDatabase object
-
getState
Returns the record state.- Returns:
- the record state
-
isValid
public boolean isValid()Returns true if the record is valid. -
isReadOnly
public boolean isReadOnly()Returns true if the record is valid.- Specified by:
isReadOnlyin interfaceRecord- Returns:
- true if the record is valid
-
isModified
public boolean isModified()Returns true if the record is modified.- Specified by:
isModifiedin interfaceRecord- Returns:
- true if the record is modified
-
isNew
public boolean isNew()Returns true if this record is a new record. -
isExists
public boolean isExists()Returns true if this record is a existing record (valid but not new). This may be used from expression language instead of the not allowed property "new"- Returns:
- true if this record is a existing record (valid but not new).
-
getFieldCount
public int getFieldCount()Returns the number of the columns.- Specified by:
getFieldCountin interfaceRecordData- Specified by:
getFieldCountin classDBRecordData- Returns:
- the number of the columns
-
getFieldIndex
Returns the index value by a specified DBColumnExpr object.- Specified by:
getFieldIndexin interfaceRecordData- Specified by:
getFieldIndexin classDBRecordData- Parameters:
column- the column for which to return the index- Returns:
- the index value
-
getFieldIndex
Returns the index value by a specified column name.- Specified by:
getFieldIndexin interfaceRecordData- Specified by:
getFieldIndexin classDBRecordData- Parameters:
column- the name of the column for which to return the index- Returns:
- the index value
-
getColumn
Implements the Record Interface getColumn method.
Internally calls getDBColumn()- Specified by:
getColumnin interfaceRecord- Specified by:
getColumnin interfaceRecordData- Parameters:
index- field index of the column expression- Returns:
- the Column at the specified index
-
wasModified
public boolean wasModified(int index) Returns true if the field was modified.- Parameters:
index- the field index- Returns:
- true if the field was modified
-
wasModified
Returns true if the field was modified.- Specified by:
wasModifiedin interfaceRecord- Parameters:
column- the requested column- Returns:
- true if the field was modified
-
wasAnyModified
Returns true if any of the given fields was modified.- Parameters:
columns- the columns to check- Returns:
- true if any of the given fields were modified or false otherwise
-
isValidateFieldValues
public boolean isValidateFieldValues()Returns whether or not values are checked for validity when calling setValue(). If set to true validateValue() is called to check validity- Returns:
- true if the validity of values is checked or false otherwise
-
setValidateFieldValues
public void setValidateFieldValues(boolean validateFieldValues) Set whether or not values are checked for validity when calling setValue(). If set to true validateValue() is called to check validity, otherwise not.- Parameters:
validateFieldValues- flag whether to check validity
-
getKeyColumns
returns an array of key columns which uniquely identify the record.- Specified by:
getKeyColumnsin interfaceRecord- Returns:
- the array of key columns if any
-
getKey
Returns a array of key columns by a specified DBRecord object. -
getValue
Returns the value for the given column or null if either the index is out of range or the value is not valid (seeisValueValid(int))- Specified by:
getValuein interfaceRecordData- Specified by:
getValuein classDBRecordData- Parameters:
index- the field index- Returns:
- the index value
-
isValueValid
public boolean isValueValid(int index) Returns whether a field value is provided i.e. the value is not DBRowSet.NO_VALUE
This function is only useful in cases where records are partially loaded.- Parameters:
index- the filed index- Returns:
- true if a valid value is supplied for the given field or false if value is
ObjectUtils.NO_VALUE
-
getFieldOptions
Gets the possbile Options for a field in the context of the current record.- Parameters:
column- the database field column- Returns:
- the field options
-
getFieldOptions
Gets the possbile Options for a field in the context of the current record.
Same as getFieldOptions(DBColumn)- Specified by:
getFieldOptionsin interfaceRecord- Parameters:
column- the column to check for visibility- Returns:
- the Option
-
validateAllValues
public void validateAllValues()validates all modified values of a record -
setValue
Sets the value of a column in the record. The functions checks if the column and the value are valid and whether the value has changed. -
setValue
Deprecated.Deprecated Renamed to set(...)- Parameters:
column- a DBColumn objectvalue- the value- Returns:
- returns self (this)
-
set
Sets the value of a column in the record. The functions checks if the column and the value are valid and whether the value has changed. -
validateValue
Validates a value before it is set in the record. By default, this method simply calls column.validate()- Specified by:
validateValuein interfaceRecord- Parameters:
column- the column that needs to be changedvalue- the new value- Returns:
- the value
-
isFieldVisible
returns whether a field is visible to the client or notMay be overridden to implement context specific logic.
- Specified by:
isFieldVisiblein interfaceRecord- Parameters:
column- the column which to check for visibility- Returns:
- true if the column is visible or false if not
-
isFieldReadOnly
returns whether a field is read only or not- Specified by:
isFieldReadOnlyin interfaceRecord- Parameters:
column- the database column- Returns:
- true if the field is read only
-
isFieldRequired
returns whether a field is required or not- Specified by:
isFieldRequiredin interfaceRecord- Parameters:
column- the database column- Returns:
- true if the field is required
-
setRecordValues
Sets record values from the supplied java bean.- Specified by:
setRecordValuesin interfaceRecord- Parameters:
bean- the Java Bean from which to read the value fromignoreList- list of column to ignore- Returns:
- true if at least one value has been set successfully
-
setRecordValues
Sets record values from the suppied java bean.- Specified by:
setRecordValuesin interfaceRecord- Parameters:
bean- the Java Bean from which to read the value from- Returns:
- true if at least one value has been set successfully
-
setParentRecord
For DBMS with IDENTITY-columns defer setting the parent-id until the record is inserted The parent record must have a one-column primary key- Parameters:
parentIdColumn- the column for which to set the parentrecord- the parent record to be set for the column
-
isSame
Compares the record to another one- Parameters:
other- the record to compare this record with- Returns:
- true if it is the same record (but maybe a different instance)
-
addXmlMeta
This function set the field descriptions to the the XML tag.- Specified by:
addXmlMetain classDBRecordData- Returns:
- the number of column descriptions added to the element
-
addXmlData
Add the values of this record to the specified XML Element object.- Specified by:
addXmlDatain classDBRecordData- Parameters:
parent- the XML Element object- Returns:
- the number of row values added to the element
-
getXmlDocument
Returns a XML document with the field description an values of this record.- Specified by:
getXmlDocumentin classDBRecordData- Returns:
- the new XML Document object
-
getFields
This function provides direct access to the record fields.
This method is used internally be the RowSet to fill the data.- Returns:
- an array of field values
-
changeState
changes the state of the record- Parameters:
newState- the new record state
-
createRollbackHandler
Factory function to create createRollbackHandler();- Returns:
- the DBRollbackHandler
-
initData
protected void initData(boolean newRecord) This method is used internally by the RowSet to initialize the record's properties- Parameters:
newRecord- flag whether the record is new (non-existing) in the database
-
initData
This method may be used to copy the record in order to preserve its state- Parameters:
other- the record to be copied
-
updateComplete
protected void updateComplete()This method is used internally to indicate that the record update has completed
This will set change the record's state to Valid -
checkUpdateable
protected void checkUpdateable()Checks whether the record is updateable If its read-only a RecordReadOnlyException is thrown- Throws:
RecordReadOnlyException- exception thrown if record cannot be updated
-
allowFieldChange
Checks whether or not this field can be changed at all. Note: This is not equivalent to isFieldReadOnly()- Parameters:
column- the column that needs to be changed- Returns:
- true if it is possible to change this field for this record context
-
modifyValue
Modifies a column value bypassing all checks made by setValue. Use this to explicitly set invalid values i.e. for temporary storage.- Parameters:
index- index of the columnvalue- the column valuefireChangeEvent- flag whether to fire the onFieldChanged event
-
setFieldModified
protected void setFieldModified(int index, boolean modifiedFlag) Sets a fields modified status- Parameters:
index- the field indexmodifiedFlag- flag indicating whether or not the field was modified
-
onRecordChanged
protected void onRecordChanged()Override this to do extra handling when the record changes -
onFieldChanged
protected void onFieldChanged(int i) Override this to get notified when a field value changes- Parameters:
i- the field index
-
setRecordValue
set a record value from a particular bean property.For a property called FOO this is equivalent of calling
setValue(column, bean.getFOO())- Parameters:
bean- the Java Bean from which to read the value fromcolumn- the column for which to set the record value
-
assignParentIdentities
protected void assignParentIdentities()For DBMS with IDENTITY-columns the deferred parent-keys are set by this functions The parent records must have been previously set using setParentRecord -
isColumn
helper function to check if a given field index corresponds to one of the given columns- Parameters:
index- the field indexcolumn- one or more columns to check- Returns:
- true if the index is for one of the columns or false otherwise
-
getXmlDictionary
returns the DBXmlDictionary that should used to generate XMLDocuments- Returns:
- the DBXmlDictionary
-