Package org.apache.empire.db
Class DBView
java.lang.Object
org.apache.empire.db.DBObject
org.apache.empire.db.DBExpr
org.apache.empire.db.DBRowSet
org.apache.empire.db.DBView
- Direct Known Subclasses:
TView
This class represents a database view.
It contains methods to get and update records from the database
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.empire.db.DBRowSet
DBRowSet.FieldInitMode, DBRowSet.PartialMode -
Field Summary
Fields inherited from class org.apache.empire.db.DBRowSet
attributes, beanType, columnReferences, columns, comment, db, entityName, log, timestampColumnFields inherited from class org.apache.empire.db.DBExpr
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESIS, CTX_VALUE -
Constructor Summary
ConstructorsConstructorDescriptionDBView(String name, DBDatabase db) Creates a view object for a given view in the database.DBView(String name, DBDatabase db, boolean isUpdateable) Creates a view object for a given view in the database.DBView(String name, DBDatabase db, boolean isUpdateable, String alias) Creates a view object for a given view in the database. -
Method Summary
Modifier and TypeMethodDescriptionprotected final DBView.DBViewColumnAdds a column to the view.protected final DBView.DBViewColumnAdds a column to the view.protected final DBView.DBViewColumnaddColumn(String columnName, DBColumnExpr columnExpr) Adds a column to the view.protected final DBView.DBViewColumnaddColumn(DBTableColumn sourceColumn) Adds a column to the view based on an existing column in another table.protected final DBView.DBViewColumnaddColumn(DBView.DBViewColumn sourceColumn) Adds a column to the view based on an existing column in another view.voidaddSQL(DBSQLBuilder sql, long context) Creates the SQL-Command adds the alias name to the SQL-Command.protected voidAdds a column to the view.clone()Allows a second instance of a view with a different alias<T extends DBView>
TAllows a second instance of a view with a different aliasprotected DBColumncloneColumn(DBRowSet clone, DBColumn sourceColumn) Clones a RowSet columnprotected DBView.DBViewColumn[]cloneKeyColumns(DBView clone) protected DBView.DBViewColumncreateAndAppendColumn(String columnName, DBColumnExpr sourceExpression, double size) Adds a column to the view.abstract DBCommandExprReturns the command required to create the view
This is function is only used for the creation of DDL statementsvoidcreateRecord(DBRecordBase record, Object[] initalKey, boolean deferredInit) voiddeleteRecord(Object[] key, DBContext context) findViewColumn(DBColumnExpr expr) This function searches for equal columns given by the specified DBColumnExpr object.protected StringgenerateAlias(String prefix) Automatically generates a new alias for this ObjectgetAlias()Returns the alias name of this object.Returns the full qualified table name.DBColumn[]Returns an array of all key columns.getName()Returns the view name of this object.booleanReturns whether or not the view is updateableprotected DBCommandUse this to create a new View command inside the createCommand() method!protected voidsetKeyColumn(DBView.DBViewColumn keyColumn) identifies the column that uniquely identifies a row in the viewprotected voidsetKeyColumns(DBView.DBViewColumn... keyColumns) identifies the columns that uniquely identify a row in the viewvoidupdateRecord(DBRecordBase rec) Updates or Inserts a record in the database.
Whether an update or insert is performed depends on the record state.
Only modified fields will be inserted or updated in the database.Methods inherited from class org.apache.empire.db.DBRowSet
addColumnReference, addReferencedColumns, checkParamRecord, completeInitRecord, count, createRecordCommand, deleteAllReferences, deleteRecord, deleteReferenceRecords, equals, getAllColumns, getAttribute, getAttributes, getBeanType, getColumn, getColumn, getColumnCount, getColumnExprAt, getColumnIndex, getColumnIndex, getColumnReferences, getColumns, getComment, getDatabase, getEntityName, getIdentifier, getKeyConstraints, getRenameTablePhrase, getRowsetData, getTimestampColumn, hashCode, initClonedFields, initRecord, initRecord, initRecord, initRecordDefaultValues, isColumnReadOnly, isKeyColumn, isSame, key, on, on, prepareInitRecord, readRecord, readRecord, readRecord, recordExists, recordExists, setAttribute, setBeanType, setBeanType, setComment, setEntityName, setRowsetData, setTimestampColumnMethods inherited from class org.apache.empire.db.DBObject
checkParamNull
-
Constructor Details
-
DBView
Creates a view object for a given view in the database.- Parameters:
name- the name of the viewdb- the database this view belongs to.isUpdateable- true if the records of this view can be updatedalias- the view alias
-
DBView
Creates a view object for a given view in the database.- Parameters:
name- the name of the viewdb- the database this view belongs to.isUpdateable- true if the records of this view can be updated
-
DBView
Creates a view object for a given view in the database.- Parameters:
name- the name of the viewdb- the database this view belongs to.
-
-
Method Details
-
generateAlias
Automatically generates a new alias for this Object- Parameters:
prefix- the alias prefix- Returns:
- an alias consisting of the prefix and a unique number
-
clone
Allows a second instance of a view with a different alias- Overrides:
clonein classObject- Returns:
- another instance of the view
- Throws:
CloneNotSupportedException
-
clone
Allows a second instance of a view with a different alias- Parameters:
newAlias- the new alias- Returns:
- another instance of the view
-
cloneColumn
Description copied from class:DBRowSetClones a RowSet column- Specified by:
cloneColumnin classDBRowSet- Parameters:
clone- the cloned rowsetsourceColumn- the source column- Returns:
- the cloned column
-
cloneKeyColumns
-
getKeyColumns
Returns an array of all key columns.- Specified by:
getKeyColumnsin interfaceEntity- Specified by:
getKeyColumnsin classDBRowSet- Returns:
- an array of all key columns
-
setKeyColumns
identifies the columns that uniquely identify a row in the view- Parameters:
keyColumns- list of columns that uniquely identify a row
-
setKeyColumn
identifies the column that uniquely identifies a row in the view- Parameters:
keyColumn- the column that uniquely identifies a row
-
newCommand
Use this to create a new View command inside the createCommand() method!- Returns:
- a new command for this view
-
createCommand
Returns the command required to create the view
This is function is only used for the creation of DDL statements- Returns:
- a command expression that is used to create the view
-
getName
Returns the view name of this object. -
getFullName
Returns the full qualified table name.- Overrides:
getFullNamein classDBRowSet- Returns:
- the full qualified table name
-
getAlias
Returns the alias name of this object. -
isUpdateable
public boolean isUpdateable()Returns whether or not the view is updateable- Specified by:
isUpdateablein classDBRowSet- Returns:
- true if the view is updateable or false if not
-
addViewColumn
Adds a column to the view.- Parameters:
col- a view column object
-
createAndAppendColumn
protected DBView.DBViewColumn createAndAppendColumn(String columnName, DBColumnExpr sourceExpression, double size) Adds a column to the view.- Parameters:
columnName- the column namesourceExpression- the source column expressionsize- the size- Returns:
- the new column
-
addColumn
Adds a column to the view.- Parameters:
columnName- name of the column in the viewcolumnExpr- the column expression that builds the column- Returns:
- the new column
-
addColumn
Adds a column to the view.- Parameters:
columnName- name of the column in the viewdataType- the data type of the columnsize- the size of the column- Returns:
- the new column
-
addColumn
Adds a column to the view.- Parameters:
columnName- name of the column in the viewdataType- the data type of the column- Returns:
- the new column
-
addColumn
Adds a column to the view based on an existing column in another table.- Parameters:
sourceColumn- existing column in another table- Returns:
- the new column
-
addColumn
Adds a column to the view based on an existing column in another view.- Parameters:
sourceColumn- existing column in another view- Returns:
- the new column
-
findViewColumn
This function searches for equal columns given by the specified DBColumnExpr object.- Parameters:
expr- the DBColumnExpr object- Returns:
- the located column (only DBViewColumn objects)
-
addSQL
Creates the SQL-Command adds the alias name to the SQL-Command. -
updateRecord
Description copied from class:DBRowSetUpdates or Inserts a record in the database.
Whether an update or insert is performed depends on the record state.
Only modified fields will be inserted or updated in the database.
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.- Overrides:
updateRecordin classDBRowSet- Parameters:
rec- the DBRecord object. contains all fields and the field properties
-
createRecord
- Specified by:
createRecordin classDBRowSet
-
deleteRecord
- Specified by:
deleteRecordin classDBRowSet
-