class ConvertJSONToSQL extends AbstractProcessor {

    protected static String createSqlStringValue(final JsonNode fieldNode, final Integer colSize, final int sqlType) {
        String fieldValue = fieldNode.asText();

        switch (sqlType) {

        // only "true" is considered true, everything else is false
        case Types.BOOLEAN:
            fieldValue = Boolean.valueOf(fieldValue).toString();
            break;

        // Don't truncate numeric types.
        case Types.BIT:
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
        case Types.REAL:
        case Types.FLOAT:
        case Types.DOUBLE:
        case Types.DECIMAL:
        case Types.NUMERIC:
            if (fieldNode.isBoolean()) {
                // Convert boolean to number representation for databases those don't support boolean type.
                fieldValue = fieldNode.asBoolean() ? "1" : "0";
            }
            break;

        // Don't truncate DATE, TIME and TIMESTAMP types. We assume date and time is already correct in long representation.
        // Specifically, milliseconds since January 1, 1970, 00:00:00 GMT
        // However, for TIMESTAMP, PutSQL accepts optional timestamp format via FlowFile attribute.
        // See PutSQL.setParameter method and NIFI-3430 for detail.
        // Alternatively, user can use JSONTreeReader and PutDatabaseRecord to handle date format more efficiently.
        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            break;

        // Truncate string data types only.
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.LONGNVARCHAR:
            if (colSize != null && fieldValue.length() > colSize) {
                fieldValue = fieldValue.substring(0, colSize);
            }
            break;
        }

        return fieldValue;
    }

}