protected Object toBigDecimal(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, BigDecimal.ZERO, (r) -> { if (data instanceof BigDecimal) { r.deliver(data); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getBigDecimal((Boolean)data)); } else if (data instanceof Short) { r.deliver(new BigDecimal(((Short)data).intValue())); } else if (data instanceof Integer) { r.deliver(new BigDecimal(((Integer)data).intValue())); } else if (data instanceof Long) { r.deliver(BigDecimal.valueOf(((Long)data).longValue())); } else if (data instanceof Float) { r.deliver(BigDecimal.valueOf(((Float)data).doubleValue())); } else if (data instanceof Double) { r.deliver(BigDecimal.valueOf(((Double)data).doubleValue())); } else if (data instanceof String) { r.deliver(new BigDecimal((String)data)); } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#DOUBLE}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ protected Object convertDouble(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, 0.0d, (r) -> { if (data instanceof Double) { r.deliver(data); } else if (data instanceof Number) { // Includes BigDecimal and other numeric values ... Number value = (Number) data; r.deliver(Double.valueOf(value.doubleValue())); } else if (data instanceof SpecialValueDecimal) { r.deliver(((SpecialValueDecimal)data).toDouble()); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getDouble((Boolean) data)); } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#REAL}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ protected Object convertReal(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, 0.0f, (r) -> { if (data instanceof Float) { r.deliver(data); } else if (data instanceof Number) { // Includes BigDecimal and other numeric values ... Number value = (Number) data; r.deliver(Float.valueOf(value.floatValue())); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getFloat((Boolean) data)); } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#SMALLINT}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ protected Object convertSmallInt(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, SHORT_FALSE, (r) -> { if (data instanceof Short) { r.deliver(data); } else if (data instanceof Number) { Number value = (Number) data; r.deliver(Short.valueOf(value.shortValue())); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getShort((Boolean)data)); } else if (data instanceof String) { r.deliver(Short.valueOf((String)data)); } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#INTEGER}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ protected Object convertBigInt(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, 0L, (r) -> { if (data instanceof Long) { r.deliver(data); } else if (data instanceof Number) { Number value = (Number) data; r.deliver(Long.valueOf(value.longValue())); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getLong((Boolean) data)); } else if (data instanceof String) { r.deliver(Long.valueOf((String) data)); } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#INTEGER}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ protected Object convertInteger(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, 0, (r) -> { if (data instanceof Integer) { r.deliver(data); } else if (data instanceof Number) { Number value = (Number) data; r.deliver(Integer.valueOf(value.intValue())); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getInteger((Boolean)data)); } else if (data instanceof String) { r.deliver(Integer.valueOf((String)data)); } }); }
@Override protected Object convertTinyInt(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, BYTE_FALSE, (r) -> { if (data instanceof Byte) { r.deliver(data); } else if (data instanceof Number) { Number value = (Number) data; r.deliver(value.byteValue()); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getByte((boolean) data)); } else if (data instanceof String) { r.deliver(Byte.parseByte((String) data)); } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#SMALLINT}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ protected Object convertSmallInt(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, SHORT_FALSE, (r) -> { if (data instanceof Short) { r.deliver(data); } else if (data instanceof Number) { Number value = (Number) data; r.deliver(new Short(value.shortValue())); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getShort((Boolean)data)); } else if (data instanceof String) { r.deliver(Short.parseShort((String)data)); } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#INTEGER}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ protected Object convertBigInt(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, 0L, (r) -> { if (data instanceof Long) { r.deliver(data); } else if (data instanceof Number) { Number value = (Number) data; r.deliver(Long.valueOf(value.longValue())); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getLong((Boolean) data)); } else if (data instanceof String) { r.deliver(Long.parseLong((String) data)); } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#INTEGER}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ protected Object convertInteger(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, 0, (r) -> { if (data instanceof Integer) { r.deliver(data); } else if (data instanceof Number) { Number value = (Number) data; r.deliver(Integer.valueOf(value.intValue())); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getInteger((Boolean)data)); } else if (data instanceof String) { r.deliver(Integer.parseInt((String)data)); } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#REAL}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ protected Object convertReal(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, 0.0f, (r) -> { if (data instanceof Float) { r.deliver(data); } else if (data instanceof Number) { // Includes BigDecimal and other numeric values ... Number value = (Number) data; r.deliver(Float.valueOf(value.floatValue())); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getFloat((Boolean) data)); } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#DOUBLE}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ protected Object convertDouble(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, 0.0d, (r) -> { if (data instanceof Double) { r.deliver(data); } else if (data instanceof Number) { // Includes BigDecimal and other numeric values ... Number value = (Number) data; r.deliver(Double.valueOf(value.doubleValue())); } else if (data instanceof SpecialValueDecimal) { r.deliver(((SpecialValueDecimal)data).toDouble()); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getDouble((Boolean) data)); } }); }
protected Object toBigDecimal(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, BigDecimal.ZERO, (r) -> { if (data instanceof BigDecimal) { r.deliver(data); } else if (data instanceof Boolean) { r.deliver(NumberConversions.getBigDecimal((Boolean)data)); } else if (data instanceof Short) { r.deliver(new BigDecimal(((Short)data).intValue())); } else if (data instanceof Integer) { r.deliver(new BigDecimal(((Integer)data).intValue())); } else if (data instanceof Long) { r.deliver(BigDecimal.valueOf(((Long)data).longValue())); } else if (data instanceof Float) { r.deliver(BigDecimal.valueOf(((Float)data).doubleValue())); } else if (data instanceof Double) { r.deliver(BigDecimal.valueOf(((Double)data).doubleValue())); } else if (data instanceof String) { r.deliver(new BigDecimal((String)data)); } }); }