Example usage for org.springframework.jdbc.support.lob LobHandler getLobCreator

List of usage examples for org.springframework.jdbc.support.lob LobHandler getLobCreator

Introduction

In this page you can find the example usage for org.springframework.jdbc.support.lob LobHandler getLobCreator.

Prototype

LobCreator getLobCreator();

Source Link

Document

Create a new LobCreator instance, i.e.

Usage

From source file:org.jumpmind.db.platform.sqlite.SqliteJdbcSqlTemplate.java

@Override
public void setValues(PreparedStatement ps, Object[] args, int[] argTypes, LobHandler lobHandler)
        throws SQLException {
    for (int i = 1; i <= args.length; i++) {
        Object arg = args[i - 1];
        int argType = argTypes != null && argTypes.length >= i ? argTypes[i - 1] : SqlTypeValue.TYPE_UNKNOWN;

        if (argType == Types.BLOB && lobHandler != null && arg instanceof byte[]) {
            lobHandler.getLobCreator().setBlobAsBytes(ps, i, (byte[]) arg);
        } else if (argType == Types.BLOB && lobHandler != null && arg instanceof String) {
            lobHandler.getLobCreator().setBlobAsBytes(ps, i, arg.toString().getBytes());
        } else if (argType == Types.CLOB && lobHandler != null) {
            lobHandler.getLobCreator().setClobAsString(ps, i, (String) arg);
        } else if (arg != null && argType == Types.DATE && arg instanceof Date) {
            Date clone = (Date) (((Date) arg).clone());
            arg = FormatUtils.TIMESTAMP_FORMATTER.format(DateUtils.truncate(clone, Calendar.DATE));
            args[i - 1] = arg;/*from  w ww  . j av a  2 s.c om*/
            StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg);
        } else if (arg != null && (arg instanceof Date || arg instanceof Timestamp)) {
            arg = FormatUtils.TIMESTAMP_FORMATTER.format(arg);
            args[i - 1] = arg;
            StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg);
        } else {
            if (arg instanceof BigDecimal) {
                arg = ((BigDecimal) arg).doubleValue();
                args[i - 1] = arg;
            }
            StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg);
        }
    }
}

From source file:org.jumpmind.db.sql.JdbcSqlTemplate.java

public void setValues(PreparedStatement ps, Object[] args, int[] argTypes, LobHandler lobHandler)
        throws SQLException {
    for (int i = 1; i <= args.length; i++) {
        Object arg = args[i - 1];
        int argType = argTypes != null && argTypes.length >= i ? argTypes[i - 1] : SqlTypeValue.TYPE_UNKNOWN;
        if (argType == Types.BLOB && lobHandler != null && arg instanceof byte[]) {
            lobHandler.getLobCreator().setBlobAsBytes(ps, i, (byte[]) arg);
        } else if (argType == Types.BLOB && lobHandler != null && arg instanceof String) {
            lobHandler.getLobCreator().setBlobAsBytes(ps, i, arg.toString().getBytes());
        } else if (argType == Types.CLOB && lobHandler != null) {
            lobHandler.getLobCreator().setClobAsString(ps, i, (String) arg);
        } else if ((argType == Types.DECIMAL || argType == Types.NUMERIC) && arg != null) {
            setDecimalValue(ps, i, arg, argType);
        } else if (argType == Types.TINYINT) {
            setTinyIntValue(ps, i, arg, argType);
        } else {/*from www  .ja  v a 2 s. co  m*/
            StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg);
        }
    }
}