private void applyColumnParameter(PreparedStatement stmt, int i, ColumnConfig col) throws SQLException,
            DatabaseException {
        if (col.getValue() != null) {
            LOG.fine(LogType.LOG, "value is string = " + col.getValue());
            if (col.getType() != null && col.getType().equalsIgnoreCase(LoadDataChange.LOAD_DATA_TYPE.UUID.name())) {
                stmt.setObject(i, UUID.fromString(col.getValue()));
            } else {
                stmt.setString(i, col.getValue());
            }
        } else if (col.getValueBoolean() != null) {
            LOG.fine(LogType.LOG, "value is boolean = " + col.getValueBoolean());
            stmt.setBoolean(i, col.getValueBoolean());
        } else if (col.getValueNumeric() != null) {
            LOG.fine(LogType.LOG, "value is numeric = " + col.getValueNumeric());
            Number number = col.getValueNumeric();
            if (number instanceof ColumnConfig.ValueNumeric) {
                ColumnConfig.ValueNumeric valueNumeric = (ColumnConfig.ValueNumeric) number;
                number = valueNumeric.getDelegate();
            }
            if (number instanceof Long) {
                stmt.setLong(i, number.longValue());
            } else if (number instanceof Integer) {
                stmt.setInt(i, number.intValue());
            } else if (number instanceof Double) {
                stmt.setDouble(i, number.doubleValue());
            } else if (number instanceof Float) {
                stmt.setFloat(i, number.floatValue());
            } else if (number instanceof BigDecimal) {
                stmt.setBigDecimal(i, (BigDecimal) number);
            } else if (number instanceof BigInteger) {
                stmt.setInt(i, number.intValue());
            } else {
                throw new UnexpectedLiquibaseException(
                        String.format(
                                coreBundle.getString("jdbc.bind.parameter.unknown.numeric.value.type"),
                                col.getName(),
                                col.getValueNumeric().toString(),
                            col.getValueNumeric().getClass().getName()
                        )
                );
            }
        } else if (col.getValueDate() != null) {
            LOG.fine(LogType.LOG, "value is date = " + col.getValueDate());
            if (col.getValueDate() instanceof Timestamp) {
                stmt.setTimestamp(i, (Timestamp) col.getValueDate());
            } else if (col.getValueDate() instanceof Time) {
                stmt.setTime(i, (Time) col.getValueDate());
            } else {
                stmt.setDate(i, new java.sql.Date(col.getValueDate().getTime()));
            }
        } else if (col.getValueBlobFile() != null) {
            LOG.fine(LogType.LOG, "value is blob = " + col.getValueBlobFile());
            try {
                LOBContent<InputStream> lob = toBinaryStream(col.getValueBlobFile());
                if (lob.length <= Integer.MAX_VALUE) {
                    stmt.setBinaryStream(i, lob.content, (int) lob.length);
                } else {
                    stmt.setBinaryStream(i, lob.content, lob.length);
                }
            } catch (IOException | LiquibaseException e) {
                throw new DatabaseException(e.getMessage(), e); // wrap
            }
        } else if (col.getValueClobFile() != null) {
            try {
                LOG.fine(LogType.LOG, "value is clob = " + col.getValueClobFile());
                LOBContent<Reader> lob = toCharacterStream(col.getValueClobFile(), col.getEncoding());
                if (lob.length <= Integer.MAX_VALUE) {
                    stmt.setCharacterStream(i, lob.content, (int) lob.length);
                } else {
                    stmt.setCharacterStream(i, lob.content, lob.length);
                }
            } catch (IOException | LiquibaseException e) {
                throw new DatabaseException(e.getMessage(), e); // wrap
            }
        } else {
            // NULL values might intentionally be set into a change, we must also add them to the prepared statement
            LOG.fine(LogType.LOG, "value is explicit null");
            stmt.setNull(i, java.sql.Types.NULL);
        }
    }
