All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liquibase.ext.cachedb.sqlgenerator.SetNullableGeneratorCache Maven / Gradle / Ivy

There is a newer version: 4.30.0
Show newest version
package liquibase.ext.cachedb.sqlgenerator;

import liquibase.database.Database;
import liquibase.ext.cachedb.database.CacheDatabase;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.sqlgenerator.core.SetNullableGenerator;
import liquibase.statement.core.SetNullableStatement;

public class SetNullableGeneratorCache extends SetNullableGenerator {

    @Override
    public int getPriority() {
        return PRIORITY_DATABASE;
    }

    @Override
    public boolean supports(SetNullableStatement statement, Database database) {
        return database instanceof CacheDatabase;
    }

    @Override
    public Sql[] generateSql(SetNullableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
        String nullableString;
        if (statement.isNullable()) {
            nullableString = " NULL";
        } else {
            nullableString = " NOT NULL";
        }

        String sql = "ALTER TABLE " + database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()) + " ALTER COLUMN  " + database.escapeColumnName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), statement.getColumnName()) + nullableString;

        return new Sql[]{new UnparsedSql(sql, getAffectedColumn(statement))};

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy