oracle.jdbc.OracleTypes Java Examples

The following examples show how to use oracle.jdbc.OracleTypes. 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
Source File: UtilAdapter.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
@Override
protected String[] createDatabaseReport(String schema, Connection connection) throws SQLException {
    try {
        interruptableCallableStatement = connection.prepareCall("{? = call " + databaseAdapter.getSQLAdapter().resolveDatabaseOperationName("citydb_stat.table_contents") + "(?)}");
        interruptableCallableStatement.registerOutParameter(1, OracleTypes.ARRAY, schema + ".STRARRAY");
        interruptableCallableStatement.setString(2, schema);
        interruptableCallableStatement.executeUpdate();

        Array result = interruptableCallableStatement.getArray(1);
        return (String[]) result.getArray();
    } catch (SQLException e) {
        if (!isInterrupted)
            throw e;
    } finally {
        if (interruptableCallableStatement != null) {
            interruptableCallableStatement.close();
            interruptableCallableStatement = null;
        }

        isInterrupted = false;
    }

    return null;
}
 
Example #2
Source File: UtilAdapter.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
@Override
protected IndexStatusInfo manageIndexes(String operation, IndexType type, String schema, Connection connection) throws SQLException {
    try {
        String call = "{? = call " + databaseAdapter.getSQLAdapter().resolveDatabaseOperationName(operation) + "(?)}";
        interruptableCallableStatement = connection.prepareCall(call);
        interruptableCallableStatement.registerOutParameter(1, OracleTypes.ARRAY, schema + ".STRARRAY");
        interruptableCallableStatement.setString(2, schema);
        interruptableCallableStatement.executeUpdate();

        Array result = interruptableCallableStatement.getArray(1);
        return IndexStatusInfo.createFromDatabaseQuery((String[]) result.getArray(), type);
    } catch (SQLException e) {
        if (!isInterrupted)
            throw e;
    } finally {
        if (interruptableCallableStatement != null) {
            interruptableCallableStatement.close();
            interruptableCallableStatement = null;
        }

        isInterrupted = false;
    }

    return null;
}
 
Example #3
Source File: UtilAdapter.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
@Override
protected int cleanupGlobalAppearances(String schema, Connection connection) throws SQLException {
    try {
        String call = "{? = call " + databaseAdapter.getSQLAdapter().resolveDatabaseOperationName("citydb_delete.cleanup_appearances") + "()";
        interruptableCallableStatement = connection.prepareCall(call);
        interruptableCallableStatement.registerOutParameter(1, OracleTypes.ARRAY, schema + ".ID_ARRAY");
        interruptableCallableStatement.execute();

        Array result = interruptableCallableStatement.getArray(1);
        return ((Object[]) result.getArray()).length;
    } catch (SQLException e) {
        if (!isInterrupted)
            throw e;
    } finally {
        if (interruptableCallableStatement != null) {
            interruptableCallableStatement.close();
            interruptableCallableStatement = null;
        }

        isInterrupted = false;
    }

    return 0;
}
 
Example #4
Source File: OracleDdlParser.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
@Override
protected DataTypeResolver initializeDataTypeResolver() {
    // todo, register all and use in ColumnDefinitionParserListener
    DataTypeResolver.Builder dataTypeResolverBuilder = new DataTypeResolver.Builder();

    dataTypeResolverBuilder.registerDataTypes(
            PlSqlParser.Native_datatype_elementContext.class.getCanonicalName(), Arrays.asList(
                    new DataTypeEntry(Types.NUMERIC, PlSqlParser.INT),
                    new DataTypeEntry(Types.NUMERIC, PlSqlParser.INTEGER),
                    new DataTypeEntry(Types.NUMERIC, PlSqlParser.SMALLINT),
                    new DataTypeEntry(Types.NUMERIC, PlSqlParser.NUMERIC),
                    new DataTypeEntry(Types.NUMERIC, PlSqlParser.DECIMAL),
                    new DataTypeEntry(Types.NUMERIC, PlSqlParser.NUMBER),

                    new DataTypeEntry(Types.TIMESTAMP, PlSqlParser.DATE),
                    new DataTypeEntry(OracleTypes.TIMESTAMPLTZ, PlSqlParser.TIMESTAMP),
                    new DataTypeEntry(OracleTypes.TIMESTAMPTZ, PlSqlParser.TIMESTAMP),
                    new DataTypeEntry(Types.TIMESTAMP, PlSqlParser.TIMESTAMP),

                    new DataTypeEntry(Types.VARCHAR, PlSqlParser.VARCHAR2),
                    new DataTypeEntry(Types.VARCHAR, PlSqlParser.VARCHAR),
                    new DataTypeEntry(Types.NVARCHAR, PlSqlParser.NVARCHAR2),
                    new DataTypeEntry(Types.CHAR, PlSqlParser.CHAR),
                    new DataTypeEntry(Types.NCHAR, PlSqlParser.NCHAR),

                    new DataTypeEntry(OracleTypes.BINARY_FLOAT, PlSqlParser.BINARY_FLOAT),
                    new DataTypeEntry(OracleTypes.BINARY_DOUBLE, PlSqlParser.BINARY_DOUBLE),
                    new DataTypeEntry(Types.FLOAT, PlSqlParser.FLOAT),
                    new DataTypeEntry(Types.FLOAT, PlSqlParser.REAL),
                    new DataTypeEntry(Types.BLOB, PlSqlParser.BLOB),
                    new DataTypeEntry(Types.CLOB, PlSqlParser.CLOB)));
    return dataTypeResolverBuilder.build();
}
 
Example #5
Source File: OracleValueConverters.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: OracleValueConverters.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: OracleClient.java    From presto with 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();
}
 
Example #8
Source File: OracleConnection.java    From debezium-incubator with Apache License 2.0 4 votes vote down vote up
@Override
public void readSchema(Tables tables, String databaseCatalog, String schemaNamePattern, TableFilter tableFilter,
                       ColumnNameFilter columnFilter, boolean removeTablesNotFoundInJdbc)
        throws SQLException {

    super.readSchema(tables, null, schemaNamePattern, null, columnFilter, removeTablesNotFoundInJdbc);

    Set<TableId> tableIds = tables.tableIds().stream().filter(x -> schemaNamePattern.equals(x.schema())).collect(Collectors.toSet());

    for (TableId tableId : tableIds) {
        // super.readSchema() populates ids without the catalog; hence we apply the filtering only
        // here and if a table is included, overwrite it with a new id including the catalog
        TableId tableIdWithCatalog = new TableId(databaseCatalog, tableId.schema(), tableId.table());

        if (tableFilter.isIncluded(tableIdWithCatalog)) {
            TableEditor editor = tables.editTable(tableId);
            editor.tableId(tableIdWithCatalog);

            List<String> columnNames = new ArrayList<>(editor.columnNames());
            for (String columnName : columnNames) {
                Column column = editor.columnWithName(columnName);
                if (column.jdbcType() == Types.TIMESTAMP) {
                    editor.addColumn(
                            column.edit()
                                    .length(column.scale().orElse(Column.UNSET_INT_VALUE))
                                    .scale(null)
                                    .create());
                }
                // NUMBER columns without scale value have it set to -127 instead of null;
                // let's rectify that
                else if (column.jdbcType() == OracleTypes.NUMBER) {
                    column.scale()
                            .filter(s -> s == ORACLE_UNSET_SCALE)
                            .ifPresent(s -> {
                                editor.addColumn(
                                        column.edit()
                                                .scale(null)
                                                .create());
                            });
                }
            }
            tables.overwriteTable(editor.create());
        }

        tables.removeTable(tableId);
    }
}