Example usage for java.sql Types ARRAY

List of usage examples for java.sql Types ARRAY

Introduction

In this page you can find the example usage for java.sql Types ARRAY.

Prototype

int ARRAY

To view the source code for java.sql Types ARRAY.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type ARRAY.

Usage

From source file:org.vulpe.model.dao.impl.jpa.AbstractVulpeBaseDAOJPA.java

public CallableStatement executeCallableStatement(final String name, final Integer returnType,
        final List<Parameter> parameters) throws VulpeApplicationException {
    CallableStatement cstmt = null;
    try {//from w w w.j ava 2s  . c o  m
        final Session session = (Session) entityManager.getDelegate();
        final SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) session
                .getSessionFactory();
        final ConnectionProvider connectionProvider = sessionFactoryImplementor.getConnectionProvider();
        final Connection connection = connectionProvider.getConnection();

        final StringBuilder call = new StringBuilder();
        call.append(returnType == null ? "{call " : "{? = call ");
        call.append(name);
        int count = 0;
        if (parameters != null) {
            call.append("(");
            do {
                if (count > 0) {
                    call.append(",");
                }
                call.append("?");
                ++count;
            } while (count < parameters.size());
            call.append(")");
        }
        call.append("}");
        if (parameters != null) {
            cstmt = connection.prepareCall(call.toString());
            if (returnType != null) {
                if (returnType != 0) {
                    cstmt.registerOutParameter(1, returnType);
                    count = 1;
                } else {
                    count = 0;
                }
            }
            for (Parameter parameter : parameters) {
                ++count;
                if (parameter.getType() == Types.ARRAY) {
                    // Connection nativeConnection =
                    // cstmt.getConnection().getMetaData().getConnection();
                    // ArrayDescriptor objectArrayDescriptor =
                    // ArrayDescriptor.createDescriptor(
                    // parameter.getArrayType(), nativeConnection);
                    // Array array = new ARRAY(objectArrayDescriptor,
                    // nativeConnection, parameter
                    // .getArrayValues());
                    // cstmt.setArray(count, array);
                    LOG.info("");
                } else {
                    cstmt.setObject(count, parameter.getValue(), parameter.getType());
                }
                if (parameter.isOut()) {
                    if (parameter.getType() == Types.ARRAY) {
                        cstmt.registerOutParameter(count, Types.ARRAY, parameter.getArrayType());
                    } else {
                        cstmt.registerOutParameter(count, parameter.getType());
                    }
                }
            }
        }
        cstmt.execute();
    } catch (SQLException e) {
        throw new VulpeApplicationException(e.getMessage());
    }
    return cstmt;
}

From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java

@Override
public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column)
        throws SQLException {
    switch (column.getJdbcType()) {
    case Types.VARCHAR:
    case Types.CLOB:
        setToPreparedStatementString(ps, index, value, column);
        return;/*from   w w w  .j  a  v  a 2  s .c o m*/
    case Types.BIT:
        ps.setBoolean(index, ((Boolean) value).booleanValue());
        return;
    case Types.SMALLINT:
        ps.setInt(index, ((Long) value).intValue());
        return;
    case Types.INTEGER:
    case Types.BIGINT:
        ps.setLong(index, ((Number) value).longValue());
        return;
    case Types.DOUBLE:
        ps.setDouble(index, ((Double) value).doubleValue());
        return;
    case Types.TIMESTAMP:
        ps.setTimestamp(index, getTimestampFromCalendar((Calendar) value));
        return;
    case Types.ARRAY:
        int jdbcBaseType = column.getJdbcBaseType();
        String jdbcBaseTypeName = column.getSqlBaseTypeString();
        if (jdbcBaseType == Types.TIMESTAMP) {
            value = getTimestampFromCalendar((Serializable[]) value);
        }
        Array array = ps.getConnection().createArrayOf(jdbcBaseTypeName, (Object[]) value);
        ps.setArray(index, array);
        return;
    case Types.OTHER:
        ColumnType type = column.getType();
        if (type.isId()) {
            setId(ps, index, value);
            return;
        } else if (type == ColumnType.FTSTORED) {
            ps.setString(index, (String) value);
            return;
        }
        throw new SQLException("Unhandled type: " + column.getType());
    default:
        throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
    }
}

