Class DBView

All Implemented Interfaces:
Cloneable, Entity
Direct Known Subclasses:
TView

public abstract class DBView extends DBRowSet implements Cloneable
This class represents a database view. It contains methods to get and update records from the database
  • Constructor Details

    • DBView

      public DBView(String name, DBDatabase db, boolean isUpdateable, String alias)
      Creates a view object for a given view in the database.
      Parameters:
      name - the name of the view
      db - the database this view belongs to.
      isUpdateable - true if the records of this view can be updated
      alias - the view alias
    • DBView

      public DBView(String name, DBDatabase db, boolean isUpdateable)
      Creates a view object for a given view in the database.
      Parameters:
      name - the name of the view
      db - the database this view belongs to.
      isUpdateable - true if the records of this view can be updated
    • DBView

      public DBView(String name, DBDatabase db)
      Creates a view object for a given view in the database.
      Parameters:
      name - the name of the view
      db - the database this view belongs to.
  • Method Details

    • generateAlias

      protected String generateAlias(String prefix)
      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

      public Object clone() throws CloneNotSupportedException
      Allows a second instance of a view with a different alias
      Overrides:
      clone in class Object
      Returns:
      another instance of the view
      Throws:
      CloneNotSupportedException
    • clone

      public <T extends DBView> T clone(String newAlias)
      Allows a second instance of a view with a different alias
      Parameters:
      newAlias - the new alias
      Returns:
      another instance of the view
    • cloneColumn

      protected DBColumn cloneColumn(DBRowSet clone, DBColumn sourceColumn)
      Description copied from class: DBRowSet
      Clones a RowSet column
      Specified by:
      cloneColumn in class DBRowSet
      Parameters:
      clone - the cloned rowset
      sourceColumn - the source column
      Returns:
      the cloned column
    • cloneKeyColumns

      protected DBView.DBViewColumn[] cloneKeyColumns(DBView clone)
    • getKeyColumns

      public DBColumn[] getKeyColumns()
      Returns an array of all key columns.
      Specified by:
      getKeyColumns in interface Entity
      Specified by:
      getKeyColumns in class DBRowSet
      Returns:
      an array of all key columns
    • setKeyColumns

      protected void setKeyColumns(DBView.DBViewColumn... keyColumns)
      identifies the columns that uniquely identify a row in the view
      Parameters:
      keyColumns - list of columns that uniquely identify a row
    • setKeyColumn

      protected void setKeyColumn(DBView.DBViewColumn keyColumn)
      identifies the column that uniquely identifies a row in the view
      Parameters:
      keyColumn - the column that uniquely identifies a row
    • newCommand

      protected DBCommand newCommand()
      Use this to create a new View command inside the createCommand() method!
      Returns:
      a new command for this view
    • createCommand

      public abstract DBCommandExpr 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

      public String getName()
      Returns the view name of this object.
      Specified by:
      getName in class DBRowSet
      Returns:
      the view name of this object
    • getFullName

      public String getFullName()
      Returns the full qualified table name.
      Overrides:
      getFullName in class DBRowSet
      Returns:
      the full qualified table name
    • getAlias

      public String getAlias()
      Returns the alias name of this object.
      Specified by:
      getAlias in class DBRowSet
      Returns:
      the alias name of this object
    • isUpdateable

      public boolean isUpdateable()
      Returns whether or not the view is updateable
      Specified by:
      isUpdateable in class DBRowSet
      Returns:
      true if the view is updateable or false if not
    • addViewColumn

      protected void addViewColumn(DBView.DBViewColumn col)
      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 name
      sourceExpression - the source column expression
      size - the size
      Returns:
      the new column
    • addColumn

      protected final DBView.DBViewColumn addColumn(String columnName, DBColumnExpr columnExpr)
      Adds a column to the view.
      Parameters:
      columnName - name of the column in the view
      columnExpr - the column expression that builds the column
      Returns:
      the new column
    • addColumn

      protected final DBView.DBViewColumn addColumn(String columnName, DataType dataType, double size)
      Adds a column to the view.
      Parameters:
      columnName - name of the column in the view
      dataType - the data type of the column
      size - the size of the column
      Returns:
      the new column
    • addColumn

      protected final DBView.DBViewColumn addColumn(String columnName, DataType dataType)
      Adds a column to the view.
      Parameters:
      columnName - name of the column in the view
      dataType - the data type of the column
      Returns:
      the new column
    • addColumn

      protected final DBView.DBViewColumn addColumn(DBTableColumn sourceColumn)
      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

      protected final DBView.DBViewColumn addColumn(DBView.DBViewColumn sourceColumn)
      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

      public DBView.DBViewColumn findViewColumn(DBColumnExpr expr)
      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

      public void addSQL(DBSQLBuilder sql, long context)
      Creates the SQL-Command adds the alias name to the SQL-Command.
      Specified by:
      addSQL in class DBExpr
      Parameters:
      sql - the SQL-Command
      context - the current SQL-Command context
    • updateRecord

      public void updateRecord(DBRecordBase rec)
      Description copied from class: DBRowSet
      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.

      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:
      updateRecord in class DBRowSet
      Parameters:
      rec - the DBRecord object. contains all fields and the field properties
    • createRecord

      public void createRecord(DBRecordBase record, Object[] initalKey, boolean deferredInit)
      Specified by:
      createRecord in class DBRowSet
    • deleteRecord

      public void deleteRecord(Object[] key, DBContext context)
      Specified by:
      deleteRecord in class DBRowSet