Package org.apache.empire.db
Class DBRecordBean
java.lang.Object
org.apache.empire.db.DBObject
org.apache.empire.db.DBRecordData
org.apache.empire.db.DBRecordBase
org.apache.empire.db.DBRecordBean
- All Implemented Interfaces:
Serializable,Cloneable,Record,RecordData,DBContextAware
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:
-
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
ConstructorsConstructorDescriptionConstructs a new DBRecordBean.DBRecordBean(boolean enableRollbackHandling) Constructs a new DBRecordBean. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the record by releasing all resources and resetting the record's state to invalid.Creates a new recordCreates a new recordvoidThis 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(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.read(DBContext context, DBRowSet rowset, DBCompareExpr whereConstraints) Reads a record from the databaseOverridden 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 disabledvoidUpdates the record in the databaseMethods inherited from class org.apache.empire.db.DBRecordBase
addXmlData, addXmlMeta, allowFieldChange, assignParentIdentities, changeState, checkUpdateable, checkValid, checkValid, clone, 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
-
tempContext
-
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
varArgs to Array- Parameters:
values- the key values- Returns:
- the record key
-
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
-
close
public void close()Description copied from class:DBRecordBaseCloses the record by releasing all resources and resetting the record's state to invalid.- Overrides:
closein classDBRecordBase
-
create
Creates a new record- Parameters:
context- the database contextrowset- the rowset from which to read the recordinitalKey- the record key- Returns:
- returns self (this)
-
create
Creates a new record- Parameters:
context- the database contextrowset- the rowset from which to read the record- Returns:
- returns self (this)
-
read
Reads a record from the database- Parameters:
context- the database contextrowset- the rowset from which to read the recordkey- an array of the primary key values- Returns:
- returns self (this)
-
read
Reads a record from the database This method can only be used for tables with a single primary key- Parameters:
context- the database contextrowset- the rowset from which to read the recordid- 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:
context- the database contextrowset- the rowset from which to read the recordwhereConstraints- 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 contextrowset- the rowset from which to read the recordkey- 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
Updates the record in the database- Parameters:
context- the database context
-
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- Parameters:
context- the database context- See Also:
-