R – c3p0 ResultSet.unwrap throws an AbstractMethodError

c3p0jdbcoracle

I have a ResultSet object that I need to turn into an OracleResultSet so that I can call the getOPAQUE(String) method on it. I'm using c3p0 as my connection pool. The problem is that c3p0 wraps ResultSets in NewProxyResultSet objects.

This shouldn't be a problem because I should just be able to call unwrap on the ResultSet like this:

rs.unwrap(OracleResultSet.class)

However, that doesn't work. It actually throws an AbstractMethodError:

java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyResultSet.unwrap(Ljava/lang/Class;)Ljava/lang/Object;

It includes a stack trace, but it's not helpful because the top line of the stack trace just points to the exact line on which I call the unwrap method. That seems to indicate that NewProxyResultSet itself does not have unwrap implemented.

What's up with this? How can I take a NewProxyResultSet and get an OracleResultSet from it?

Best Answer

I figured out a way to get the inner value! It's a hack, but it works. If anyone knows a more portable way of getting the inner value (like making the unwrap method work) then I'd love to do that instead.

But, it turns out that the "inner" variable of the NewProxyResultSet is declared protected. So I just make a class in the same package as NewProxyResultSet and use it to get the inner value like so:

package com.mchange.v2.c3p0.impl;

import java.sql.ResultSet;

/**
 * This is a sneaky way to get at the inner ResultSet of NewProxyResultSet. It marks the     variable as protected,
 * so here I just make a class in the same package and get the value out. 
 *
 */
public class C3P0ResultSetPeeker
{
public static ResultSet getInnerFrom(NewProxyResultSet rs) {
    return rs.inner;
}
}
Related Topic