com.alpine.sql

SQLExecutor

trait SQLExecutor extends AnyRef

Created by Paul Chang 2016-07-12 (6.1 release)

The purpose of SQLExecutor is to provide an object to facilitate the execution of commonly used SQL queries. All DDL (data definition language) methods are prefixed with "ddl...". These are methods that create, modify, or drop database objects (tables, views, etc.).

Each SQLExecutor is instantiated with a SQLGenerator, URL, and JDBC Connection. The SQLGenerator is used to generate SQL, and the Connection is used to execute SQL. The URL is informational. Several of the methods in SQLGenerator are called by corresponding methods in SQLExecutor and have similar signatures, but unlike SQLGenerator, SQLExecutor will actually execute SQL. SQLGenerator objects are database-type specific, so different SQLGenerator objects are instantiated for different database types.

Once instantiated, the SQLGenerator, URL, and Connection for a SQLExecutor do not change. Aside from database changes, this object has no side-effects once instantiated.

For certain methods, when specifying table names, fully qualify and delimit as necessary (i.e. "schemaname"."tablename"). Delimiting is required for table names with non-standard characters ([A-Za-z][A-Za-z0-9]*). Not all databases support delimiters or non-standard characters (such as Teradata). For those databases that support schemas, specifying the schema name is recommended.

For certain methods, when specifying column names, these must be a comma-separated string of columns that one would find in a SELECT query. This can include expressions that are aliased (i.e. sqlexpression AS aliasname). Any columns with non-standard characters should be delimited (i.e. "columnname"). When SELECTing from more than one table, if column names are not unique, then columns should be fully qualified (i.e. "schemaname"."tablename"."columnname" AS "columnalias").

For certain methods, when specifying a source table, it is permissible to specify more than one table as a join (i.e. table1 INNER JOIN table2 ON ...).

