public class DBRecord extends DBRecordData implements Record, Cloneable
Modifier and Type | Class and Description |
---|---|
static class |
DBRecord.State |
Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
log |
Constructor and Description |
---|
DBRecord()
Create a new DBRecord object.
|
DBRecord(DBRowSet initialRowset) |
Modifier and Type | Method and Description |
---|---|
int |
addColumnDesc(Element parent)
This function set the field descriptions to the the XML tag.
|
int |
addRowValues(Element parent)
Add the values of this record to the specified XML Element object.
|
protected boolean |
allowFieldChange(DBColumn column)
Checks whether or not this field can be changed at all.
|
protected void |
changeState(DBRecord.State newState)
changes the state of the record
|
DBRecord |
clone() |
void |
close()
Closes the record by releasing all resources and resetting the record's state to invalid.
|
void |
create(DBRowSet table)
Creates a new record for the given table.
|
void |
create(DBRowSet table,
Connection conn)
Creates a new record for the given table.
|
void |
delete(Connection conn)
This helper function calls the DBRowset.deleteRecord method
to delete the record.
|
int |
fillMissingDefaults(Connection conn)
Set the record default value for the fields with
the value
ObjectUtils.NO_VALUE |
Column |
getColumn(int index)
Implements the Record Interface getColumn method.
|
ColumnExpr |
getColumnExpr(int index)
Returns a DBColumnExpr object by a specified index value.
|
DBDatabase |
getDatabase()
Returns the current DBDatabase object.
|
DBColumn |
getDBColumn(int index)
Returns the DBColumn for the field at the given index.
|
int |
getFieldCount()
Returns the number of the columns.
|
int |
getFieldIndex(ColumnExpr column)
Returns the index value by a specified DBColumnExpr object.
|
int |
getFieldIndex(String column)
Returns the index value by a specified column name.
|
Options |
getFieldOptions(Column column)
Gets the possbile Options for a field in the context of the current record.
|
Options |
getFieldOptions(DBColumn column)
Gets the possbile Options for a field in the context of the current record.
|
protected Object[] |
getFields()
This function provides direct access to the record fields.
|
Column[] |
getKeyColumns()
returns an array of key columns which uniquely identify the record.
|
Object[] |
getKeyValues()
Returns the array of primary key columns.
|
DBRowSet |
getRowSet()
Returns the DBRowSet object.
|
Object |
getRowSetData()
Returns the DBRowSet object.
|
DBRecord.State |
getState()
Returns the record state.
|
Object |
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 (see
isValueValid(int) ) |
protected DBXmlDictionary |
getXmlDictionary()
returns the DBXmlDictionary that should used to generate XMLDocuments
|
Document |
getXmlDocument()
Returns a XML document with the field description an values of this record.
|
void |
init(DBRowSet table,
Object[] keyValues,
boolean insert)
Initializes this record object by attaching it to a rowset,
setting its primary key values and setting the record state.
|
protected void |
initData(DBRowSet rowset,
Object rowSetData,
boolean newRecord)
This method is used internally by the RowSet to initialize the record's properties
|
protected boolean |
isColumn(int index,
DBColumn... column)
helper function to check if a given field index corresponds to one of the given columns
|
boolean |
isExists()
Returns true if this record is a existing record (valid but not new).
|
boolean |
isFieldReadOnly(Column column)
returns whether a field is read only or not
|
boolean |
isFieldRequired(Column column)
returns whether a field is required or not
|
boolean |
isFieldVisible(Column column)
returns whether a field is visible to the client or not
May be overridden to implement context specific logic.
|
boolean |
isModified()
Returns true if the record is modified.
|
boolean |
isNew()
Returns true if this record is a new record.
|
boolean |
isReadOnly()
Returns true if the record is valid.
|
boolean |
isValid()
Returns true if the record is valid.
|
boolean |
isValidateFieldValues()
Returns whether or not values are checked for validity when calling setValue().
|
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. |
protected void |
modifyValue(int index,
Object value,
boolean fireChangeEvent)
Modifies a column value bypassing all checks made by setValue.
|
protected void |
onFieldChanged(int i)
Override this to get notified when a field value changes
|
protected void |
onRecordChanged()
Override this to do extra handling when the record changes
|
protected void |
onRowSetChanged()
Override this to do extra handling when the rowset for this record changes
|
void |
read(DBRowSet table,
DBCompareExpr whereConstraints,
Connection conn)
Reads a record from the database identified by one or more constraints.
|
void |
read(DBRowSet table,
Object[] key,
Connection conn)
Reads a record from the database identified by it's primary key.
|
void |
read(DBRowSet table,
Object id,
Connection conn)
Reads a record from the database identified by it's primary key.
|
void |
setModified(DBColumn column,
boolean isModified)
Sets the modified state of a column.
|
protected void |
setRecordValue(Column column,
Object bean,
String property)
set a record value from a particular bean property.
|
int |
setRecordValues(Object bean)
Sets record values from the suppied java bean.
|
int |
setRecordValues(Object bean,
Collection<Column> ignoreList)
Sets record values from the supplied java bean.
|
void |
setValidateFieldValues(boolean validateFieldValues)
Set whether or not values are checked for validity when calling setValue().
|
void |
setValue(Column column,
Object value)
Sets the value of the column in the record.
|
void |
setValue(int index,
Object value)
Sets the value of the column in the record.
|
void |
update(Connection conn)
Updates the record and saves all changes in the database.
|
protected void |
updateComplete(Object rowSetData)
This method is used internally to indicate that the record update has completed
This will set change the record's state to Valid |
void |
validateAllValues()
validates all modified values of a record
|
Object |
validateValue(Column column,
Object value)
Validates a value before it is set in the record.
|
boolean |
wasAnyModified(Column... columns)
Returns true if any of the given fields was modified.
|
boolean |
wasModified(Column column)
Returns true if the field was modified.
|
boolean |
wasModified(int index)
Returns true if the field was modified.
|
getAs, getAs, getBoolean, getBoolean, getDateTime, getDateTime, getDecimal, getDecimal, getDouble, getDouble, getEnum, getEnum, getEnum, getInt, getInt, getLong, getLong, getString, getString, getValue, getValues, isNull, isNull, setBeanProperties, setBeanProperties, setBeanProperty
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getValue, isNull, isNull, setBeanProperties, setBeanProperties
public DBRecord()
public DBRecord(DBRowSet initialRowset)
protected void initData(DBRowSet rowset, Object rowSetData, boolean newRecord)
rowset
- the rowset to which to attach this recordrowSetData
- any further RowSet specific datanewRecord
- protected void changeState(DBRecord.State newState)
newState
- protected Object[] getFields()
public void close()
close
in class DBRecordData
public DBDatabase getDatabase()
getDatabase
in class DBObject
public DBRowSet getRowSet()
public Object getRowSetData()
public DBRecord.State getState()
public boolean isValid()
public boolean isReadOnly()
isReadOnly
in interface Record
public boolean isModified()
isModified
in interface Record
public boolean isNew()
public boolean isExists()
public int getFieldCount()
getFieldCount
in interface RecordData
getFieldCount
in class DBRecordData
public int getFieldIndex(ColumnExpr column)
getFieldIndex
in interface RecordData
getFieldIndex
in class DBRecordData
column
- the column for which to return the indexpublic int getFieldIndex(String column)
getFieldIndex
in interface RecordData
getFieldIndex
in class DBRecordData
column
- the name of the column for which to return the indexpublic DBColumn getDBColumn(int index)
index
- the field indexpublic final Column getColumn(int index)
public final ColumnExpr getColumnExpr(int index)
getColumnExpr
in interface RecordData
getColumnExpr
in class DBRecordData
index
- field index of the column expressionprotected boolean isColumn(int index, DBColumn... column)
index
- the field indexcolumn
- one or more columns to checkpublic boolean wasModified(int index)
index
- the field indexpublic final boolean wasModified(Column column)
wasModified
in interface Record
column
- the requested columnpublic final boolean wasAnyModified(Column... columns)
public void setModified(DBColumn column, boolean isModified)
column
- the columnisModified
- modified or notpublic Column[] getKeyColumns()
getKeyColumns
in interface Record
public Object[] getKeyValues()
public Object getValue(int index)
isValueValid(int)
)getValue
in interface RecordData
getValue
in class DBRecordData
index
- the field index for which to return the valuepublic boolean isValueValid(int index)
index
- the filed indexObjectUtils.NO_VALUE
public Options getFieldOptions(DBColumn column)
column
- the database field columnpublic final Options getFieldOptions(Column column)
getFieldOptions
in interface Record
column
- the column to check for visibilityprotected void modifyValue(int index, Object value, boolean fireChangeEvent)
index
- index of the columnvalue
- the column valuepublic void validateAllValues()
public void setValue(int index, Object value)
public final void setValue(Column column, Object value)
protected boolean allowFieldChange(DBColumn column)
column
- the column that needs to be changedpublic Object validateValue(Column column, Object value)
validateValue
in interface Record
column
- the column that needs to be changedvalue
- the new valuepublic boolean isValidateFieldValues()
public void setValidateFieldValues(boolean validateFieldValues)
validateFieldValues
- flag whether to check validitypublic boolean isFieldVisible(Column column)
May be overridden to implement context specific logic.
isFieldVisible
in interface Record
column
- the column which to check for visibilitypublic boolean isFieldReadOnly(Column column)
isFieldReadOnly
in interface Record
column
- the database columnpublic boolean isFieldRequired(Column column)
isFieldRequired
in interface Record
column
- the database columnpublic void init(DBRowSet table, Object[] keyValues, boolean insert)
table
- the rowsetkeyValues
- a Object array, the primary key(s)insert
- if true change the state of this object to REC_NEWpublic void create(DBRowSet table, Connection conn)
If a connection is supplied sequence generated values will be obtained
Otherwise the sequence will be generated later.
table
- the table for which to create a recordconn
- a valid JDBC connectionpublic final void create(DBRowSet table)
table
- the table for which to create a recordpublic void read(DBRowSet table, Object[] key, Connection conn)
table
- the rowset from which to read the recordkeys
- an array of the primary key valuesconn
- a valid connection to the database.DBRowSet.readRecord(DBRecord, Object[], Connection)
public final void read(DBRowSet table, Object id, Connection conn)
table
- the rowset from which to read the recordid
- the primary key of the record to load.conn
- a valid connection to the database.DBRowSet.readRecord(DBRecord, Object[], Connection)
public void read(DBRowSet table, DBCompareExpr whereConstraints, Connection conn)
table
- the rowset from which to read the recordwhereConstraints
- the constraint(s) (which must all be on the table)conn
- a valid connection to the database.public void update(Connection conn)
conn
- a valid connection to the database.DBRowSet.updateRecord(DBRecord, Connection)
protected void updateComplete(Object rowSetData)
rowSetData
- additional data held by the rowset for this record (optional)public void delete(Connection conn)
conn
- a valid connection to the database.DBTable.deleteRecord(Object[], Connection)
public int addColumnDesc(Element parent)
addColumnDesc
in class DBRecordData
public int addRowValues(Element parent)
addRowValues
in class DBRecordData
parent
- the XML Element objectprotected DBXmlDictionary getXmlDictionary()
public Document getXmlDocument()
getXmlDocument
in class DBRecordData
public int fillMissingDefaults(Connection conn)
ObjectUtils.NO_VALUE
conn
- the sql connectionprotected void setRecordValue(Column column, Object bean, String property)
For a property called FOO this is equivalent of calling
setValue(column, bean.getFOO())
bean
- the Java Bean from which to read the value fromproperty
- the name of the propertycolumn
- the column for which to set the record valuepublic int setRecordValues(Object bean, Collection<Column> ignoreList)
setRecordValues
in interface Record
bean
- the Java Bean from which to read the value fromignoreList
- list of column to ignorepublic final int setRecordValues(Object bean)
setRecordValues
in interface Record
bean
- the Java Bean from which to read the value fromprotected void onRowSetChanged()
protected void onRecordChanged()
protected void onFieldChanged(int i)
Copyright © 2008–2022 Apache Software Foundation. All rights reserved.