private void applyColumnParameter(PreparedStatement stmt, int i, ColumnConfig col) throws SQLException,
            DatabaseException {
        if (col.getValue() != null) {
            LOG.fine(LogType.LOG, "value is string = " + col.getValue());
            if (col.getType() != null && col.getType().equalsIgnoreCase(LoadDataChange.LOAD_DATA_TYPE.UUID.name())) {
                stmt.setObject(i, UUID.fromString(col.getValue()));
            } else {
                stmt.setString(i, col.getValue());
            }
        } else if (col.getValueBoolean() != null) {
            LOG.fine(LogType.LOG, "value is boolean = " + col.getValueBoolean());
            stmt.setBoolean(i, col.getValueBoolean());
        } else if (col.getValueNumeric() != null) {
            LOG.fine(LogType.LOG, "value is numeric = " + col.getValueNumeric());
            Number number = col.getValueNumeric();
            if (number instanceof ColumnConfig.ValueNumeric) {
                ColumnConfig.ValueNumeric valueNumeric = (ColumnConfig.ValueNumeric) number;
                number = valueNumeric.getDelegate();
            }
            if (number instanceof Long) {
                stmt.setLong(i, number.longValue());
            } else if (number instanceof Integer) {
                stmt.setInt(i, number.intValue());
            } else if (number instanceof Double) {
                stmt.setDouble(i, number.doubleValue());
            } else if (number instanceof Float) {
                stmt.setFloat(i, number.floatValue());
            } else if (number instanceof BigDecimal) {
                stmt.setBigDecimal(i, (BigDecimal) number);
            } else if (number instanceof BigInteger) {
                stmt.setInt(i, number.intValue());
            } else {
                throw new UnexpectedLiquibaseException(
                        String.format(
                                coreBundle.getString("jdbc.bind.parameter.unknown.numeric.value.type"),
                                col.getName(),
                                col.getValueNumeric().toString(),
                            col.getValueNumeric().getClass().getName()
                        )
                );
            }
        } else if (col.getValueDate() != null) {
            LOG.fine(LogType.LOG, "value is date = " + col.getValueDate());
            if (col.getValueDate() instanceof Timestamp) {
                stmt.setTimestamp(i, (Timestamp) col.getValueDate());
            } else if (col.getValueDate() instanceof Time) {
                stmt.setTime(i, (Time) col.getValueDate());
            } else {
                stmt.setDate(i, new java.sql.Date(col.getValueDate().getTime()));
            }
        } else if (col.getValueBlobFile() != null) {
            LOG.fine(LogType.LOG, "value is blob = " + col.getValueBlobFile());
            try {
                LOBContent<InputStream> lob = toBinaryStream(col.getValueBlobFile());
                if (lob.length <= Integer.MAX_VALUE) {
                    stmt.setBinaryStream(i, lob.content, (int) lob.length);
                } else {
                    stmt.setBinaryStream(i, lob.content, lob.length);
                }
            } catch (IOException | LiquibaseException e) {
                throw new DatabaseException(e.getMessage(), e); 
            }
        } else if (col.getValueClobFile() != null) {
            try {
                LOG.fine(LogType.LOG, "value is clob = " + col.getValueClobFile());
                LOBContent<Reader> lob = toCharacterStream(col.getValueClobFile(), col.getEncoding());
                if (lob.length <= Integer.MAX_VALUE) {
                    stmt.setCharacterStream(i, lob.content, (int) lob.length);
                } else {
                    stmt.setCharacterStream(i, lob.content, lob.length);
                }
            } catch (IOException | LiquibaseException e) {
                throw new DatabaseException(e.getMessage(), e); 
            }
        } else {
            
            LOG.fine(LogType.LOG, "value is explicit null");
            stmt.setNull(i, java.sql.Types.NULL);
        }
    }
