java.lang.Object
edu.internet2.middleware.grouper.ext.org.apache.ddlutils.util.JdbcSupport
edu.internet2.middleware.grouper.ext.org.apache.ddlutils.platform.PlatformImplBase
All Implemented Interfaces:
Platform
Direct Known Subclasses:
AxionPlatform, CloudscapePlatform, Db2Platform, FirebirdPlatform, HsqlDbPlatform, InterbasePlatform, MckoiPlatform, MSSqlPlatform, MySqlPlatform, Oracle8Platform, PostgreSqlPlatform, SapDbPlatform, SybasePlatform

public abstract class PlatformImplBase extends JdbcSupport implements Platform
Base class for platform implementations.
Version:
$Revision: 231110 $
  • Field Details

    • MODEL_DEFAULT_NAME

      protected static final String MODEL_DEFAULT_NAME
      The default name for models read from the database, if no name as given.
      See Also:
  • Constructor Details

    • PlatformImplBase

      public PlatformImplBase()
  • Method Details

    • getSqlBuilder

      public SqlBuilder getSqlBuilder()
      Returns the sql builder for the this platform.
      Specified by:
      getSqlBuilder in interface Platform
      Returns:
      The sql builder
    • setSqlBuilder

      protected void setSqlBuilder(SqlBuilder builder)
      Sets the sql builder for this platform.
      Parameters:
      builder - The sql builder
    • getModelReader

      public JdbcModelReader getModelReader()
      Returns the model reader (which reads a database model from a live database) for this platform.
      Specified by:
      getModelReader in interface Platform
      Returns:
      The model reader
    • setModelReader

      protected void setModelReader(JdbcModelReader modelReader)
      Sets the model reader for this platform.
      Parameters:
      modelReader - The model reader
    • getPlatformInfo

      public PlatformInfo getPlatformInfo()
      Returns the info object for this platform.
      Specified by:
      getPlatformInfo in interface Platform
      Returns:
      The info object
    • isScriptModeOn

      public boolean isScriptModeOn()
      Determines whether script mode is on. This means that the generated SQL is not intended to be sent directly to the database but rather to be saved in a SQL script file. Per default, script mode is off.
      Specified by:
      isScriptModeOn in interface Platform
      Returns:
      true if script mode is on
    • setScriptModeOn

      public void setScriptModeOn(boolean scriptModeOn)
      Specifies whether script mode is on. This means that the generated SQL is not intended to be sent directly to the database but rather to be saved in a SQL script file.
      Specified by:
      setScriptModeOn in interface Platform
      Parameters:
      scriptModeOn - true if script mode is on
    • isSqlCommentsOn

      public boolean isSqlCommentsOn()
      Determines whether SQL comments are generated.
      Specified by:
      isSqlCommentsOn in interface Platform
      Returns:
      true if SQL comments shall be generated
    • setSqlCommentsOn

      public void setSqlCommentsOn(boolean sqlCommentsOn)
      Specifies whether SQL comments shall be generated.
      Specified by:
      setSqlCommentsOn in interface Platform
      Parameters:
      sqlCommentsOn - true if SQL comments shall be generated
    • isDelimitedIdentifierModeOn

      public boolean isDelimitedIdentifierModeOn()
      Determines whether delimited identifiers are used or normal SQL92 identifiers (which may only contain alphanumerical characters and the underscore, must start with a letter and cannot be a reserved keyword). Per default, delimited identifiers are not used
      Specified by:
      isDelimitedIdentifierModeOn in interface Platform
      Returns:
      true if delimited identifiers are used
    • setDelimitedIdentifierModeOn

      public void setDelimitedIdentifierModeOn(boolean delimitedIdentifierModeOn)
      Specifies whether delimited identifiers are used or normal SQL92 identifiers.
      Specified by:
      setDelimitedIdentifierModeOn in interface Platform
      Parameters:
      delimitedIdentifierModeOn - true if delimited identifiers shall be used
    • isIdentityOverrideOn

      public boolean isIdentityOverrideOn()
      Determines whether SQL insert statements can specify values for identity columns. This setting is only relevant if the database supports it (PlatformInfo.isIdentityOverrideAllowed()). If this is off, then the insert methods will ignore values for identity columns.
      Specified by:
      isIdentityOverrideOn in interface Platform
      Returns:
      true if identity override is enabled (the default)
    • setIdentityOverrideOn

      public void setIdentityOverrideOn(boolean identityOverrideOn)
      Specifies whether SQL insert statements can specify values for identity columns. This setting is only relevant if the database supports it (PlatformInfo.isIdentityOverrideAllowed()). If this is off, then the insert methods will ignore values for identity columns.
      Specified by:
      setIdentityOverrideOn in interface Platform
      Parameters:
      identityOverrideOn - true if identity override is enabled (the default)
    • isForeignKeysSorted

      public boolean isForeignKeysSorted()
      Determines whether foreign keys of a table read from a live database are alphabetically sorted.
      Specified by:
      isForeignKeysSorted in interface Platform
      Returns:
      true if read foreign keys are sorted
    • setForeignKeysSorted

      public void setForeignKeysSorted(boolean foreignKeysSorted)
      Specifies whether foreign keys read from a live database, shall be alphabetically sorted.
      Specified by:
      setForeignKeysSorted in interface Platform
      Parameters:
      foreignKeysSorted - true if read foreign keys shall be sorted
    • getLog

      protected org.apache.commons.logging.Log getLog()
      Returns the log for this platform.
      Returns:
      The log
    • logWarnings

      protected void logWarnings(Connection connection) throws SQLException
      Logs any warnings associated to the given connection. Note that the connection needs to be open for this.
      Parameters:
      connection - The open connection
      Throws:
      SQLException
    • evaluateBatch

      public int evaluateBatch(String sql, boolean continueOnError) throws DatabaseOperationException
      Executes a series of sql statements which must be seperated by the delimiter configured as PlatformInfo.getSqlCommandDelimiter() of the info object of this platform.
      Specified by:
      evaluateBatch in interface Platform
      Parameters:
      sql - The sql statements to execute
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Returns:
      The number of errors
      Throws:
      DatabaseOperationException
    • evaluateBatch

      public int evaluateBatch(Connection connection, String sql, boolean continueOnError) throws DatabaseOperationException
      Executes a series of sql statements which must be seperated by the delimiter configured as PlatformInfo.getSqlCommandDelimiter() of the info object of this platform. TODO: consider outputting a collection of String or some kind of statement object from the SqlBuilder instead of having to parse strings here
      Specified by:
      evaluateBatch in interface Platform
      Parameters:
      connection - The connection to the database
      sql - The sql statements to execute
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Returns:
      The number of errors
      Throws:
      DatabaseOperationException
    • shutdownDatabase

      public void shutdownDatabase() throws DatabaseOperationException
      Performs a shutdown at the database. This is necessary for some embedded databases which otherwise would be locked and thus would refuse other connections. Note that this does not change the database structure or data in it in any way.
      Specified by:
      shutdownDatabase in interface Platform
      Throws:
      DatabaseOperationException
    • shutdownDatabase

      public void shutdownDatabase(Connection connection) throws DatabaseOperationException
      Performs a shutdown at the database. This is necessary for some embedded databases which otherwise would be locked and thus would refuse other connections. Note that this does not change the database structure or data in it in any way.
      Specified by:
      shutdownDatabase in interface Platform
      Parameters:
      connection - The connection to the database
      Throws:
      DatabaseOperationException
    • createDatabase

      public void createDatabase(String jdbcDriverClassName, String connectionUrl, String username, String password, Map parameters) throws DatabaseOperationException, UnsupportedOperationException
      Creates the database specified by the given parameters. Please note that this method does not use a data source set via Platform.setDataSource(DataSource) because it is not possible to retrieve the connection information from it without establishing a connection.
      The given connection url is the url that you'd use to connect to the already-created database.
      On some platforms, this method suppurts additional parameters. These are documented in the manual section for the individual platforms.
      Specified by:
      createDatabase in interface Platform
      Parameters:
      jdbcDriverClassName - The jdbc driver class name
      connectionUrl - The url to connect to the database if it were already created
      username - The username for creating the database
      password - The password for creating the database
      parameters - Additional parameters relevant to database creation (which are platform specific)
      Throws:
      DatabaseOperationException
      UnsupportedOperationException
    • dropDatabase

      public void dropDatabase(String jdbcDriverClassName, String connectionUrl, String username, String password) throws DatabaseOperationException, UnsupportedOperationException
      Drops the database specified by the given parameters. Please note that this method does not use a data source set via Platform.setDataSource(DataSource) because it is not possible to retrieve the connection information from it without establishing a connection.
      Specified by:
      dropDatabase in interface Platform
      Parameters:
      jdbcDriverClassName - The jdbc driver class name
      connectionUrl - The url to connect to the database
      username - The username for creating the database
      password - The password for creating the database
      Throws:
      DatabaseOperationException
      UnsupportedOperationException
    • createTables

      public void createTables(Database model, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException
      Creates the tables defined in the database model.
      Specified by:
      createTables in interface Platform
      Parameters:
      model - The database model
      dropTablesFirst - Whether to drop the tables prior to creating them (anew)
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Throws:
      DatabaseOperationException
    • createTables

      public void createTables(Connection connection, Database model, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException
      Creates the tables defined in the database model.
      Specified by:
      createTables in interface Platform
      Parameters:
      connection - The connection to the database
      model - The database model
      dropTablesFirst - Whether to drop the tables prior to creating them (anew)
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Throws:
      DatabaseOperationException
    • getCreateTablesSql

      public String getCreateTablesSql(Database model, boolean dropTablesFirst, boolean continueOnError)
      Returns the SQL for creating the tables defined in the database model.
      Specified by:
      getCreateTablesSql in interface Platform
      Parameters:
      model - The database model
      dropTablesFirst - Whether to drop the tables prior to creating them (anew)
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Returns:
      The SQL statements
    • createTables

      public void createTables(Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException
      Creates the tables defined in the database model.
      Specified by:
      createTables in interface Platform
      Parameters:
      model - The database model
      params - The parameters used in the creation
      dropTablesFirst - Whether to drop the tables prior to creating them (anew)
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Throws:
      DatabaseOperationException
    • createTables

      public void createTables(Connection connection, Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException
      Creates the tables defined in the database model.
      Specified by:
      createTables in interface Platform
      Parameters:
      connection - The connection to the database
      model - The database model
      params - The parameters used in the creation
      dropTablesFirst - Whether to drop the tables prior to creating them (anew)
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Throws:
      DatabaseOperationException
    • getCreateTablesSql

      public String getCreateTablesSql(Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError)
      Returns the SQL for creating the tables defined in the database model.
      Specified by:
      getCreateTablesSql in interface Platform
      Parameters:
      model - The database model
      params - The parameters used in the creation
      dropTablesFirst - Whether to drop the tables prior to creating them (anew)
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Returns:
      The SQL statements
    • alterTables

      public void alterTables(Database desiredDb, boolean continueOnError) throws DatabaseOperationException
      Alters the database schema so that it match the given model.
      Specified by:
      alterTables in interface Platform
      Parameters:
      desiredDb - The desired database schema
      continueOnError - Whether to continue with the next sql statement when an error occurred
      Throws:
      DatabaseOperationException
    • getAlterTablesSql

      public String getAlterTablesSql(Database desiredDb) throws DatabaseOperationException
      Returns the SQL for altering the database schema so that it match the given model.
      Specified by:
      getAlterTablesSql in interface Platform
      Parameters:
      desiredDb - The desired database schema
      Returns:
      The SQL statements
      Throws:
      DatabaseOperationException
    • alterTables

      public void alterTables(Database desiredDb, CreationParameters params, boolean continueOnError) throws DatabaseOperationException
      Alters the database schema so that it match the given model.
      Specified by:
      alterTables in interface Platform
      Parameters:
      desiredDb - The desired database schema
      params - The parameters used in the creation
      continueOnError - Whether to continue with the next sql statement when an error occurred
      Throws:
      DatabaseOperationException
    • getAlterTablesSql

      public String getAlterTablesSql(Database desiredDb, CreationParameters params) throws DatabaseOperationException
      Returns the SQL for altering the database schema so that it match the given model.
      Specified by:
      getAlterTablesSql in interface Platform
      Parameters:
      desiredDb - The desired database schema
      params - The parameters used in the creation
      Returns:
      The SQL statements
      Throws:
      DatabaseOperationException
    • alterTables

      public void alterTables(Connection connection, Database desiredModel, boolean continueOnError) throws DatabaseOperationException
      Alters the database schema so that it match the given model.
      Specified by:
      alterTables in interface Platform
      Parameters:
      connection - A connection to the existing database that shall be modified
      desiredModel - The desired database schema
      continueOnError - Whether to continue with the next sql statement when an error occurred
      Throws:
      DatabaseOperationException
    • getAlterTablesSql

      public String getAlterTablesSql(Connection connection, Database desiredModel) throws DatabaseOperationException
      Returns the SQL for altering the database schema so that it match the given model.
      Specified by:
      getAlterTablesSql in interface Platform
      Parameters:
      connection - A connection to the existing database that shall be modified
      desiredModel - The desired database schema
      Returns:
      The SQL statements
      Throws:
      DatabaseOperationException
    • alterTables

      public void alterTables(Connection connection, Database desiredModel, CreationParameters params, boolean continueOnError) throws DatabaseOperationException
      Alters the database schema so that it match the given model.
      Specified by:
      alterTables in interface Platform
      Parameters:
      connection - A connection to the existing database that shall be modified
      desiredModel - The desired database schema
      params - The parameters used in the creation
      continueOnError - Whether to continue with the next sql statement when an error occurred
      Throws:
      DatabaseOperationException
    • getAlterTablesSql

      public String getAlterTablesSql(Connection connection, Database desiredModel, CreationParameters params) throws DatabaseOperationException
      Returns the SQL for altering the database schema so that it match the given model.
      Specified by:
      getAlterTablesSql in interface Platform
      Parameters:
      connection - A connection to the existing database that shall be modified
      desiredModel - The desired database schema
      params - The parameters used in the creation
      Returns:
      The SQL statements
      Throws:
      DatabaseOperationException
    • alterTables

      public void alterTables(String catalog, String schema, String[] tableTypes, Database desiredModel, boolean continueOnError) throws DatabaseOperationException
      Alters the database schema so that it match the given model.
      Specified by:
      alterTables in interface Platform
      Parameters:
      catalog - The catalog in the existing database to read (can be a pattern); use null for the platform-specific default value
      schema - The schema in the existing database to read (can be a pattern); use null for the platform-specific default value
      tableTypes - The table types to read from the existing database; use null or an empty array for the platform-specific default value
      desiredModel - The desired database schema
      continueOnError - Whether to continue with the next sql statement when an error occurred
      Throws:
      DatabaseOperationException
    • getAlterTablesSql

      public String getAlterTablesSql(String catalog, String schema, String[] tableTypes, Database desiredModel) throws DatabaseOperationException
      Returns the SQL for altering the database schema so that it match the given model.
      Specified by:
      getAlterTablesSql in interface Platform
      Parameters:
      catalog - The catalog in the existing database to read (can be a pattern); use null for the platform-specific default value
      schema - The schema in the existing database to read (can be a pattern); use null for the platform-specific default value
      tableTypes - The table types to read from the existing database; use null or an empty array for the platform-specific default value
      desiredModel - The desired database schema
      Returns:
      The SQL statements
      Throws:
      DatabaseOperationException
    • alterTables

      public void alterTables(String catalog, String schema, String[] tableTypes, Database desiredModel, CreationParameters params, boolean continueOnError) throws DatabaseOperationException
      Alters the database schema so that it match the given model.
      Specified by:
      alterTables in interface Platform
      Parameters:
      catalog - The catalog in the existing database to read (can be a pattern); use null for the platform-specific default value
      schema - The schema in the existing database to read (can be a pattern); use null for the platform-specific default value
      tableTypes - The table types to read from the existing database; use null or an empty array for the platform-specific default value
      desiredModel - The desired database schema
      params - The parameters used in the creation
      continueOnError - Whether to continue with the next sql statement when an error occurred
      Throws:
      DatabaseOperationException
    • getAlterTablesSql

      public String getAlterTablesSql(String catalog, String schema, String[] tableTypes, Database desiredModel, CreationParameters params) throws DatabaseOperationException
      Returns the SQL for altering the database schema so that it match the given model.
      Specified by:
      getAlterTablesSql in interface Platform
      Parameters:
      catalog - The catalog in the existing database to read (can be a pattern); use null for the platform-specific default value
      schema - The schema in the existing database to read (can be a pattern); use null for the platform-specific default value
      tableTypes - The table types to read from the existing database; use null or an empty array for the platform-specific default value
      desiredModel - The desired database schema
      params - The parameters used in the creation
      Returns:
      The SQL statements
      Throws:
      DatabaseOperationException
    • alterTables

      public void alterTables(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredModel, boolean continueOnError) throws DatabaseOperationException
      Alters the database schema so that it match the given model.
      Specified by:
      alterTables in interface Platform
      Parameters:
      connection - A connection to the existing database that shall be modified
      catalog - The catalog in the existing database to read (can be a pattern); use null for the platform-specific default value
      schema - The schema in the existing database to read (can be a pattern); use null for the platform-specific default value
      tableTypes - The table types to read from the existing database; use null or an empty array for the platform-specific default value
      desiredModel - The desired database schema
      continueOnError - Whether to continue with the next sql statement when an error occurred
      Throws:
      DatabaseOperationException
    • getAlterTablesSql

      public String getAlterTablesSql(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredModel) throws DatabaseOperationException
      Returns the SQL for altering the database schema so that it match the given model.
      Specified by:
      getAlterTablesSql in interface Platform
      Parameters:
      connection - A connection to the existing database that shall be modified
      catalog - The catalog in the existing database to read (can be a pattern); use null for the platform-specific default value
      schema - The schema in the existing database to read (can be a pattern); use null for the platform-specific default value
      tableTypes - The table types to read from the existing database; use null or an empty array for the platform-specific default value
      desiredModel - The desired database schema
      Returns:
      The SQL statements
      Throws:
      DatabaseOperationException
    • alterTables

      public void alterTables(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredModel, CreationParameters params, boolean continueOnError) throws DatabaseOperationException
      Alters the database schema so that it match the given model.
      Specified by:
      alterTables in interface Platform
      Parameters:
      connection - A connection to the existing database that shall be modified
      catalog - The catalog in the existing database to read (can be a pattern); use null for the platform-specific default value
      schema - The schema in the existing database to read (can be a pattern); use null for the platform-specific default value
      tableTypes - The table types to read from the existing database; use null or an empty array for the platform-specific default value
      desiredModel - The desired database schema
      params - The parameters used in the creation
      continueOnError - Whether to continue with the next sql statement when an error occurred
      Throws:
      DatabaseOperationException
    • getAlterTablesSql

      public String getAlterTablesSql(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredModel, CreationParameters params) throws DatabaseOperationException
      Returns the SQL for altering the database schema so that it match the given model.
      Specified by:
      getAlterTablesSql in interface Platform
      Parameters:
      connection - A connection to the existing database that shall be modified
      catalog - The catalog in the existing database to read (can be a pattern); use null for the platform-specific default value
      schema - The schema in the existing database to read (can be a pattern); use null for the platform-specific default value
      tableTypes - The table types to read from the existing database; use null or an empty array for the platform-specific default value
      desiredModel - The desired database schema
      params - The parameters used in the creation
      Returns:
      The SQL statements
      Throws:
      DatabaseOperationException
    • dropTable

      public void dropTable(Connection connection, Database model, Table table, boolean continueOnError) throws DatabaseOperationException
      Drops the specified table and all foreign keys pointing to it.
      Specified by:
      dropTable in interface Platform
      Parameters:
      connection - The connection to the database
      model - The database model
      table - The table to drop
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Throws:
      DatabaseOperationException
    • dropTable

      public void dropTable(Database model, Table table, boolean continueOnError) throws DatabaseOperationException
      Drops the specified table and all foreign keys pointing to it.
      Specified by:
      dropTable in interface Platform
      Parameters:
      model - The database model
      table - The table to drop
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Throws:
      DatabaseOperationException
    • getDropTableSql

      public String getDropTableSql(Database model, Table table, boolean continueOnError)
      Returns the SQL for dropping the given table and all foreign keys pointing to it.
      Specified by:
      getDropTableSql in interface Platform
      Parameters:
      model - The database model
      table - The table to drop
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Returns:
      The SQL statements
    • dropTables

      public void dropTables(Database model, boolean continueOnError) throws DatabaseOperationException
      Drops the tables defined in the given database.
      Specified by:
      dropTables in interface Platform
      Parameters:
      model - The database model
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Throws:
      DatabaseOperationException
    • dropTables

      public void dropTables(Connection connection, Database model, boolean continueOnError) throws DatabaseOperationException
      Drops the tables defined in the given database.
      Specified by:
      dropTables in interface Platform
      Parameters:
      connection - The connection to the database
      model - The database model
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Throws:
      DatabaseOperationException
    • getDropTablesSql

      public String getDropTablesSql(Database model, boolean continueOnError)
      Returns the SQL for dropping the tables defined in the given database.
      Specified by:
      getDropTablesSql in interface Platform
      Parameters:
      model - The database model
      continueOnError - Whether to continue executing the sql commands when an error occurred
      Returns:
      The SQL statements
    • query

      public Iterator query(Database model, String sql) throws DatabaseOperationException
      Performs the given SQL query returning an iterator over the results.
      Specified by:
      query in interface Platform
      Parameters:
      model - The database model to use
      sql - The sql query to perform
      Returns:
      An iterator for the dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • query

      public Iterator query(Database model, String sql, Collection parameters) throws DatabaseOperationException
      Performs the given parameterized SQL query returning an iterator over the results.
      Specified by:
      query in interface Platform
      Parameters:
      model - The database model to use
      sql - The sql query to perform
      parameters - The query parameter values
      Returns:
      An iterator for the dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • query

      public Iterator query(Database model, String sql, Table[] queryHints) throws DatabaseOperationException
      Performs the given SQL query returning an iterator over the results.
      Specified by:
      query in interface Platform
      Parameters:
      model - The database model to use
      sql - The sql query to perform
      queryHints - The tables that are queried (optional)
      Returns:
      An iterator for the dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • query

      public Iterator query(Database model, String sql, Collection parameters, Table[] queryHints) throws DatabaseOperationException
      Performs the given parameterized SQL query returning an iterator over the results.
      Specified by:
      query in interface Platform
      Parameters:
      model - The database model to use
      sql - The sql query to perform
      parameters - The query parameter values
      queryHints - The tables that are queried (optional)
      Returns:
      An iterator for the dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • fetch

      public List fetch(Database model, String sql) throws DatabaseOperationException
      Queries for a list of dyna beans representing rows of the given query. In contrast to the Platform.query(Database, String) method all beans will be materialized and the connection will be closed before returning the beans.
      Specified by:
      fetch in interface Platform
      Parameters:
      model - The database model to use
      sql - The sql query
      Returns:
      The dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • fetch

      public List fetch(Database model, String sql, Table[] queryHints) throws DatabaseOperationException
      Queries for a list of dyna beans representing rows of the given query. In contrast to the Platform.query(Database, String) method all beans will be materialized and the connection will be closed before returning the beans.
      Specified by:
      fetch in interface Platform
      Parameters:
      model - The database model to use
      sql - The sql query
      queryHints - The tables that are queried (optional)
      Returns:
      The dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • fetch

      public List fetch(Database model, String sql, int start, int end) throws DatabaseOperationException
      Queries for a list of dyna beans representing rows of the given query. In contrast to the Platform.query(Database, String) method all beans will be materialized and the connection will be closed before returning the beans. Also, the two int parameters specify which rows of the result set to use. If there are more rows than desired, they will be ignored (and not read from the database).
      Specified by:
      fetch in interface Platform
      Parameters:
      model - The database model to use
      sql - The sql query
      start - Row number to start from (0 for first row)
      end - Row number to stop at (inclusively; -1 for last row)
      Returns:
      The dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • fetch

      public List fetch(Database model, String sql, Table[] queryHints, int start, int end) throws DatabaseOperationException
      Queries for a list of dyna beans representing rows of the given query. In contrast to the Platform.query(Database, String, Table[]) method all beans will be materialized and the connection will be closed before returning the beans. Also, the two int parameters specify which rows of the result set to use. If there are more rows than desired, they will be ignored (and not read from the database).
      Specified by:
      fetch in interface Platform
      Parameters:
      model - The database model to use
      sql - The sql query
      queryHints - The tables that are queried (optional)
      start - Row number to start from (0 for first row)
      end - Row number to stop at (inclusively; -1 for last row)
      Returns:
      The dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • fetch

      public List fetch(Database model, String sql, Collection parameters) throws DatabaseOperationException
      Queries for a list of dyna beans representing rows of the given query. In contrast to the Platform.query(Database, String, Collection) method all beans will be materialized and the connection will be closed before returning the beans.
      Specified by:
      fetch in interface Platform
      Parameters:
      model - The database model to use
      sql - The parameterized query
      parameters - The parameter values
      Returns:
      The dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • fetch

      public List fetch(Database model, String sql, Collection parameters, int start, int end) throws DatabaseOperationException
      Queries for a list of dyna beans representing rows of the given query. In contrast to the Platform.query(Database, String, Collection) method all beans will be materialized and the connection will be closed before returning the beans. Also, the two int parameters specify which rows of the result set to use. If there are more rows than desired, they will be ignored (and not read from the database).
      Specified by:
      fetch in interface Platform
      Parameters:
      model - The database model to use
      sql - The parameterized sql query
      parameters - The parameter values
      start - Row number to start from (0 for first row)
      end - Row number to stop at (inclusively; -1 for last row)
      Returns:
      The dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • fetch

      public List fetch(Database model, String sql, Collection parameters, Table[] queryHints) throws DatabaseOperationException
      Queries for a list of dyna beans representing rows of the given query. In contrast to the Platform.query(Database, String, Collection) method all beans will be materialized and the connection will be closed before returning the beans.
      Specified by:
      fetch in interface Platform
      Parameters:
      model - The database model to use
      sql - The parameterized query
      parameters - The parameter values
      queryHints - The tables that are queried (optional)
      Returns:
      The dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • fetch

      public List fetch(Database model, String sql, Collection parameters, Table[] queryHints, int start, int end) throws DatabaseOperationException
      Queries for a list of dyna beans representing rows of the given query. In contrast to the Platform.query(Database, String, Collection, Table[]) method all beans will be materialized and the connection will be closed before returning the beans. Also, the two int parameters specify which rows of the result set to use. If there are more rows than desired, they will be ignored (and not read from the database).
      Specified by:
      fetch in interface Platform
      Parameters:
      model - The database model to use
      sql - The parameterized sql query
      parameters - The parameter values
      queryHints - The tables that are queried (optional)
      start - Row number to start from (0 for first row)
      end - Row number to stop at (inclusively; -1 for last row)
      Returns:
      The dyna beans resulting from the query
      Throws:
      DatabaseOperationException
    • createInsertSql

      protected String createInsertSql(Database model, SqlDynaClass dynaClass, SqlDynaProperty[] properties, org.apache.commons.beanutils.DynaBean bean)
      Creates the SQL for inserting an object of the given type. If a concrete bean is given, then a concrete insert statement is created, otherwise an insert statement usable in a prepared statement is build.
      Parameters:
      model - The database model
      dynaClass - The type
      properties - The properties to write
      bean - Optionally the concrete bean to insert
      Returns:
      The SQL required to insert an instance of the class
    • createSelectLastInsertIdSql

      protected String createSelectLastInsertIdSql(Database model, SqlDynaClass dynaClass)
      Creates the SQL for querying for the id generated by the last insert of an object of the given type.
      Parameters:
      model - The database model
      dynaClass - The type
      Returns:
      The SQL required for querying for the id, or null if the database does not support this
    • getInsertSql

      public String getInsertSql(Database model, org.apache.commons.beanutils.DynaBean dynaBean)
      Returns the sql for inserting the given bean.
      Specified by:
      getInsertSql in interface Platform
      Parameters:
      model - The database model to use
      dynaBean - The bean
      Returns:
      The insert sql
    • insert

      public void insert(Connection connection, Database model, org.apache.commons.beanutils.DynaBean dynaBean) throws DatabaseOperationException
      Inserts the bean. If one of the columns is an auto-incremented column, then the bean will also be updated with the column value generated by the database. Note that the connection will not be closed by this method.
      Specified by:
      insert in interface Platform
      Parameters:
      connection - The database connection
      model - The database model to use
      dynaBean - The bean
      Throws:
      DatabaseOperationException
    • insert

      public void insert(Database model, org.apache.commons.beanutils.DynaBean dynaBean) throws DatabaseOperationException
      Inserts the given DynaBean in the database, assuming the primary key values are specified.
      Specified by:
      insert in interface Platform
      Parameters:
      model - The database model to use
      dynaBean - The bean to insert
      Throws:
      DatabaseOperationException
    • insert

      public void insert(Connection connection, Database model, Collection dynaBeans) throws DatabaseOperationException
      Inserts the given beans. Note that a batch insert is used for subsequent beans of the same type. Also the properties for the primary keys are not updated in the beans. Hence you should not use this method when the primary key values are defined by the database (via a sequence or identity constraint). This method does not close the connection.
      Specified by:
      insert in interface Platform
      Parameters:
      connection - The database connection
      model - The database model to use
      dynaBeans - The beans
      Throws:
      DatabaseOperationException
    • insert

      public void insert(Database model, Collection dynaBeans) throws DatabaseOperationException
      Inserts the given beans in the database, assuming the primary key values are specified. Note that a batch insert is used for subsequent beans of the same type. Also the properties for the primary keys are not updated in the beans. Hence you should not use this method when the primary key values are defined by the database (via a sequence or identity constraint).
      Specified by:
      insert in interface Platform
      Parameters:
      model - The database model to use
      dynaBeans - The beans to insert
      Throws:
      DatabaseOperationException
    • beforeInsert

      protected void beforeInsert(Connection connection, Table table) throws SQLException
      Allows platforms to issue statements directly before rows are inserted into the specified table.
      Parameters:
      connection - The connection used for the insertion
      table - The table that the rows are inserted into
      Throws:
      SQLException
    • afterInsert

      protected void afterInsert(Connection connection, Table table) throws SQLException
      Allows platforms to issue statements directly after rows have been inserted into the specified table.
      Parameters:
      connection - The connection used for the insertion
      table - The table that the rows have been inserted into
      Throws:
      SQLException
    • createUpdateSql

      protected String createUpdateSql(Database model, SqlDynaClass dynaClass, SqlDynaProperty[] primaryKeys, SqlDynaProperty[] properties, org.apache.commons.beanutils.DynaBean bean)
      Creates the SQL for updating an object of the given type. If a concrete bean is given, then a concrete update statement is created, otherwise an update statement usable in a prepared statement is build.
      Parameters:
      model - The database model
      dynaClass - The type
      primaryKeys - The primary keys
      properties - The properties to write
      bean - Optionally the concrete bean to update
      Returns:
      The SQL required to update the instance
    • getUpdateSql

      public String getUpdateSql(Database model, org.apache.commons.beanutils.DynaBean dynaBean)
      Returns the sql for updating the given bean in the database.
      Specified by:
      getUpdateSql in interface Platform
      Parameters:
      model - The database model to use
      dynaBean - The bean
      Returns:
      The update sql
    • update

      public void update(Connection connection, Database model, org.apache.commons.beanutils.DynaBean dynaBean) throws DatabaseOperationException
      Updates the row which maps to the given bean.
      Specified by:
      update in interface Platform
      Parameters:
      connection - The database connection
      model - The database model to use
      dynaBean - The bean
      Throws:
      DatabaseOperationException
    • update

      public void update(Database model, org.apache.commons.beanutils.DynaBean dynaBean) throws DatabaseOperationException
      Updates the given bean in the database, assuming the primary key values are specified.
      Specified by:
      update in interface Platform
      Parameters:
      model - The database model to use
      dynaBean - The bean
      Throws:
      DatabaseOperationException
    • beforeUpdate

      protected void beforeUpdate(Connection connection, Table table) throws SQLException
      Allows platforms to issue statements directly before rows are updated in the specified table.
      Parameters:
      connection - The connection used for the update
      table - The table that the rows are updateed into
      Throws:
      SQLException
    • afterUpdate

      protected void afterUpdate(Connection connection, Table table) throws SQLException
      Allows platforms to issue statements directly after rows have been updated in the specified table.
      Parameters:
      connection - The connection used for the update
      table - The table that the rows have been updateed into
      Throws:
      SQLException
    • exists

      protected boolean exists(Connection connection, org.apache.commons.beanutils.DynaBean dynaBean)
      Determines whether the given dyna bean is stored in the database.
      Parameters:
      dynaBean - The bean
      connection - The connection
      Returns:
      true if this dyna bean has a primary key
    • store

      public void store(Database model, org.apache.commons.beanutils.DynaBean dynaBean) throws DatabaseOperationException
      Stores the given bean in the database, inserting it if there is no primary key otherwise the bean is updated in the database.
      Specified by:
      store in interface Platform
      Parameters:
      model - The database model to use
      dynaBean - The bean to store
      Throws:
      DatabaseOperationException
    • createDeleteSql

      protected String createDeleteSql(Database model, SqlDynaClass dynaClass, SqlDynaProperty[] primaryKeys, org.apache.commons.beanutils.DynaBean bean)
      Creates the SQL for deleting an object of the given type. If a concrete bean is given, then a concrete delete statement is created, otherwise a delete statement usable in a prepared statement is build.
      Parameters:
      model - The database model
      dynaClass - The type
      primaryKeys - The primary keys
      bean - Optionally the concrete bean to update
      Returns:
      The SQL required to delete the instance
    • getDeleteSql

      public String getDeleteSql(Database model, org.apache.commons.beanutils.DynaBean dynaBean)
      Returns the sql for deleting the given bean from the database.
      Specified by:
      getDeleteSql in interface Platform
      Parameters:
      model - The database model to use
      dynaBean - The bean
      Returns:
      The sql
    • delete

      public void delete(Database model, org.apache.commons.beanutils.DynaBean dynaBean) throws DatabaseOperationException
      Deletes the given bean from the database, assuming the primary key values are specified.
      Specified by:
      delete in interface Platform
      Parameters:
      model - The database model to use
      dynaBean - The bean to delete
      Throws:
      DatabaseOperationException
    • delete

      public void delete(Connection connection, Database model, org.apache.commons.beanutils.DynaBean dynaBean) throws DatabaseOperationException
      Deletes the row which maps to the given bean from the database.
      Specified by:
      delete in interface Platform
      Parameters:
      connection - The database connection
      model - The database model to use
      dynaBean - The bean
      Throws:
      DatabaseOperationException
    • readModelFromDatabase

      public Database readModelFromDatabase(String name) throws DatabaseOperationException
      Reads the database model from the live database as specified by the data source set for this platform.
      Specified by:
      readModelFromDatabase in interface Platform
      Parameters:
      name - The name of the resulting database; null when the default name (the catalog) is desired which might be null itself though
      Returns:
      The database model
      Throws:
      DatabaseOperationException - If an error occurred during reading the model
    • readModelFromDatabase

      public Database readModelFromDatabase(Connection connection, String name) throws DatabaseOperationException
      Reads the database model from the live database to which the given connection is pointing.
      Specified by:
      readModelFromDatabase in interface Platform
      Parameters:
      connection - The connection to the database
      name - The name of the resulting database; null when the default name (the catalog) is desired which might be null itself though
      Returns:
      The database model
      Throws:
      DatabaseOperationException - If an error occurred during reading the model
    • readModelFromDatabase

      public Database readModelFromDatabase(String name, String catalog, String schema, String[] tableTypes) throws DatabaseOperationException
      Reads the database model from the live database as specified by the data source set for this platform.
      Specified by:
      readModelFromDatabase in interface Platform
      Parameters:
      name - The name of the resulting database; null when the default name (the catalog) is desired which might be null itself though
      catalog - The catalog to access in the database; use null for the default value
      schema - The schema to access in the database; use null for the default value
      tableTypes - The table types to process; use null or an empty list for the default ones
      Returns:
      The database model
      Throws:
      DatabaseOperationException - If an error occurred during reading the model
    • readModelFromDatabase

      public Database readModelFromDatabase(Connection connection, String name, String catalog, String schema, String[] tableTypes) throws DatabaseOperationException
      Reads the database model from the live database to which the given connection is pointing.
      Specified by:
      readModelFromDatabase in interface Platform
      Parameters:
      connection - The connection to the database
      name - The name of the resulting database; null when the default name (the catalog) is desired which might be null itself though
      catalog - The catalog to access in the database; use null for the default value
      schema - The schema to access in the database; use null for the default value
      tableTypes - The table types to process; use null or an empty list for the default ones
      Returns:
      The database model
      Throws:
      DatabaseOperationException - If an error occurred during reading the model
    • postprocessModelFromDatabase

      protected void postprocessModelFromDatabase(Database model)
      Allows the platform to postprocess the model just read from the database.
      Parameters:
      model - The model
    • toColumnValues

      protected HashMap toColumnValues(SqlDynaProperty[] properties, org.apache.commons.beanutils.DynaBean bean)
      Derives the column values for the given dyna properties from the dyna bean.
      Parameters:
      properties - The properties
      bean - The bean
      Returns:
      The values indexed by the column names
    • setObject

      protected void setObject(PreparedStatement statement, int sqlIndex, org.apache.commons.beanutils.DynaBean dynaBean, SqlDynaProperty property) throws SQLException
      Sets a parameter of the prepared statement based on the type of the column of the property.
      Parameters:
      statement - The statement
      sqlIndex - The index of the parameter to set in the statement
      dynaBean - The bean of which to take the value
      property - The property of the bean, which also defines the corresponding column
      Throws:
      SQLException
    • setStatementParameterValue

      protected void setStatementParameterValue(PreparedStatement statement, int sqlIndex, int typeCode, Object value) throws SQLException
      This is the core method to set the parameter of a prepared statement to a given value. The primary purpose of this method is to call the appropriate method on the statement, and to give database-specific implementations the ability to change this behavior.
      Parameters:
      statement - The statement
      sqlIndex - The parameter index
      typeCode - The JDBC type code
      value - The value
      Throws:
      SQLException - If an error occurred while setting the parameter value
    • getObjectFromResultSet

      protected Object getObjectFromResultSet(ResultSet resultSet, String columnName, Table table) throws SQLException
      Helper method esp. for the ModelBasedResultSetIterator class that retrieves the value for a column from the given result set. If a table was specified, and it contains the column, then the jdbc type defined for the column is used for extracting the value, otherwise the object directly retrieved from the result set is returned.
      The method is defined here rather than in the ModelBasedResultSetIterator class so that concrete platforms can modify its behavior.
      Parameters:
      resultSet - The result set
      columnName - The name of the column
      table - The table
      Returns:
      The value
      Throws:
      SQLException
    • getObjectFromResultSet

      protected Object getObjectFromResultSet(ResultSet resultSet, Column column, int idx) throws SQLException
      Helper method for retrieving the value for a column from the given result set using the type code of the column.
      Parameters:
      resultSet - The result set
      column - The column
      idx - The value's index in the result set (starting from 1)
      Returns:
      The value
      Throws:
      SQLException
    • extractColumnValue

      protected Object extractColumnValue(ResultSet resultSet, String columnName, int columnIdx, int jdbcType) throws SQLException
      This is the core method to retrieve a value for a column from a result set. Its primary purpose is to call the appropriate method on the result set, and to provide an extension point where database-specific implementations can change this behavior.
      Parameters:
      resultSet - The result set to extract the value from
      columnName - The name of the column; can be null in which case the columnIdx will be used instead
      columnIdx - The index of the column's value in the result set; is only used if columnName is null
      jdbcType - The jdbc type to extract
      Returns:
      The value
      Throws:
      SQLException - If an error occurred while accessing the result set
    • createResultSetIterator

      protected ModelBasedResultSetIterator createResultSetIterator(Database model, ResultSet resultSet, Table[] queryHints)
      Creates an iterator over the given result set.
      Parameters:
      model - The database model
      resultSet - The result set to iterate over
      queryHints - The tables that were queried in the query that produced the given result set (optional)
      Returns:
      The iterator