예제 #1
0
 @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;
     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());
   }
 }
예제 #2
0
 @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 {
     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());
 }