Java Code Examples for oracle.jdbc.OracleTypes#BINARY_FLOAT

The following examples show how to use oracle.jdbc.OracleTypes#BINARY_FLOAT . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public SchemaBuilder schemaBuilder(Column column) {
    logger.debug("Building schema for column {} of type {} named {} with constraints ({},{})",
            column.name(),
            column.jdbcType(),
            column.typeName(),
            column.length(),
            column.scale());

    switch (column.jdbcType()) {
        // Oracle's float is not float as in Java but a NUMERIC without scale
        case Types.FLOAT:
            return variableScaleSchema(column);
        case Types.NUMERIC:
            return getNumericSchema(column);
        case OracleTypes.BINARY_FLOAT:
            return SchemaBuilder.float32();
        case OracleTypes.BINARY_DOUBLE:
            return SchemaBuilder.float64();
        case OracleTypes.TIMESTAMPTZ:
        case OracleTypes.TIMESTAMPLTZ:
            return ZonedTimestamp.builder();
        case OracleTypes.INTERVALYM:
        case OracleTypes.INTERVALDS:
            return MicroDuration.builder();
        default:
            return super.schemaBuilder(column);
    }
}
 
Example 2
@Override
public ValueConverter converter(Column column, Field fieldDefn) {
    switch (column.jdbcType()) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
            return data -> convertString(column, fieldDefn, data);
        case OracleTypes.BINARY_FLOAT:
            return data -> convertFloat(column, fieldDefn, data);
        case OracleTypes.BINARY_DOUBLE:
            return data -> convertDouble(column, fieldDefn, data);
        case Types.NUMERIC:
            return getNumericConverter(column, fieldDefn);
        case Types.FLOAT:
            return data -> convertVariableScale(column, fieldDefn, data);
        case OracleTypes.TIMESTAMPTZ:
        case OracleTypes.TIMESTAMPLTZ:
            return (data) -> convertTimestampWithZone(column, fieldDefn, data);
        case OracleTypes.INTERVALYM:
            return (data) -> convertIntervalYearMonth(column, fieldDefn, data);
        case OracleTypes.INTERVALDS:
            return (data) -> convertIntervalDaySecond(column, fieldDefn, data);
    }

    return super.converter(column, fieldDefn);
}
 
Example 3
Source Project: presto   File: OracleClient.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Optional<ColumnMapping> toPrestoType(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle)
{
    int columnSize = typeHandle.getColumnSize();

    switch (typeHandle.getJdbcType()) {
        case Types.SMALLINT:
            return Optional.of(smallintColumnMapping());
        case OracleTypes.BINARY_FLOAT:
            return Optional.of(ColumnMapping.longMapping(
                    REAL,
                    (resultSet, columnIndex) -> floatToRawIntBits(resultSet.getFloat(columnIndex)),
                    oracleRealWriteFunction()));

        case OracleTypes.BINARY_DOUBLE:
        case OracleTypes.FLOAT:
            return Optional.of(ColumnMapping.doubleMapping(
                    DOUBLE,
                    ResultSet::getDouble,
                    oracleDoubleWriteFunction()));
        case OracleTypes.NUMBER:
            int decimalDigits = typeHandle.getDecimalDigits();
            // Map negative scale to decimal(p+s, 0).
            int precision = columnSize + max(-decimalDigits, 0);
            int scale = max(decimalDigits, 0);
            Optional<Integer> numberDefaultScale = getNumberDefaultScale(session);
            RoundingMode roundingMode = getNumberRoundingMode(session);
            if (precision < scale) {
                if (roundingMode == RoundingMode.UNNECESSARY) {
                    break;
                }
                scale = min(Decimals.MAX_PRECISION, scale);
                precision = scale;
            }
            else if (numberDefaultScale.isPresent() && precision == PRECISION_OF_UNSPECIFIED_NUMBER) {
                precision = Decimals.MAX_PRECISION;
                scale = numberDefaultScale.get();
            }
            else if (precision > Decimals.MAX_PRECISION || columnSize <= 0) {
                break;
            }
            DecimalType decimalType = createDecimalType(precision, scale);
            int finalScale = scale;
            // JDBC driver can return BigDecimal with lower scale than column's scale when there are trailing zeroes
            if (decimalType.isShort()) {
                return Optional.of(ColumnMapping.longMapping(
                        decimalType,
                        (resultSet, columnIndex) -> encodeShortScaledValue(resultSet.getBigDecimal(columnIndex), finalScale, roundingMode),
                        shortDecimalWriteFunction(decimalType)));
            }
            return Optional.of(ColumnMapping.sliceMapping(
                    decimalType,
                    (resultSet, columnIndex) -> encodeScaledValue(resultSet.getBigDecimal(columnIndex), finalScale, roundingMode),
                    longDecimalWriteFunction(decimalType)));

        case OracleTypes.CHAR:
        case OracleTypes.NCHAR:
            CharType charType = createCharType(columnSize);
            return Optional.of(ColumnMapping.sliceMapping(
                    charType,
                    charReadFunction(),
                    oracleCharWriteFunction(charType)));

        case OracleTypes.VARCHAR:
        case OracleTypes.NVARCHAR:
            return Optional.of(ColumnMapping.sliceMapping(
                    createVarcharType(columnSize),
                    (varcharResultSet, varcharColumnIndex) -> utf8Slice(varcharResultSet.getString(varcharColumnIndex)),
                    varcharWriteFunction()));

        case OracleTypes.CLOB:
        case OracleTypes.NCLOB:
            return Optional.of(ColumnMapping.sliceMapping(
                    createUnboundedVarcharType(),
                    (resultSet, columnIndex) -> utf8Slice(resultSet.getString(columnIndex)),
                    varcharWriteFunction(),
                    DISABLE_PUSHDOWN));

        case OracleTypes.VARBINARY: // Oracle's RAW(n)
        case OracleTypes.BLOB:
            return Optional.of(ColumnMapping.sliceMapping(
                    VARBINARY,
                    (resultSet, columnIndex) -> wrappedBuffer(resultSet.getBytes(columnIndex)),
                    varbinaryWriteFunction(),
                    DISABLE_PUSHDOWN));

        // This mapping covers both DATE and TIMESTAMP, as Oracle's DATE has second precision.
        case OracleTypes.TIMESTAMP:
            return Optional.of(oracleTimestampColumnMapping(session));
        case OracleTypes.TIMESTAMPTZ:
            return Optional.of(oracleTimestampWithTimeZoneColumnMapping());
    }
    if (getUnsupportedTypeHandling(session) == CONVERT_TO_VARCHAR) {
        return mapToUnboundedVarchar(typeHandle);
    }
    return Optional.empty();
}