c3p0 ResultSet.unwrap引发AbstractMethodError [英] c3p0 ResultSet.unwrap throws an AbstractMethodError

查看:166
本文介绍了c3p0 ResultSet.unwrap引发AbstractMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ResultSet对象,需要将其转换为OracleResultSet,以便可以在其上调用getOPAQUE(String)方法。我正在使用c3p0作为连接池。问题是c3p0将ResultSet包装在NewProxyResultSet对象中。

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.

这应该不是问题,因为我应该能够像这样调用ResultSet上的unwrap:

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

rs.unwrap(OracleResultSet.class)

但是,这不起作用。实际上会引发AbstractMethodError:

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;

它包括堆栈跟踪,但是它没有用,因为堆栈跟踪的顶行仅指向我调用unwrap方法的确切行。这似乎表明NewProxyResultSet本身尚未实现拆包。

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.

这是怎么回事?我该如何获取NewProxyResultSet并从中获取OracleResultSet?

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

推荐答案

我想出了一种获取内部值的方法!这是一种hack,但可以。如果有人知道一种获取内在价值的更便携式的方法(例如使展开方法起作用),那么我很乐意这样做。

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.

但是,事实证明NewProxyResultSet的内部变量被声明为受保护。因此,我只是在与NewProxyResultSet相同的包中创建一个类,并使用它来获取内部值,如下所示:

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;
}
}

这篇关于c3p0 ResultSet.unwrap引发AbstractMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