public abstract class DBRowSet extends DBExpr implements EntityType
Modifier and Type | Class and Description |
---|---|
static class |
DBRowSet.FieldInitMode |
static class |
DBRowSet.PartialMode |
Modifier and Type | Field and Description |
---|---|
protected Class<?> |
beanType |
protected Map<DBColumn,DBColumn> |
columnReferences |
protected List<DBColumn> |
columns |
protected String |
comment |
protected DBDatabase |
db |
protected String |
entityName |
protected static org.slf4j.Logger |
log |
protected DBColumn |
timestampColumn |
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESIS, CTX_VALUE
Constructor and Description |
---|
DBRowSet(DBDatabase db)
Constructs a DBRecord object set the current database object.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addColumnReference(DBColumn source,
DBColumn target)
Adds a column reference to the list of table references.
|
void |
addReferencedColumns(Set<DBColumn> list)
Internal function to obtain all DBColumnExpr-objects used by this expression.
|
protected void |
checkParamRecord(DBRecordBase record,
boolean checkValid)
Internally used for parameter checking
|
protected void |
completeInitRecord(DBRecordBase record)
Completes the record initialization.
|
DBColumnExpr |
count()
Returns a new DBCountExpr object.
|
abstract void |
createRecord(DBRecordBase record,
Object[] initalKey,
boolean deferredInit) |
protected DBCommand |
createRecordCommand(DBContext context)
Mabe use Prepared statements even if disabled in context
|
protected void |
deleteAllReferences(Object[] key,
DBContext context)
Deletes all records which reference this table.
|
void |
deleteRecord(long id,
DBContext context)
Deletes a single record from the database.
|
abstract void |
deleteRecord(Object[] key,
DBContext context) |
protected void |
deleteReferenceRecords(DBRelation.DBReference[] refs,
Object[] parentKey,
DBContext context)
Deletes all records which are referenced by a particular relation.
|
boolean |
equals(Object other) |
abstract String |
getAlias() |
Class<?> |
getBeanType()
returns the bean type for this rowset
|
DBColumn |
getColumn(int iColumn)
Returns a DBColumn object by a specified index value.
|
DBColumn |
getColumn(String name)
Gets the column Expression with a particular name.
|
protected DBColumnExpr |
getColumnExprAt(int index)
Returns the column expression at a given column index
Allow overrides in derived classes
|
int |
getColumnIndex(ColumnExpr columnExpr)
Gets the index of a particular column expression.
|
int |
getColumnIndex(DBColumn column)
Gets the index of a particular column expression.
|
Map<DBColumn,DBColumn> |
getColumnReferences()
Returns the a list of column references.
|
List<DBColumn> |
getColumns()
Gets all columns of this rowset (e.g. for cmd.select()).
|
String |
getComment() |
DBDatabase |
getDatabase()
Returns the current DBDatabase object.
|
String |
getEntityName()
Returns the entity name creating qualified names.
|
String |
getFullName()
Returns the full qualified name of the rowset.
|
String |
getIdentifier()
Gets an identifier for this RowSet Object
|
abstract DBColumn[] |
getKeyColumns() |
protected DBCompareExpr |
getKeyConstraints(Object[] key)
Set the constraints for a single record from a supplied key
|
abstract String |
getName() |
protected String |
getRenameTablePhrase()
Returns the sql phrase for renaming tables.
|
protected Object |
getRowsetData(DBRecordBase record)
Returns additional data stored on a record by the RowSet
|
DBColumn |
getTimestampColumn() |
int |
hashCode()
Custom serialization for transient database.
|
void |
initRecord(DBRecordBase record,
DBRecordData recData)
Initializes a DBRecord for this rowset using the record data provided (i.e. from a DBReader)
The record may then be modified and updated. |
protected void |
initRecord(DBRecordBase record,
Object[] key,
DBRowSet.FieldInitMode fieldInitMode,
boolean newRecord)
Initializes a DBRecord for this RowSet and sets primary key values.
|
protected void |
initRecordDefaultValues(DBRecordBase record,
DBRowSet.FieldInitMode fieldInitMode)
initializes the Record Default Values
|
boolean |
isColumnReadOnly(DBColumn col)
Checks whether a column is read only or writable.
|
boolean |
isKeyColumn(DBColumn column)
Checks whether a given column is part of the primary key for this RowSet
|
boolean |
isSame(DBRowSet other)
Compares the rowset to another one
|
abstract boolean |
isUpdateable() |
static DBColumn[] |
key(DBColumn... parts)
varArgs to Array
|
DBCompareJoinExpr |
on(DBCompareExpr cmp)
Creates a join expression based on a compare expression
|
DBCrossJoinExpr |
on(DBRowSet right)
Creates a cross join expression
|
protected void |
prepareInitRecord(DBRecordBase record,
boolean newRecord)
Initialize this DBRowSet object and sets it's initial state.
|
protected void |
readRecord(DBRecordBase record,
DBCommand cmd)
Reads a single record from the database using the given command object.
|
void |
readRecord(DBRecordBase record,
DBCompareExpr whereConstraints)
Reads a record from the database
|
void |
readRecord(DBRecordBase record,
DBCompareExpr whereConstraints,
DBRowSet.PartialMode mode,
DBColumn... columns)
Reads the partial record for a given primary key from the database
|
boolean |
recordExists(Object[] key,
DBContext context)
Returns true if the record exists in the database or false otherwise.
|
boolean |
recordExists(Object id,
DBContext context)
Returns true if the record exists in the database or false otherwise.
|
void |
setBeanType(Class<?> beanType)
sets the bean type for this rowset
|
<T> void |
setBeanType(Class<T> beanType,
DBBeanListFactory<T> factory)
sets the bean type for this rowset
|
void |
setComment(String comment) |
protected void |
setEntityName(String entityName)
sets the entity name for creating qualified names.
|
protected void |
setRowsetData(DBRecordBase record,
Object rowsetData)
May be used by a Rowset to store additional data on a record
|
void |
setTimestampColumn(DBColumn timestampColumn) |
<R extends DBRecordBase> |
updateRecord(R record)
Updates or Inserts a record in the database.
|
checkParamNull
protected static final org.slf4j.Logger log
protected final DBDatabase db
protected String comment
protected String entityName
protected DBColumn timestampColumn
protected Class<?> beanType
public DBRowSet(DBDatabase db)
db
- the database objectprotected void checkParamRecord(DBRecordBase record, boolean checkValid)
record
- the record to checkcheckValid
- flag whether to check the validitypublic static DBColumn[] key(DBColumn... parts)
parts
- the partspublic String getIdentifier()
public int hashCode()
public boolean isSame(DBRowSet other)
other
- the rowset to compare this rowset withpublic abstract String getName()
public abstract String getAlias()
public abstract boolean isUpdateable()
public abstract void createRecord(DBRecordBase record, Object[] initalKey, boolean deferredInit)
public abstract DBColumn[] getKeyColumns()
getKeyColumns
in interface EntityType
public String getFullName()
public String getEntityName()
getEntityName
in interface EntityType
protected void setEntityName(String entityName)
entityName
- the entity namepublic Class<?> getBeanType()
getBeanType
in interface EntityType
public void setBeanType(Class<?> beanType)
beanType
- the bean type for this rowsetpublic <T> void setBeanType(Class<T> beanType, DBBeanListFactory<T> factory)
beanType
- the bean type for this rowsetpublic void addReferencedColumns(Set<DBColumn> list)
DBExpr
addReferencedColumns
in class DBExpr
list
- list to which all used column expressions must be addedDBExpr.addReferencedColumns(Set)
public DBDatabase getDatabase()
getDatabase
in class DBObject
public List<DBColumn> getColumns()
getColumns
in interface EntityType
public int getColumnIndex(DBColumn column)
column
- column the DBColumn to get the index forpublic int getColumnIndex(ColumnExpr columnExpr)
columnExpr
- the Column to get the index forpublic DBColumn getColumn(int iColumn)
iColumn
- the index to get the DBColumn forpublic DBColumn getColumn(String name)
name
- the name of the column to look forpublic boolean isColumnReadOnly(DBColumn col)
col
- the column objectpublic boolean isKeyColumn(DBColumn column)
column
- the column to checkpublic String getComment()
public void setComment(String comment)
comment
- The comment to set.public DBColumn getTimestampColumn()
public void setTimestampColumn(DBColumn timestampColumn)
timestampColumn
- The timestampColumn to set.public Map<DBColumn,DBColumn> getColumnReferences()
protected void addColumnReference(DBColumn source, DBColumn target)
source
- a column reference for one of this table's columntarget
- the target column to which the source column referencespublic DBColumnExpr count()
protected String getRenameTablePhrase()
protected DBColumnExpr getColumnExprAt(int index)
index
- public DBCompareJoinExpr on(DBCompareExpr cmp)
public DBCrossJoinExpr on(DBRowSet right)
protected void initRecord(DBRecordBase record, Object[] key, DBRowSet.FieldInitMode fieldInitMode, boolean newRecord)
record
- the Record objectkey
- an array of the values for the primary keyfieldInitMode
- indicates how to initializes the record fieldsnewRecord
- true if the record is new or false if it is an existing recordpublic void initRecord(DBRecordBase record, DBRecordData recData)
record
- the record objectrecData
- the record data from which to initialized the recordprotected void initRecordDefaultValues(DBRecordBase record, DBRowSet.FieldInitMode fieldInitMode)
record
- the recordfieldInitMode
- the field initialization modeprotected void prepareInitRecord(DBRecordBase record, boolean newRecord)
record
- the DBRecord object to initialize this DBRowSet objectnewRecord
- flag whether the record is new (non-existing) in the databaseprotected void completeInitRecord(DBRecordBase record)
record
- the DBRecord object to initializeprotected DBCompareExpr getKeyConstraints(Object[] key)
key
- the record keyprotected void readRecord(DBRecordBase record, DBCommand cmd)
record
- the DBRecord object which holds the record datacmd
- the SQL-Command used to query the recordpublic void readRecord(DBRecordBase record, DBCompareExpr whereConstraints)
record
- the DBRecord object which will hold the record datawhereConstraints
- the constraint for querying the recordpublic void readRecord(DBRecordBase record, DBCompareExpr whereConstraints, DBRowSet.PartialMode mode, DBColumn... columns)
record
- the DBRecord object which will hold the record datawhereConstraints
- a compare expression for querying the recordmode
- 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)public boolean recordExists(Object[] key, DBContext context)
key
- an array of the primary key columnscontext
- the DBContextpublic final boolean recordExists(Object id, DBContext context)
id
- id of the recordcontext
- the DBContextpublic <R extends DBRecordBase> void updateRecord(R record)
If a timestamp-column is set for this RowSet then a constraint will be added in the
update statement in order to detect concurrent changes.
If the record has been modified by another user, an error of type
DBErrors.RecordUpdateFailed will be set.
record
- the DBRecord object. contains all fields and the field propertiespublic final void deleteRecord(long id, DBContext context)
id
- the record's primary keycontext
- the DBContextprotected final void deleteAllReferences(Object[] key, DBContext context)
key
- the key the record to be deletedcontext
- the DBContextprotected void deleteReferenceRecords(DBRelation.DBReference[] refs, Object[] parentKey, DBContext context)
refs
- the reference columns belonging to the relationparentKey
- the key of the parent elementcontext
- the DBContextprotected DBCommand createRecordCommand(DBContext context)
protected final Object getRowsetData(DBRecordBase record)
record
- the recordprotected final void setRowsetData(DBRecordBase record, Object rowsetData)
record
- the recordrowsetData
- the extra data to set on this recordCopyright © 2008–2023 Apache Software Foundation. All rights reserved.