@Override public ValidationErrors validate( RenameSequenceStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { ValidationErrors validationErrors = new ValidationErrors(); validationErrors.checkRequiredField("newSequenceName", statement.getNewSequenceName()); validationErrors.checkRequiredField("oldSequenceName", statement.getOldSequenceName()); return validationErrors; }
protected Sequence getAffectedOldSequence(RenameSequenceStatement statement) { return new Sequence() .setName(statement.getOldSequenceName()) .setSchema(statement.getCatalogName(), statement.getSchemaName()); }
@Override public Sql[] generateSql( RenameSequenceStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { String sql; if (database instanceof PostgresDatabase) { sql = "ALTER SEQUENCE " + database.escapeSequenceName( statement.getCatalogName(), statement.getSchemaName(), statement.getOldSequenceName()) + " RENAME TO " + database.escapeObjectName(statement.getNewSequenceName(), Sequence.class); } else if (database instanceof OracleDatabase) { sql = "RENAME " + database.escapeObjectName(statement.getOldSequenceName(), Sequence.class) + " TO " + database.escapeObjectName(statement.getNewSequenceName(), Sequence.class); } else if (database instanceof MSSQLDatabase) { sql = "SP_RENAME " + database.escapeObjectName(statement.getOldSequenceName(), Sequence.class) + " ," + database.escapeObjectName(statement.getNewSequenceName(), Sequence.class); } else { sql = "ALTER SEQUENCE " + database.escapeSequenceName( statement.getCatalogName(), statement.getSchemaName(), statement.getOldSequenceName()) + " RENAME TO " + database.escapeObjectName(statement.getNewSequenceName(), Sequence.class); } return new Sql[] { new UnparsedSql(sql, getAffectedOldSequence(statement), getAffectedNewSequence(statement)) }; }