javaoracle-databaseoracle11gucp

OracleConnection Deprecated Methods Problem


I am working on upgrading a class that uses Connection Pool. Especially the interface:

oracle.jdbc.OracleConnection

Now this interface has a lot of methods which are deprecated. I just wanted to know is there any other alternative to this interface, so that I wont get the usual:

The type XXXX must implement the inherited abstract method OracleConnection.getJavaObject(String)

so on and so forth. Previously the code was kept in check with the SupressWarning annotation. I don't like that. Is there any way to get over this? Or the annotation is the only way?

My maven dependecy import is like, if that is of any help:

<!-- https://mvnrepository.com/artifact/com.oracle/ojdbc6 -->
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.4</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.oracle/ucp -->
        <dependency>
            <groupId>com.oracle.jdbc</groupId>
            <artifactId>ucp</artifactId>
            <version>12.2.0.1</version>
        </dependency>

Adding the code (the class is only over-riding all the methods in the on OracleConnection interface), I am pretty certain it is not being used much, but since its an old code, cant really say for sure.

@SuppressWarnings("deprecation")
public class APPDBConnection implements OracleConnection {

    private OracleConnection connection;

    public APPDBConnection (OracleConnection connection) {
        super();
        this.connection = connection;
    }

    @Override
    public <T> T unwrap(Class<T> iface) throws SQLException {
        return connection.unwrap(iface);
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        return connection.isWrapperFor(iface);
    }

    @Override
    public void clearWarnings() throws SQLException {
        connection.clearWarnings();
    }
.
.
.
.

Solution

  • There is no alternative to OracleConnection that I know of, especially for Oracle 11g.

    Are you sure you absolutely need to know about OracleConnection?
    You're basically tying your implementation to a specific provider.

    Which methods provided only by OracleConnection are you effectively using?
    Consider programming against the java.sql.Connection interface.


    public class APPDBConnection implements Connection {
        private final Connection connection;
    
        public APPDBConnection(final Connection connection) {
            this.connection = connection;
        }
    

    Just pass in an already constructed OracleConnection.
    After that point, you won't know anymore about it, which imho is what interfaces aim to do.