Class ADbMigration

    • Constructor Detail

      • ADbMigration

        public ADbMigration()
        Constructor
    • Method Detail

      • prepareSql

        protected final String prepareSql​(String statement,
                                          String... args)
        Create the SQL statement
        Parameters:
        statement - The sql statement template
        args - The argument for the template
        Returns:
        the parameterized sql statement
      • prepareStatement

        protected PreparedStatement prepareStatement​(String statement,
                                                     String... args)
                                              throws SQLException
        Creates a PreparedStatement object for sending parameterized SQL statements to the database.

        This method will create the sql statement with the given statement template and args and create the appropriate PrepatedStatement object with the databse

        Parameters:
        statement - The sql statement template
        args - The argument for the template
        Returns:
        PreparedStatement object
        Throws:
        SQLException - if a database access error occurs or this method is called on a closed connection
        See Also:
        Connection.prepareCall(String)
      • prepareCall

        protected CallableStatement prepareCall​(String statement,
                                                String... args)
                                         throws SQLException
        Creates a CallableStatement object for calling database stored procedures.

        This method will create the sql statement with the given statement template and args and create the appropriate PrepatedStatement object with the databse

        Parameters:
        statement - The sql statement template
        args - The argument for the template
        Returns:
        the CallableStatement object
        Throws:
        SQLException - if a database access error occurs or this method is called on a closed connection
      • onlyForH2

        protected void onlyForH2()
                          throws MigrationException
        Marks a migration operation as designed only for H2 databases.

        This occurs when performing complex operations, where only the sequence of operations is important.

        Throws:
        MigrationException - when called, stopping the migration
      • getTypeForClob

        protected String getTypeForClob()
        Gets the type name for CLOB, depending on the databose type.
        Returns:
        type name
      • unprefixTable

        protected String unprefixTable​(String table)
        Removes newly prefixed tables to get the old name.
        Parameters:
        table - table name
        Returns:
        old table name
      • createSequence

        protected String createSequence​(String name,
                                        int start)
        Creates a sequence.
        Parameters:
        name - sequence name
        start - sequence start value
        Returns:
        SQL statement to create a sequence
      • migrateHibernateIds

        protected void migrateHibernateIds​(com.quartetfs.fwk.IPair<String,​String>... idColumns)
                                    throws MigrationException,
                                           SQLException
        Migrates all referenced id columns using the default hibernate sequence.

        This also removes the default value set for those columns.

        Parameters:
        idColumns - list of columns with ids, as (table, column)
        Throws:
        MigrationException - on any failure
        SQLException - for invalid statement
      • renameTableStatement

        protected String renameTableStatement​(String oldName,
                                              String newName)
        Gets a SQL statement to rename a toble.
        Parameters:
        oldName - old table name
        newName - new table name
        Returns:
        statement
      • renameColumnStatement

        protected String renameColumnStatement​(String table,
                                               String oldName,
                                               String newName)
        Gets a SQL statement to rename a column of a particular table.
        Parameters:
        table - table name
        oldName - old column name
        newName - new column name
        Returns:
        statement
      • changeColumnType

        protected String changeColumnType​(String table,
                                          String column,
                                          String newType)
        Gets a SQL statement to change the type of given table column
        Parameters:
        table - table name
        column - column name
        newType - new type
        Returns:
        statement
      • createConnection

        protected abstract Connection createConnection()
        Creates a connection to the database.
        Returns:
        the connection