Search in sources :

Example 1 with UpdateExecutablePreparedStatement

use of liquibase.statement.UpdateExecutablePreparedStatement in project liquibase by liquibase.

the class UpdateDataChange method generateStatements.

@Override
public SqlStatement[] generateStatements(Database database) {
    boolean needsPreparedStatement = false;
    for (ColumnConfig column : getColumns()) {
        if (column.getValueBlobFile() != null) {
            needsPreparedStatement = true;
        }
        if (column.getValueClobFile() != null) {
            needsPreparedStatement = true;
        }
        if ((database instanceof OracleDatabase) && (column.getType() != null) && "CLOB".equalsIgnoreCase(column.getType()) && (column.getValue() != null) && (column.getValue().length() >= 4000)) {
            needsPreparedStatement = true;
        }
        final Object valueObject = column.getValueObject();
        if (valueObject instanceof SequenceNextValueFunction) {
            ((SequenceNextValueFunction) valueObject).setSchemaName(this.getSchemaName());
        }
        if (valueObject instanceof SequenceCurrentValueFunction) {
            ((SequenceCurrentValueFunction) valueObject).setSchemaName(this.getSchemaName());
        }
    }
    if (needsPreparedStatement) {
        UpdateExecutablePreparedStatement statement = new UpdateExecutablePreparedStatement(database, catalogName, schemaName, tableName, columns, getChangeSet(), Scope.getCurrentScope().getResourceAccessor());
        statement.setWhereClause(where);
        for (ColumnConfig whereParam : whereParams) {
            if (whereParam.getName() != null) {
                statement.addWhereColumnName(whereParam.getName());
            }
            statement.addWhereParameter(whereParam.getValueObject());
        }
        return new SqlStatement[] { statement };
    }
    UpdateStatement statement = new UpdateStatement(getCatalogName(), getSchemaName(), getTableName());
    for (ColumnConfig column : getColumns()) {
        statement.addNewColumnValue(column.getName(), column.getValueObject());
    }
    statement.setWhereClause(where);
    for (ColumnConfig whereParam : whereParams) {
        if (whereParam.getName() != null) {
            statement.addWhereColumnName(whereParam.getName());
        }
        statement.addWhereParameter(whereParam.getValueObject());
    }
    return new SqlStatement[] { statement };
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) SequenceCurrentValueFunction(liquibase.statement.SequenceCurrentValueFunction) SqlStatement(liquibase.statement.SqlStatement) UpdateStatement(liquibase.statement.core.UpdateStatement) UpdateExecutablePreparedStatement(liquibase.statement.UpdateExecutablePreparedStatement) SequenceNextValueFunction(liquibase.statement.SequenceNextValueFunction)

Aggregations

OracleDatabase (liquibase.database.core.OracleDatabase)1 SequenceCurrentValueFunction (liquibase.statement.SequenceCurrentValueFunction)1 SequenceNextValueFunction (liquibase.statement.SequenceNextValueFunction)1 SqlStatement (liquibase.statement.SqlStatement)1 UpdateExecutablePreparedStatement (liquibase.statement.UpdateExecutablePreparedStatement)1 UpdateStatement (liquibase.statement.core.UpdateStatement)1