For certain methods, when specifying a whereClause, the literal "WHERE" should be included. Note that we can include anything that follows a FROM clause here, such as GROUP BY, ORDER BY, etc.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. SQLExecutor
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def ddlCreateTableAsSelect(selectQuery: String, destinationTable: String): Unit

    Generates a table based on a given SELECT query, not necessarily from any particular table.

    Generates a table based on a given SELECT query, not necessarily from any particular table. The entire SELECT query must be supplied to generate something like "CREATE TABLE destinationTable AS selectQuery". This method is useful for calls to UDFs or stored procedures that might be database-specific and don't conform to selecting columns from a source table.

    NOTE: Currently, this works only on certain databases like PostgreSQL, Greenplum, Oracle, MySQL, Teradata, but not MSSQL, which does not support CREATE TABLE ... AS SELECT ....

    Table name should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename").

    selectQuery is not necessarily a SELECT query, but any query that can feed the CREATE TABLE statement.

    selectQuery

    query (not necessary SELECT) to be used for CREATE TABLE

    destinationTable

    name of destination table to be created from SELECT query

  2. abstract def ddlCreateTableAsSelect(columns: String, sourceTable: String, destinationTable: String, whereClause: String): Unit

    Generates a table based on a SELECT query from the specified table, column list, and where clause.

    Generates a table based on a SELECT query from the specified table, column list, and where clause.

    Table names should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename"). It is acceptable to specify a table join as the sourceTable (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    The specified WHERE clause should include the "WHERE" keyword. Note that this is simply SQL that is appended to the query as "SELECT columns FROM sourceTable whereClause" and can include other SQL outside of just a WHERE clause, such as GROUP BY, ORDER BY, etc.

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationTable

    name of destination table to be created from SELECT query

    whereClause

    where clause of the SELECT query, including the literal "WHERE" keyword

  3. abstract def ddlCreateTableAsSelect(columns: String, sourceTable: String, destinationTable: String): Unit

    Generates a table based on a SELECT query from the specified table and column list.

    Generates a table based on a SELECT query from the specified table and column list.

    Table names should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename"). It is acceptable to specify a table join as the sourceTable (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationTable

    name of destination table to be created from SELECT query

  4. abstract def ddlCreateTableOrViewAsSelect(selectQuery: String, destinationTableOrView: String, isView: Boolean): Unit

    Generates a table or view based on a given SELECT query, not necessarily from any particular table.

    Generates a table or view based on a given SELECT query, not necessarily from any particular table. The entire SELECT query must be supplied to generate something like "CREATE TABLE destinationTable AS selectQuery" or "CREATE VIEW destinationView AS selectQuery. This method is useful for calls to UDFs or stored procedures that might be database-specific and don't conform to selecting columns from a source table.

    NOTE: Currently, table creation does not work on MSSQL, which does not support CREATE TABLE ... AS SELECT ....

    Table or view name should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename" or "schemaname"."viewname").

    selectQuery is not necessarily a SELECT query, but any query that can feed the CREATE TABLE statement.

    selectQuery

    query (not necessary SELECT) to be used for CREATE TABLE

    destinationTableOrView

    name of destination table to be created from SELECT query

    isView

    true if we are generating a view, false if we are generating a table

  5. abstract def ddlCreateTableOrViewAsSelect(columns: String, sourceTable: String, destinationTableOrView: String, whereClause: String, isView: Boolean): Unit

    Generates a table or view based on a SELECT query from an existing table, column list, and where clause.

    Generates a table or view based on a SELECT query from an existing table, column list, and where clause.

    Table and view names should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename" or "schemaname"."viewname"). It is acceptable to specify a table join as the sourceTable (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    The specified WHERE clause should include the "WHERE" keyword. Note that this is simply SQL that is appended to the query as "SELECT columns FROM sourceTable whereClause" and can include other SQL outside of just a WHERE clause, such as GROUP BY, ORDER BY, etc.

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationTableOrView

    name of destination table or view to be created from SELECT query

    whereClause

    where clause of the SELECT query, including the literal "WHERE" keyword

    isView

    true if we are generating a view, false if we are generating a table

  6. abstract def ddlCreateTableOrViewAsSelect(columns: String, sourceTable: String, destinationTableOrView: String, isView: Boolean): Unit

    Generates a table or view based on a SELECT query from an existing table and column list.

    Generates a table or view based on a SELECT query from an existing table and column list.

    Table and view names should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename" or "schemaname"."viewname"). It is acceptable to specify a table join as the sourceTable (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationTableOrView

    name of destination table or view to be created from SELECT query

    isView

    true if we are generating a view, false if we are generating a table

  7. abstract def ddlCreateViewAsSelect(selectQuery: String, destinationView: String): Unit

    Generates a view based on a given SELECT query, not necessarily from any particular table.

    Generates a view based on a given SELECT query, not necessarily from any particular table. The entire SELECT query must be supplied to generate something like "CREATE VIEW destinationTable AS selectQuery". This method is useful for calls to UDFs or stored procedures that might be database-specific and don't conform to selecting columns from a source table.

    Table name should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename").

    selectQuery is not necessarily a SELECT query, but any query that can feed the CREATE TABLE statement.

    selectQuery

    query (not necessary SELECT) to be used for CREATE VIEW

    destinationView

    name of destination table to be created from SELECT query

  8. abstract def ddlCreateViewAsSelect(columns: String, sourceTable: String, destinationView: String, whereClause: String): Unit

    Generates a view based on a SELECT query from the specified table, column list, and where clause.

    Generates a view based on a SELECT query from the specified table, column list, and where clause.

    Table and view names should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename" or "schemaname"."viewname"). It is acceptable to specify a table join as the sourceTable (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    The specified WHERE clause should include the "WHERE" keyword. Note that this is simply SQL that is appended to the query as "SELECT columns FROM sourceTable whereClause" and can include other SQL outside of just a WHERE clause, such as GROUP BY, ORDER BY, etc.

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationView

    name of destination view to be created from SELECT query

    whereClause

    where clause of the SELECT query, including the literal "WHERE" keyword

  9. abstract def ddlCreateViewAsSelect(columns: String, sourceTable: String, destinationView: String): Unit

    Generates a view based on a SELECT query from the specified table and column list.

    Generates a view based on a SELECT query from the specified table and column list.

    Table and view names should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename" or "schemaname"."viewname"). It is acceptable to specify a table join as the sourceTable (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationView

    name of destination view to be created from SELECT query

  10. abstract def ddlDropTableIfExists(tableName: String, cascadeFlag: Boolean): Unit

    Drops table if it exists, optionally cascade drop all dependent objects

    Drops table if it exists, optionally cascade drop all dependent objects

    Note: Table name should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename").

    Note: Not all databases support cascade drop. In such cases, a DROP TABLE without a CASCADE is attempted.

    tableName

    name of the table to be dropped

    cascadeFlag

    if true, drop any dependent objects as well (not supported on all databases)

  11. abstract def ddlDropTableIfExists(tableName: String): Unit

    Drops table if it exists

    Drops table if it exists

    Note: Table name should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename").

    tableName

    name of the table to be dropped

  12. abstract def ddlDropTableOrViewIfExists(tableOrViewName: String, cascadeFlag: Boolean): Unit

    Drops table or view if it exists, optionally cascade drop all dependent objects.

    Drops table or view if it exists, optionally cascade drop all dependent objects. SQLExecutor attempts to drop a table with the given name, and then a view with the given name

    Note: Table or view name should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename" or "schemaname"."viewname").

    Note: Not all databases support cascade drop. In such cases, a DROP TABLE or DROP VIEW without a CASCADE is attempted.

    tableOrViewName

    name of the table or view to be dropped

    cascadeFlag

    if true, drop any dependent objects as well (not supported on all databases)

  13. abstract def ddlDropTableOrViewIfExists(tableOrViewName: String): Unit

    Drops table or view if it exists.

    Drops table or view if it exists. SQLExecutor attempts to drop a table with the given name, and then a view with the given name

    Note: Table or view name should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename" or "schemaname"."viewname").

    tableOrViewName

    name of the table or view to be dropped

  14. abstract def ddlDropViewIfExists(viewName: String, cascadeFlag: Boolean): Unit

    Drops view if it exists, optionally cascade drop all dependent objects

    Drops view if it exists, optionally cascade drop all dependent objects

    Note: View name should be fully qualified and delimited, if necessary (i.e. "schemaname"."viewname").

    Note: Not all databases support cascade drop. In such cases, a DROP VIEW without a CASCADE is attempted.

    viewName

    name of the view to be dropped

    cascadeFlag

    if true, drop any dependent objects as well (not supported on all databases)

  15. abstract def ddlDropViewIfExists(viewName: String): Unit

    Drops view if it exists

    Drops view if it exists

    Note: View name should be fully qualified and delimited, if necessary (i.e. "schemaname"."viewname").

    viewName

    name of the view to be dropped

  16. abstract def executeQuery(sql: String): Array[Array[AnyRef]]

    Executes a query that returns a ResultSet, but transforms it into an array of arrays of Objects.

    Executes a query that returns a ResultSet, but transforms it into an array of arrays of Objects.

    sql

    query to execute, assumes a single ResultSet will be generated from it.

    returns

    Array of Array of Objects, transformed from ResultSet

  17. abstract def executeQuery[R](sql: String, resultSetParser: SQLExecutorResultSetParser[R]): R

    Executes a query that returns a ResultSet and applies the ResultSetParser object to it.

    Executes a query that returns a ResultSet and applies the ResultSetParser object to it.

    R

    Type parameter returned by SQLExecutorResultSetParser

    sql

    query to execute, assumes a single ResultSet will be generated from it.

    resultSetParser

    SQLExecutorResultSetParser object that takes a ResultSet and parses it to return something

    returns

    Invocation of resultSetParser on ResultSet, returns object of data type R

  18. abstract def executeQuery[R](sql: String, resultSetParser: (ResultSet) ⇒ R): R

    Executes a query that returns a ResultSet and applies the function to it.

    Executes a query that returns a ResultSet and applies the function to it.

    R

    Type parameter returned by resultSetParser

    sql

    query to execute, assumes a single ResultSet will be generated from it.

    resultSetParser

    function that takes a ResultSet and returns something

    returns

    Invocation of resultSetParser on ResultSet, returns object of data type R

  19. abstract def executeUpdate(sql: String): Int

    Executes a DML-like query that INSERTs, UPDATEs, or DELETEs rows.

    Executes a DML-like query that INSERTs, UPDATEs, or DELETEs rows.

    sql

    DML query to execute

    returns

    number of rows affected or 0

  20. abstract def getColumnDefs(objectName: String): Seq[ColumnDef]

    Generates the ColumnDef representations for columns of the given object.

    Generates the ColumnDef representations for columns of the given object.

    objectName

    The fully quoted object name.

    returns

    The ColumnDefs of the object.

    Annotations
    @throws( classOf[SQLException] )
    Exceptions thrown
    java.sql.SQLException

    Throws exception if the object does not exist.

  21. abstract def getConnection: Connection

    Returns JDBC Connection object embedded within this SQLExecutor.

    Returns JDBC Connection object embedded within this SQLExecutor. This is also the same Connection that this SQLExecutor uses to execute SQL.

    returns

    the JDBC Connection object embedded within this SQLExecutor.

  22. abstract def getRowCount(tableOrViewName: String): Long

    Returns number of rows from a table or view.

    Returns number of rows from a table or view.

    tableOrViewName

    name of table or view for which to count rows

    returns

    number of rows found

  23. abstract def getSQLGenerator: SQLGenerator

    Returns the SQLGenerator object used by this SQLExecutor to generate SQL strings.

    Returns the SQLGenerator object used by this SQLExecutor to generate SQL strings. SQLGenerator objects are database-type specific, so different SQLGenerator objects are instantiated for different database types.

    returns

    the SQLGenerator object that is embedded within this SQLExecutor.

  24. abstract def getURL: String

    Returns the JDBC URL that was used to create the JDBC Connection object that is embedded within this SQLExecutor.

    Returns the JDBC URL that was used to create the JDBC Connection object that is embedded within this SQLExecutor. The URL is useful in determining the type of the database and other connection information, but does not include security credentials.

    returns

    the URL that was used to create the JDBC Connection object embedded within this SQLExecutor.

  25. abstract def tableOrViewExists(tableOrViewName: String): Boolean

    Checks if table or view exists, and if so, returns true.

    Checks if table or view exists, and if so, returns true.

    tableOrViewName

    name of table or view to check

    returns

    true if the table or view does exist, false otherwise

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  18. def toString(): String

    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped