Beispiel #1
0
  /** {@inheritDoc} */
  protected void setStatementParameterValue(
      PreparedStatement statement, int sqlIndex, int typeCode, Object value) throws SQLException {
    if (value != null) {
      if ((value instanceof byte[])
          && ((typeCode == Types.BINARY)
              || (typeCode == Types.VARBINARY)
              || (typeCode == Types.BLOB))) {
        byte[] bytes = (byte[]) value;
        ByteArrayInputStream stream = new ByteArrayInputStream(bytes);

        statement.setBinaryStream(sqlIndex, stream, bytes.length);
        return;
      } else if ((value instanceof String)
          && ((typeCode == Types.CLOB) || (typeCode == Types.LONGVARCHAR))) {
        // Clob is not supported directly
        statement.setString(sqlIndex, (String) value);
        return;
      }
    }
    super.setStatementParameterValue(statement, sqlIndex, typeCode, value);
  }
  /** {@inheritDoc} */
  protected void setObject(
      PreparedStatement statement, int sqlIndex, DynaBean dynaBean, SqlDynaProperty property)
      throws SQLException {
    int typeCode = property.getColumn().getTypeCode();
    Object value = dynaBean.get(property.getName());

    // PostgreSQL doesn't like setNull for BYTEA columns
    if (value == null) {
      switch (typeCode) {
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.BLOB:
          statement.setBytes(sqlIndex, null);
          break;
        default:
          statement.setNull(sqlIndex, typeCode);
          break;
      }
    } else {
      super.setObject(statement, sqlIndex, dynaBean, property);
    }
  }