private void applyColumnParameter ( PreparedStatement stmt , int i , ColumnConfig col ) throws SQLException , DatabaseException { if ( col . getValue ( ) != null ) { LOG . fine ( LogType . LOG , "value is string = " + col . getValue ( ) ) ; if ( col . getType ( ) != null && col . getType ( ) . equalsIgnoreCase ( LoadDataChange . LOAD_DATA_TYPE . UUID . name ( ) ) ) { stmt . setObject ( i , UUID . fromString ( col . getValue ( ) ) ) ; } else { stmt . setString ( i , col . getValue ( ) ) ; } } else if ( col . getValueBoolean ( ) != null ) { LOG . fine ( LogType . LOG , "value is boolean = " + col . getValueBoolean ( ) ) ; stmt . setBoolean ( i , col . getValueBoolean ( ) ) ; } else if ( col . getValueNumeric ( ) != null ) { LOG . fine ( LogType . LOG , "value is numeric = " + col . getValueNumeric ( ) ) ; Number number = col . getValueNumeric ( ) ; if ( number instanceof ColumnConfig . ValueNumeric ) { ColumnConfig . ValueNumeric valueNumeric = ( ColumnConfig . ValueNumeric ) number ; number = valueNumeric . getDelegate ( ) ; } if ( number instanceof Long ) { stmt . setLong ( i , number . longValue ( ) ) ; } else if ( number instanceof Integer ) { stmt . setInt ( i , number . intValue ( ) ) ; } else if ( number instanceof Double ) { stmt . setDouble ( i , number . doubleValue ( ) ) ; } else if ( number instanceof Float ) { stmt . setFloat ( i , number . floatValue ( ) ) ; } else if ( number instanceof BigDecimal ) { stmt . setBigDecimal ( i , ( BigDecimal ) number ) ; } else if ( number instanceof BigInteger ) { stmt . setInt ( i , number . intValue ( ) ) ; } else { throw new UnexpectedLiquibaseException ( String . format ( coreBundle . getString ( "jdbc.bind.parameter.unknown.numeric.value.type" ) , col . getName ( ) , col . getValueNumeric ( ) . toString ( ) , col . getValueNumeric ( ) . getClass ( ) . getName ( ) ) ) ; } } else if ( col . getValueDate ( ) != null ) { LOG . fine ( LogType . LOG , "value is date = " + col . getValueDate ( ) ) ; if ( col . getValueDate ( ) instanceof Timestamp ) { stmt . setTimestamp ( i , ( Timestamp ) col . getValueDate ( ) ) ; } else if ( col . getValueDate ( ) instanceof Time ) { stmt . setTime ( i , ( Time ) col . getValueDate ( ) ) ; } else { stmt . setDate ( i , new java . sql . Date ( col . getValueDate ( ) . getTime ( ) ) ) ; } } else if ( col . getValueBlobFile ( ) != null ) { LOG . fine ( LogType . LOG , "value is blob = " + col . getValueBlobFile ( ) ) ; try { LOBContent < InputStream > lob = toBinaryStream ( col . getValueBlobFile ( ) ) ; if ( lob . length <= Integer . MAX_VALUE ) { stmt . setBinaryStream ( i , lob . content , ( int ) lob . length ) ; } else { stmt . setBinaryStream ( i , lob . content , lob . length ) ; } } catch ( IOException | LiquibaseException e ) { throw new DatabaseException ( e . getMessage ( ) , e ) ; // wrap } } else if ( col . getValueClobFile ( ) != null ) { try { LOG . fine ( LogType . LOG , "value is clob = " + col . getValueClobFile ( ) ) ; LOBContent < Reader > lob = toCharacterStream ( col . getValueClobFile ( ) , col . getEncoding ( ) ) ; if ( lob . length <= Integer . MAX_VALUE ) { stmt . setCharacterStream ( i , lob . content , ( int ) lob . length ) ; } else { stmt . setCharacterStream ( i , lob . content , lob . length ) ; } } catch ( IOException | LiquibaseException e ) { throw new DatabaseException ( e . getMessage ( ) , e ) ; // wrap } } else { // NULL values might intentionally be set into a change, we must also add them to the prepared statement LOG . fine ( LogType . LOG , "value is explicit null" ) ; stmt . setNull ( i , java . sql . Types . NULL ) ; } }
Sets a single bind variable for a statement to its designated value
@param stmt the PreparedStatement whose parameter is to be set
@param i the parameter index (first bind variable is 1)
@param col a ColumnConfig with information about the column, its type, and the desired value
@throws SQLException if JDBC objects to a setting (non-existent bind number, wrong column type etc.)
@throws DatabaseException if an I/O error occurs during the read of LOB values
Sets a single bind variable for a statement to its designated value