Class DBCommandExpr

Direct Known Subclasses:
DBCombinedCmd, DBCommand

public abstract class DBCommandExpr extends DBExpr
This abstract class handles the creation of the SQL-Commands. There are inner classes to construct different SQL-Commands.
  • Field Details

  • Constructor Details

    • DBCommandExpr

      public DBCommandExpr(DBMSHandler dbms)
      Constructs an empty DBCommandExpr object
      Parameters:
      dbms - the database handler
  • Method Details

    • not

      protected final boolean not(int flags, int flag)
      Checks if a flag is NOT set
      Parameters:
      flags - the flags
      flag - the flag to check in flags
      Returns:
      true if the bit provided in flag is not set in flags or false otherwise
    • notEmpty

      protected final boolean notEmpty(Collection<?> list)
      Checks if a collection is not null or empty
      Parameters:
      list - the collection to check
      Returns:
      true if the collection is not empty or false if empty
    • getDbms

      public final DBMSHandler getDbms()
      returns the DBMSHandler this command belongs to
      Returns:
      the DBMSHandler
    • clone

      public DBCommandExpr clone()
      Creates a clone of this class.
      Overrides:
      clone in class Object
    • isValid

      public abstract boolean isValid()
    • hasSelectExpr

      public abstract boolean hasSelectExpr()
      returns whether or not the command has any select expression
      Returns:
      true if the command has any select expression of false otherwise
    • hasSelectExpr

      public abstract boolean hasSelectExpr(DBColumnExpr expr)
      returns whether or not the command has a specific select expression
      Parameters:
      expr - the column expr
      Returns:
      true if the command contains the given select expression of false otherwise
    • getSelectExprList

      public abstract DBColumnExpr[] getSelectExprList()
      Returns the list of all select expressions as an array Used internally only
      Returns:
      the select expression array
    • getSelectExpressions

      public abstract List<DBColumnExpr> getSelectExpressions()
      returns a list of expressions for the SELECT part of the sql statement
      Returns:
      the select expression list
    • getSelect

      public abstract void getSelect(DBSQLBuilder sql, int flags)
      returns an SQL select command
      Parameters:
      sql - the sql builder to add the command to
      flags - bitwise context flags for sql building (see "Select Context Flags")
    • getSelect

      public final String getSelect(int flags)
      returns an SQL select command for querying records.
      Parameters:
      flags - bitwise context flags for sql building (see "Select Context Flags")
      Returns:
      the SQL-Command
    • getSelect

      public final String getSelect()
      returns an SQL select command for querying records.
      Returns:
      the SQL-Command
    • getParams

      public abstract DBCmdParams getParams()
    • getParamValues

      public abstract Object[] getParamValues()
      returns an array holding all parameter values in the order of their occurrence. To ensure the correct order, getSelect() must be called first.
      Returns:
      an array of command parameter values
    • getDataType

      public abstract DataType getDataType()
      Returns the DataType selected by this command if only one column is returned If the command has more than one select expression DataType.UNKNOWN will be returned
      Returns:
      the DataType of the selected expression or DataType.UNKNOWN
    • result

      public DBColumnExpr result()
      Returns a ColumnExpr for the result of the query If the command must have exactly one select column otherwise a NotSupportedException is thrown;
      Returns:
      the result expression
    • addSQL

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

      public DBCommandExpr union(DBCommandExpr other)
      Constructs a new DBCombinedCmd object with this object, the key word= "UNION" and the selected DBCommandExpr.
      Parameters:
      other - the second DBCommandExpr
      Returns:
      the new DBCombinedCmd object
      See Also:
    • unionAll

      public DBCommandExpr unionAll(DBCommandExpr other)
      Constructs a new DBCombinedCmd object with this object, the key word= "UNION ALL" and the selected DBCommandExpr.
      Parameters:
      other - the second DBCommandExpr
      Returns:
      the new DBCombinedCmd object
      See Also:
    • intersect

      public DBCommandExpr intersect(DBCommandExpr other)
      Constructs a new DBCombinedCmd object with this object, the key word= "INTERSECT" and the selected DBCommandExpr.
      Parameters:
      other - the second DBCommandExpr
      Returns:
      the new DBCombinedCmd object
    • hasOrderBy

      public boolean hasOrderBy()
      Returns whether or not the command has order by set
      Returns:
      flag whether an order by is provided
    • getOrderBy

      public List<DBOrderByExpr> getOrderBy()
      Returns a copy of the defined order-bys.
      Returns:
      list of order-bys
    • clearOrderBy

      public void clearOrderBy()
      Clears the list of order by expressions.
    • orderBy

      public DBCommandExpr orderBy(DBOrderByExpr... exprs)
      Adds an order by expression the command
      Parameters:
      exprs - vararg of orderBy expressions
      Returns:
      itself (this)
      See Also:
    • orderBy

      public DBCommandExpr orderBy(DBColumnExpr expr, boolean desc)
      Adds an order by with ascending or descending order
      Parameters:
      expr - the expression for ordering
      desc - if true, the results from select statement will sort top down
      Returns:
      itself (this)
    • orderBy

      public DBCommandExpr orderBy(DBColumnExpr... exprs)
      Adds a list of columns to the orderBy clause in ascending order
      Parameters:
      exprs - vararg of order by expressions
      Returns:
      itself (this)
    • orderByUpper

      public DBCommandExpr orderByUpper(DBColumnExpr expr, boolean desc)
      Adds a case insensitive order by with ascending or descending order
      Parameters:
      expr - the expression for ordering
      desc - if true, the results from select statement will sort top down
      Returns:
      itself (this)
    • orderByUpper

      public DBCommandExpr orderByUpper(DBColumnExpr... exprs)
      Adds a list of columns to the orderBy clause in ascending order
      Parameters:
      exprs - vararg of order by expressions
      Returns:
      itself (this)
    • limitRows

      public DBCommandExpr limitRows(int numRows)
      set the maximum number of rows to return when executing a query command A negative value will remove the limit.
      Parameters:
      numRows - the number of rows to limit
      Returns:
      itself (this)
    • skipRows

      public DBCommandExpr skipRows(int numRows)
      sets the offset of the first row to return when executing a query command. A negative value will remove the offset.
      Parameters:
      numRows - the number of rows to skip
      Returns:
      itself (this)
    • clearLimit

      public void clearLimit()
      Clears a limit or offset set by calling limit() or offset()
    • getInsertInto

      public final String getInsertInto(DBTable table, List<DBColumnExpr> columns)
      Create the insert into SQL-Command which copies data from a select statement to a destination table.
      Parameters:
      table - the table
      columns - the columns
      Returns:
      the insert into SQL-Command
    • getInsertInto

      public final String getInsertInto(DBTable table)
      Create the insert into SQL-Command which copies data from a select statement to a destination table.
      Parameters:
      table - the table
      Returns:
      the insert into SQL-Command
    • createSQLBuilder

      protected DBSQLBuilder createSQLBuilder(String initalSQL)
      creates a new DBSQLBuilder
      Parameters:
      initalSQL - the initial sql fragment
      Returns:
      the new DBSQLBuilder
    • getCmdColumn

      protected DBColumnExpr getCmdColumn(DBColumnExpr col)
      wraps a column expression such that is specific for to this command and detached from its source.
      Parameters:
      col - the column expression to wrap
      Returns:
      column expression that is specific for to this command
    • addListExpr

      protected void addListExpr(DBSQLBuilder sql, List<? extends DBExpr> list, long context, String separator)
      Internally used to build a string from a list of database expressions
      Parameters:
      sql - the sql target buffer
      list - the list of expressions to add to the sql
      context - the sql command context
      separator - string to use as separator between list items
    • getInsertInto

      protected String getInsertInto(DBTable table, DBColumnExpr[] select, List<DBColumnExpr> columns)
      Create the insert into SQL-Command which copies data from a select statement to a destination table.
      Parameters:
      table - the table to insert
      select - the selected columns
      columns - the list of column expressions
      Returns:
      the insert into SQL-Command