|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.empire.db.DBObject
org.apache.empire.db.DBRecordData
org.apache.empire.db.DBRecord
public class DBRecord
This class handles one record from a database table.
Nested Class Summary | |
---|---|
static class |
DBRecord.State
|
Field Summary | |
---|---|
protected static org.slf4j.Logger |
log
|
Constructor Summary | |
---|---|
DBRecord()
Create a new DBRecord object. The record is not attached to a RowSet and the record's state is initially set to REC_INVALID. |
|
DBRecord(DBRowSet initialRowset)
|
Method Summary | |
---|---|
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. All record fields will be filled with their default values. The record's state is set to NEW |
void |
create(DBRowSet table,
Connection conn)
Creates a new record for the given table. All record fields will be filled with their default values. |
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. Internally calls getDBColumn() |
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. Same as getFieldOptions(DBColumn) |
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. This method is used internally be the RowSet to fill the data. |
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. This function is useful for updating a record without prior reading. |
protected void |
initData(DBRowSet rowset,
Object rowSetData,
boolean newRecord)
This method is used internally by the RowSet to initialize the record's properties |
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 |
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. |
protected void |
modifyValue(int i,
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,
Object[] keys,
Connection conn)
Loads a record from the database identified by it's primary key. |
void |
read(DBRowSet table,
Object id,
Connection conn)
Loads a record from the database identified by it's primary key. |
protected void |
setBeanValue(Object bean,
String property,
Column column)
set a record value from a particular bean property. |
int |
setBeanValues(Object bean)
Sets record values from the suppied java bean. |
int |
setBeanValues(Object bean,
Collection<Column> ignoreList)
Sets record values from the supplied java bean. |
void |
setModified(DBColumn column,
boolean isModified)
Sets the modified state of a column. This will force the field to be updated in the database, if set to TRUE. |
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 |
Object |
validateValue(Column column,
Object value)
Validates a value before it is set in the record. |
boolean |
wasModified(Column column)
Returns true if the field was modified. |
boolean |
wasModified(int index)
Returns true if the field was modified. |
Methods inherited from class org.apache.empire.db.DBRecordData |
---|
getBeanProperties, getBeanProperties, getBeanProperty, getBoolean, getBoolean, getDateTime, getDateTime, getDecimal, getDecimal, getDouble, getDouble, getInt, getInt, getLong, getLong, getString, getString, getValue, isNull, isNull |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.empire.data.RecordData |
---|
getBeanProperties, getBeanProperties, getValue, isNull, isNull |
Field Detail |
---|
protected static final org.slf4j.Logger log
Constructor Detail |
---|
public DBRecord()
public DBRecord(DBRowSet initialRowset)
Method Detail |
---|
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 DBRecord clone()
clone
in class Object
public DBDatabase getDatabase()
getDatabase
in class DBObject
public DBRowSet getRowSet()
public Object getRowSetData()
public DBRecord.State getState()
public boolean isValid()
isValid
in interface Record
public boolean isReadOnly()
isReadOnly
in interface Record
public boolean isModified()
isModified
in interface Record
public boolean isNew()
isNew
in interface Record
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 index
public int getFieldIndex(String column)
getFieldIndex
in interface RecordData
getFieldIndex
in class DBRecordData
column
- the name of the column for which to return the index
public DBColumn getDBColumn(int index)
index
- the field index
public final Column getColumn(int index)
getColumn
in interface Record
index
- index of a requested column
public final ColumnExpr getColumnExpr(int index)
getColumnExpr
in interface RecordData
getColumnExpr
in class DBRecordData
index
- field index of the column expression
public boolean wasModified(int index)
index
- the field index
public final boolean wasModified(Column column)
wasModified
in interface Record
column
- the requested column
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 value
public boolean isValueValid(int index)
index
- the filed index
ObjectUtils.NO_VALUE
public Options getFieldOptions(DBColumn column)
column
- the database field column
public final Options getFieldOptions(Column column)
getFieldOptions
in interface Record
column
- the column to check for visibility
protected void modifyValue(int i, Object value, boolean fireChangeEvent)
i
- index of the columnvalue
- the column valuepublic void setValue(int index, Object value)
setValue
in interface Record
index
- the index of the columnvalue
- the valuepublic final void setValue(Column column, Object value)
setValue
in interface Record
column
- a DBColumn objectvalue
- the valueprotected boolean allowFieldChange(DBColumn column)
column
- the column that needs to be changed
public Object validateValue(Column column, Object value)
validateValue
in interface Record
column
- the column that needs to be changedvalue
- the new value
public 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 visibility
public boolean isFieldReadOnly(Column column)
isFieldReadOnly
in interface Record
column
- the database column
public boolean isFieldRequired(Column column)
isFieldRequired
in interface Record
column
- the database column
public 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[] keys, 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 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 object
protected DBXmlDictionary getXmlDictionary()
public Document getXmlDocument()
getXmlDocument
in class DBRecordData
public int fillMissingDefaults(Connection conn)
ObjectUtils.NO_VALUE
conn
- the sql connection
protected void setBeanValue(Object bean, String property, Column column)
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 setBeanValues(Object bean, Collection<Column> ignoreList)
setBeanValues
in interface Record
bean
- the Java Bean from which to read the value fromignoreList
- list of column to ignore
public final int setBeanValues(Object bean)
setBeanValues
in interface Record
bean
- the Java Bean from which to read the value from
protected void onRowSetChanged()
protected void onRecordChanged()
protected void onFieldChanged(int i)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |