0

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();
    }
.
.
.
.
hell_storm2004
  • 1,401
  • 2
  • 33
  • 66
  • Whether there is or isn't an alternative depends on how you use this class. Can you share the relevant part of your code? – Mureinik Apr 01 '19 at 07:51

1 Answers1

1

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.

LppEdd
  • 20,274
  • 11
  • 84
  • 139
  • From what i can see, there are methods like `pingDatabase()`, `getUsingXAFlag()`, `prepareStatementWithKey()` being over-riden in the method. I wont find them in the Connection interface. But to be honest, I am not even sure these methods are being used anywhere. – hell_storm2004 Apr 01 '19 at 08:12
  • @hell_storm2004 It's pretty easy to check if they're used. Remove them (by switching to implement `Connection`) and recompile. You'll get errors if they're used. – LppEdd Apr 01 '19 at 08:13
  • Yes, that is what I did for now. I am not sure where the errors happened, my total workspace has errors but because of other reasons. I will post back and later if i need any help. Thanks!!! – hell_storm2004 Apr 01 '19 at 14:20
  • 1
    @hell_storm2004 sure, feel free to ping me. – LppEdd Apr 01 '19 at 14:29