From source file:nl.nn.adapterframework.util.JdbcUtil.java

public static String getValue(final ResultSet rs, final int colNum, final ResultSetMetaData rsmeta,
        String blobCharset, boolean decompressBlobs, String nullValue, boolean trimSpaces, boolean getBlobSmart,
        boolean encodeBlobBase64) throws JdbcException, IOException, SQLException, JMSException {
    switch (rsmeta.getColumnType(colNum)) {
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
    case Types.BLOB:
        try {//  ww w  . j a  v a2s. co m
            return JdbcUtil.getBlobAsString(rs, colNum, blobCharset, false, decompressBlobs, getBlobSmart,
                    encodeBlobBase64);
        } catch (JdbcException e) {
            log.debug("Caught JdbcException, assuming no blob found", e);
            return nullValue;
        }
    case Types.CLOB:
        try {
            return JdbcUtil.getClobAsString(rs, colNum, false);
        } catch (JdbcException e) {
            log.debug("Caught JdbcException, assuming no clob found", e);
            return nullValue;
        }
        // return "undefined" for types that cannot be rendered to strings easily
    case Types.ARRAY:
    case Types.DISTINCT:
    case Types.BINARY:
    case Types.REF:
    case Types.STRUCT:
        return "undefined";
    default: {
        String value = rs.getString(colNum);
        if (value == null) {
            return nullValue;
        }
        if (trimSpaces) {
            return value.trim();
        }
        return value;
    }
    }
}

From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java

@Override
@SuppressWarnings("boxing")
public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException {
    int jdbcType = rs.getMetaData().getColumnType(index);
    if (column.getJdbcType() == Types.ARRAY && jdbcType != Types.ARRAY) {
        jdbcType = column.getJdbcBaseType();
    } else {//from w w  w  .j a v  a  2  s. com
        jdbcType = column.getJdbcType();
    }
    switch (jdbcType) {
    case Types.VARCHAR:
    case Types.CLOB:
        return getFromResultSetString(rs, index, column);
    case Types.BIT:
        return rs.getBoolean(index);
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
        return rs.getLong(index);
    case Types.DOUBLE:
        return rs.getDouble(index);
    case Types.TIMESTAMP:
        return getCalendarFromTimestamp(rs.getTimestamp(index));
    case Types.ARRAY:
        Array array = rs.getArray(index);
        if (array == null) {
            return null;
        }
        if (array.getBaseType() == Types.TIMESTAMP) {
            return getCalendarFromTimestamp((Timestamp[]) array.getArray());
        } else {
            return (Serializable) array.getArray();
        }
    case Types.OTHER:
        ColumnType type = column.getType();
        if (type.isId()) {
            return getId(rs, index);
        }
        throw new SQLException("Unhandled type: " + column.getType());
    }
    throw new SQLException(
            "Unhandled JDBC type: " + column.getJdbcType() + " for type " + column.getType().toString());
}

From source file:org.apache.oozie.command.SchemaCheckXCommand.java

private String getSQLTypeFromInt(int t) {
    switch (t) {//from w  w w. j  ava2 s  . c  o m
    case Types.BIT:
        return "BIT";
    case Types.TINYINT:
        return "TINYINT";
    case Types.SMALLINT:
        return "SMALLINT";
    case Types.INTEGER:
        return "INTEGER";
    case Types.BIGINT:
        return "BIGINT";
    case Types.FLOAT:
        return "FLOAT";
    case Types.REAL:
        return "REAL";
    case Types.DOUBLE:
        return "DOUBLE";
    case Types.NUMERIC:
        return "NUMERIC";
    case Types.DECIMAL:
        return "DECIMAL";
    case Types.CHAR:
        return "CHAR";
    case Types.VARCHAR:
        return "VARCHAR";
    case Types.LONGVARCHAR:
        return "LONGVARCHAR";
    case Types.DATE:
        return "DATE";
    case Types.TIME:
        return "TIME";
    case Types.TIMESTAMP:
        return "TIMESTAMP";
    case Types.BINARY:
        return "BINARY";
    case Types.VARBINARY:
        return "VARBINARY";
    case Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case Types.NULL:
        return "NULL";
    case Types.OTHER:
        return "OTHER";
    case Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case Types.DISTINCT:
        return "DISTINCT";
    case Types.STRUCT:
        return "STRUCT";
    case Types.ARRAY:
        return "ARRAY";
    case Types.BLOB:
        return "BLOB";
    case Types.CLOB:
        return "CLOB";
    case Types.REF:
        return "REF";
    case Types.DATALINK:
        return "DATALINK";
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.ROWID:
        return "ROWID";
    case Types.NCHAR:
        return "NCHAR";
    case Types.NVARCHAR:
        return "NVARCHAR";
    case Types.LONGNVARCHAR:
        return "LONGNVARCHAR";
    case Types.NCLOB:
        return "NCLOB";
    case Types.SQLXML:
        return "SQLXML";
    default:
        return "unknown";
    }
}

From source file:org.apache.ode.bpel.extvar.jdbc.JdbcExternalVariableModule.java

private Object downcastValue(Object value, int dataType) {
    if (value == null) {
        return null;
    }//from  w w  w .ja va2  s.c om
    // Try down casting the value as per its column type.
    try {
        // Some JDBC 4.0 types have been ignored to avoid compilation errors
        switch (dataType) {
        case Types.ARRAY:
            break;
        case Types.BIGINT:
            if (!(value instanceof BigInteger)) {
                value = new BigDecimal(value.toString()).longValue();
            }
            break;
        case Types.BINARY:
            break;
        case Types.BIT:
            if (!(value instanceof Boolean)) {
                value = new Boolean(value.toString());
            }
            break;
        case Types.BLOB:
            break;
        case Types.BOOLEAN:
            if (!(value instanceof Boolean)) {
                value = new Boolean(value.toString());
            }
            break;
        case Types.CHAR:
            break;
        case Types.CLOB:
            break;
        case Types.DATALINK:
            break;
        case Types.DATE:
            break;
        case Types.DECIMAL:
            //ODE-872: Oracle 9g and 10g has problems with BigDecimal on Java1.5
            value = new BigDecimal(new BigDecimal(value.toString()).toPlainString());
            break;
        case Types.DISTINCT:
            break;
        case Types.DOUBLE:
            if (!(value instanceof Double)) {
                value = Double.valueOf(value.toString()).doubleValue();
            }
            break;
        case Types.FLOAT:
            if (!(value instanceof Float)) {
                value = Float.valueOf(value.toString()).floatValue();
            }
            break;
        case Types.INTEGER:
            if (!(value instanceof Integer)) {
                value = Double.valueOf(value.toString()).intValue();
            }
            break;
        case Types.JAVA_OBJECT:
            break;
        //          case Types.LONGNVARCHAR:
        //             break;
        case Types.LONGVARBINARY:
            break;
        case Types.LONGVARCHAR:
            break;
        //          case Types.NCHAR:
        //             break;
        //          case Types.NCLOB:
        //             break;
        case Types.NUMERIC:
            //ODE-872: Oracle 9g and 10g has problems with BigDecimal on Java1.5
            value = new BigDecimal(new BigDecimal(value.toString()).toPlainString());
            break;
        //          case Types.NVARCHAR:
        //             break;
        case Types.OTHER:
            break;
        case Types.REAL:
            if (!(value instanceof Double)) {
                value = Float.valueOf(value.toString()).floatValue();
            }
            break;
        case Types.REF:
            break;
        //          case Types.ROWID:
        //             break;
        case Types.SMALLINT:
            if (!(value instanceof Short)) {
                value = new Short(value.toString()).shortValue();
            }
            break;
        //          case Types.SQLXML:
        //             break;
        case Types.STRUCT:
            break;
        case Types.TIME:
            break;
        case Types.TIMESTAMP:
            break;
        case Types.TINYINT:
            if (!(value instanceof Short)) {
                value = new Short(value.toString()).shortValue();
            }
            break;
        case Types.VARBINARY:
            break;
        case Types.VARCHAR:
            break;
        default:
            break;
        }
    } catch (Exception e) {
        // couldn't cast... let's just use original value object
    }
    return value;
}

From source file:org.eclipse.ecr.core.storage.sql.jdbc.JDBCMapper.java

@Override
public void insertClusterInvalidations(Invalidations invalidations) throws StorageException {
    String sql = sqlInfo.dialect.getClusterInsertInvalidations();
    List<Column> columns = sqlInfo.getClusterInvalidationsColumns();
    PreparedStatement ps = null;/*from  w  ww .j a v a  2  s . c om*/
    try {
        ps = connection.prepareStatement(sql);
        int kind = Invalidations.MODIFIED;
        while (true) {
            Set<RowId> rowIds = invalidations.getKindSet(kind);

            // reorganize by id
            Map<Serializable, Set<String>> res = new HashMap<Serializable, Set<String>>();
            for (RowId rowId : rowIds) {
                Set<String> tableNames = res.get(rowId.id);
                if (tableNames == null) {
                    res.put(rowId.id, tableNames = new HashSet<String>());
                }
                tableNames.add(rowId.tableName);
            }

            // do inserts
            for (Entry<Serializable, Set<String>> en : res.entrySet()) {
                Serializable id = en.getKey();
                String fragments = join(en.getValue(), ' ');
                if (logger.isLogEnabled()) {
                    logger.logSQL(sql, Arrays.<Serializable>asList(id, fragments, Long.valueOf(kind)));
                }
                Serializable frags;
                if (sqlInfo.dialect.supportsArrays() && columns.get(1).getJdbcType() == Types.ARRAY) {
                    frags = fragments.split(" ");
                } else {
                    frags = fragments;
                }
                columns.get(0).setToPreparedStatement(ps, 1, id);
                columns.get(1).setToPreparedStatement(ps, 2, frags);
                columns.get(2).setToPreparedStatement(ps, 3, Long.valueOf(kind));
                ps.execute();
            }
            if (kind == Invalidations.MODIFIED) {
                kind = Invalidations.DELETED;
            } else {
                break;
            }
        }
    } catch (Exception e) {
        checkConnectionReset(e);
        throw new StorageException("Could not invalidate", e);
    } finally {
        if (ps != null) {
            try {
                closeStatement(ps);
            } catch (SQLException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}

From source file:org.eclipse.ecr.core.storage.sql.extensions.H2Fulltext.java

protected static String asString(Object data, int type) throws SQLException {
    if (data == null) {
        return "";
    }//from  www .jav  a  2  s .com
    switch (type) {
    case Types.BIT:
    case DataType.TYPE_BOOLEAN:
    case Types.INTEGER:
    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.NUMERIC:
    case Types.REAL:
    case Types.SMALLINT:
    case Types.TINYINT:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
    case Types.LONGVARCHAR:
    case Types.CHAR:
    case Types.VARCHAR:
        return data.toString();
    case Types.CLOB:
        try {
            if (data instanceof Clob) {
                data = ((Clob) data).getCharacterStream();
            }
            return IOUtils.readStringAndClose((Reader) data, -1);
        } catch (IOException e) {
            throw Message.convert(e);
        }
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
    case Types.BINARY:
    case Types.JAVA_OBJECT:
    case Types.OTHER:
    case Types.BLOB:
    case Types.STRUCT:
    case Types.REF:
    case Types.NULL:
    case Types.ARRAY:
    case DataType.TYPE_DATALINK:
    case Types.DISTINCT:
        throw new SQLException("Unsupported column data type: " + type);
    default:
        return "";
    }
}

From source file:org.apache.cocoon.util.JDBCTypeConversions.java

/**
 * Set the Statement column so that the results are mapped correctly.
 *
 * @param statement the prepared statement
 * @param position the position of the column
 * @param value the value of the column// w ww. j  a  v a  2  s .  co m
 */
public static void setColumn(PreparedStatement statement, int position, Object value, Integer typeObject)
        throws Exception {
    if (value instanceof String) {
        value = ((String) value).trim();
    }
    if (typeObject == null) {
        throw new SQLException("Can't set column because the type is unrecognized");
    }
    if (value == null) {
        /** If the value is null, set the column value null and return **/
        statement.setNull(position, typeObject.intValue());
        return;
    }
    if ("".equals(value)) {
        switch (typeObject.intValue()) {
        case Types.CHAR:
        case Types.CLOB:
        case Types.VARCHAR:
            /** If the value is an empty string and the column is
            a string type, we can continue **/
            break;
        default:
            /** If the value is an empty string and the column
            is something else, we treat it as a null value **/
            statement.setNull(position, typeObject.intValue());
            return;
        }
    }

    File file = null;
    int length = -1;
    InputStream asciiStream = null;

    //System.out.println("========================================================================");
    //System.out.println("JDBCTypeConversions: setting type "+typeObject.intValue());
    switch (typeObject.intValue()) {
    case Types.CLOB:
        //System.out.println("CLOB");
        Clob clob = null;
        if (value instanceof Clob) {
            clob = (Clob) value;
        } else if (value instanceof File) {
            File asciiFile = (File) value;
            asciiStream = new BufferedInputStream(new FileInputStream(asciiFile));
            length = (int) asciiFile.length();
            clob = new ClobHelper(asciiStream, length);
        } else if (value instanceof Part) {
            Part anyFile = (Part) value;
            asciiStream = new BufferedInputStream(anyFile.getInputStream());
            length = anyFile.getSize();
            clob = new ClobHelper(asciiStream, length);
        } else if (value instanceof JDBCxlobHelper) {
            asciiStream = ((JDBCxlobHelper) value).inputStream;
            length = ((JDBCxlobHelper) value).length;
            clob = new ClobHelper(asciiStream, length);
        } else if (value instanceof Source) {
            asciiStream = ((Source) value).getInputStream();
            length = (int) ((Source) value).getContentLength();
            clob = new ClobHelper(asciiStream, length);
        } else {
            String asciiText = value.toString();
            asciiStream = new ByteArrayInputStream(asciiText.getBytes());
            length = asciiText.length();
            clob = new ClobHelper(asciiStream, length);
        }

        statement.setClob(position, clob);
        break;
    case Types.CHAR:
        // simple large object, e.g. Informix's TEXT
        //System.out.println("CHAR");

        if (value instanceof File) {
            File asciiFile = (File) value;
            asciiStream = new BufferedInputStream(new FileInputStream(asciiFile));
            length = (int) asciiFile.length();
        } else if (value instanceof JDBCxlobHelper) {
            asciiStream = ((JDBCxlobHelper) value).inputStream;
            length = ((JDBCxlobHelper) value).length;
        } else if (value instanceof Source) {
            asciiStream = ((Source) value).getInputStream();
            length = (int) ((Source) value).getContentLength();
        } else if (value instanceof Part) {
            Part anyFile = (Part) value;
            asciiStream = new BufferedInputStream(anyFile.getInputStream());
            length = anyFile.getSize();
            clob = new ClobHelper(asciiStream, length);
        } else {
            String asciiText = value.toString();
            asciiStream = new BufferedInputStream(new ByteArrayInputStream(asciiText.getBytes()));
            length = asciiText.length();
        }

        statement.setAsciiStream(position, asciiStream, length);
        break;
    case Types.BIGINT:
        //System.out.println("BIGINT");
        BigDecimal bd = null;

        if (value instanceof BigDecimal) {
            bd = (BigDecimal) value;
        } else if (value instanceof Number) {
            bd = BigDecimal.valueOf(((Number) value).longValue());
        } else {
            bd = new BigDecimal(value.toString());
        }

        statement.setBigDecimal(position, bd);
        break;
    case Types.TINYINT:
        //System.out.println("TINYINT");
        Byte b = null;

        if (value instanceof Byte) {
            b = (Byte) value;
        } else if (value instanceof Number) {
            b = new Byte(((Number) value).byteValue());
        } else {
            b = new Byte(value.toString());
        }

        statement.setByte(position, b.byteValue());
        break;
    case Types.DATE:
        //System.out.println("DATE");
        Date d = null;

        if (value instanceof Date) {
            d = (Date) value;
        } else if (value instanceof java.util.Date) {
            d = new Date(((java.util.Date) value).getTime());
        } else if (value instanceof Calendar) {
            d = new Date(((Calendar) value).getTime().getTime());
        } else {
            d = Date.valueOf(value.toString());
        }

        statement.setDate(position, d);
        break;
    case Types.DOUBLE:
        //System.out.println("DOUBLE");
        double db;

        if (value instanceof Number) {
            db = (((Number) value).doubleValue());
        } else {
            db = Double.parseDouble(value.toString());
        }
        statement.setDouble(position, db);
        break;
    case Types.FLOAT:
        //System.out.println("FLOAT");
        float f;

        if (value instanceof Number) {
            f = (((Number) value).floatValue());
        } else {
            f = Float.parseFloat(value.toString());
        }
        statement.setFloat(position, f);
        break;
    case Types.NUMERIC:
        //System.out.println("NUMERIC");
        long l;

        if (value instanceof Number) {
            l = (((Number) value).longValue());
        } else {
            l = Long.parseLong(value.toString());
        }

        statement.setLong(position, l);
        break;
    case Types.SMALLINT:
        //System.out.println("SMALLINT");
        Short s = null;

        if (value instanceof Short) {
            s = (Short) value;
        } else if (value instanceof Number) {
            s = new Short(((Number) value).shortValue());
        } else {
            s = new Short(value.toString());
        }

        statement.setShort(position, s.shortValue());
        break;
    case Types.TIME:
        //System.out.println("TIME");
        Time t = null;

        if (value instanceof Time) {
            t = (Time) value;
        } else if (value instanceof java.util.Date) {
            t = new Time(((java.util.Date) value).getTime());
        } else {
            t = Time.valueOf(value.toString());
        }

        statement.setTime(position, t);
        break;
    case Types.TIMESTAMP:
        //System.out.println("TIMESTAMP");
        Timestamp ts = null;

        if (value instanceof Time) {
            ts = (Timestamp) value;
        } else if (value instanceof java.util.Date) {
            ts = new Timestamp(((java.util.Date) value).getTime());
        } else {
            ts = Timestamp.valueOf(value.toString());
        }

        statement.setTimestamp(position, ts);
        break;
    case Types.ARRAY:
        //System.out.println("ARRAY");
        statement.setArray(position, (Array) value); // no way to convert string to array
        break;
    case Types.STRUCT:
        //System.out.println("STRUCT");
    case Types.OTHER:
        //System.out.println("OTHER");
        statement.setObject(position, value);
        break;
    case Types.LONGVARBINARY:
        //System.out.println("LONGVARBINARY");
        statement.setTimestamp(position, new Timestamp((new java.util.Date()).getTime()));
        break;
    case Types.VARCHAR:
        //System.out.println("VARCHAR");
        statement.setString(position, value.toString());
        break;
    case Types.BLOB:
        //System.out.println("BLOB");
        if (value instanceof JDBCxlobHelper) {
            statement.setBinaryStream(position, ((JDBCxlobHelper) value).inputStream,
                    ((JDBCxlobHelper) value).length);
        } else if (value instanceof Source) {
            statement.setBinaryStream(position, ((Source) value).getInputStream(),
                    (int) ((Source) value).getContentLength());
        } else {
            Blob blob = null;
            if (value instanceof Blob) {
                blob = (Blob) value;
            } else if (value instanceof File) {
                file = (File) value;
                blob = new BlobHelper(new FileInputStream(file), (int) file.length());
            } else if (value instanceof String) {
                file = new File((String) value);
                blob = new BlobHelper(new FileInputStream(file), (int) file.length());
            } else if (value instanceof Part) {
                Part anyFile = (Part) value;
                blob = new BlobHelper(new BufferedInputStream(anyFile.getInputStream()), anyFile.getSize());
            } else {
                throw new SQLException("Invalid type for blob: " + value.getClass().getName());
            }
            //InputStream input = new BufferedInputStream(new FileInputStream(file));
            statement.setBlob(position, blob);
        }
        break;
    case Types.VARBINARY:
        //System.out.println("VARBINARY");
        if (value instanceof JDBCxlobHelper) {
            statement.setBinaryStream(position, ((JDBCxlobHelper) value).inputStream,
                    ((JDBCxlobHelper) value).length);
        } else if (value instanceof Source) {
            statement.setBinaryStream(position, ((Source) value).getInputStream(),
                    (int) ((Source) value).getContentLength());
        } else if (value instanceof Part) {
            statement.setBinaryStream(position, ((Part) value).getInputStream(), ((Part) value).getSize());
        } else {
            if (value instanceof File) {
                file = (File) value;
            } else if (value instanceof String) {
                file = new File((String) value);
            } else {
                throw new SQLException("Invalid type for blob: " + value.getClass().getName());
            }
            //InputStream input = new BufferedInputStream(new FileInputStream(file));
            FileInputStream input = new FileInputStream(file);
            statement.setBinaryStream(position, input, (int) file.length());
        }
        break;
    case Types.INTEGER:
        //System.out.println("INTEGER");
        Integer i = null;
        if (value instanceof Integer) {
            i = (Integer) value;
        } else if (value instanceof Number) {
            i = new Integer(((Number) value).intValue());
        } else {
            i = new Integer(value.toString());
        }
        statement.setInt(position, i.intValue());
        break;
    case Types.BIT:
        //System.out.println("BIT");
        Boolean bo = null;
        if (value instanceof Boolean) {
            bo = (Boolean) value;
        } else if (value instanceof Number) {
            bo = BooleanUtils.toBooleanObject(((Number) value).intValue() == 1);
        } else {
            bo = BooleanUtils.toBooleanObject(value.toString());
        }
        statement.setBoolean(position, bo.booleanValue());
        break;

    default:
        //System.out.println("default");
        throw new SQLException("Impossible exception - invalid type ");
    }
    //System.out.println("========================================================================");
}

From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java

protected Object getObjectValue(String value, Column column, BinaryEncoding encoding, boolean useVariableDates,
        boolean fitToColumn) throws DecoderException {
    Object objectValue = value;/* ww w  .jav  a 2s .  c  om*/
    int type = column.getMappedTypeCode();
    if ((value == null || (getDdlBuilder().getDatabaseInfo().isEmptyStringNulled() && value.equals("")))
            && column.isRequired() && column.isOfTextType()) {
        objectValue = REQUIRED_FIELD_NULL_SUBSTITUTE;
    }
    if (value != null) {
        if (type == Types.DATE || type == Types.TIMESTAMP || type == Types.TIME) {
            objectValue = parseDate(type, value, useVariableDates);
        } else if (type == Types.CHAR) {
            String charValue = value.toString();
            if ((StringUtils.isBlank(charValue)
                    && getDdlBuilder().getDatabaseInfo().isBlankCharColumnSpacePadded())
                    || (StringUtils.isNotBlank(charValue)
                            && getDdlBuilder().getDatabaseInfo().isNonBlankCharColumnSpacePadded())) {
                objectValue = StringUtils.rightPad(value.toString(), column.getSizeAsInt(), ' ');
            }
        } else if (type == Types.BIGINT) {
            objectValue = parseBigInteger(value);
        } else if (type == Types.INTEGER || type == Types.SMALLINT || type == Types.BIT
                || type == Types.TINYINT) {
            objectValue = parseInteger(value);
        } else if (type == Types.NUMERIC || type == Types.DECIMAL || type == Types.FLOAT || type == Types.DOUBLE
                || type == Types.REAL) {
            objectValue = parseBigDecimal(value);
        } else if (type == Types.BOOLEAN) {
            objectValue = value.equals("1") ? Boolean.TRUE : Boolean.FALSE;
        } else if (!(column.getJdbcTypeName() != null
                && column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOMETRY))
                && !(column.getJdbcTypeName() != null
                        && column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOGRAPHY))
                && (type == Types.BLOB || type == Types.LONGVARBINARY || type == Types.BINARY
                        || type == Types.VARBINARY ||
                        // SQLServer ntext type
                        type == -10)) {
            if (encoding == BinaryEncoding.NONE) {
                objectValue = value.getBytes();
            } else if (encoding == BinaryEncoding.BASE64) {
                objectValue = Base64.decodeBase64(value.getBytes());
            } else if (encoding == BinaryEncoding.HEX) {
                objectValue = Hex.decodeHex(value.toCharArray());
            }
        } else if (type == Types.ARRAY) {
            objectValue = createArray(column, value);
        }
    }
    if (objectValue instanceof String) {
        String stringValue = cleanTextForTextBasedColumns((String) objectValue);
        int size = column.getSizeAsInt();
        if (fitToColumn && size > 0 && stringValue.length() > size) {
            stringValue = stringValue.substring(0, size);
        }
        objectValue = stringValue;
    }

    return objectValue;

}