【发布时间】:2015-06-09 02:48:09
【问题描述】:
我正在使用 Google App Engine(端点)生成一个简单的 API 服务。
我目前正在尝试更快、更高效地查询数据库,因此我决定仔细检查调用 ResultSet 和 Connections 的位置并关闭它们。
但是我想使用 CachedRowSet 并且几乎不可能,因为当我尝试访问 CachedRowSetImpl() 时,记录器会返回:
java.lang.NoClassDefFoundError: com.sun.rowset.CachedRowSetImpl 是一个 限制类。请参阅 Google App Engine 开发者指南 了解更多
所以我做了一些调查,Google App Engine's JRE whitelist 包括:
javax.sql.rowset.CachedRowSet
但不是
com.sun.rowset.CachedRowSetImpl
这有意义吗?否则我该如何初始化/使用CachedRowSet?
我的代码:
public ResultSet getRecordsWhereInt(String table, String where, int condition) throws SQLException {
c = DatabaseConnect();
preStatement = c.prepareStatement("SELECT * FROM " + table + " WHERE " + where + " = ?");
preStatement.setInt(1, condition);
CachedRowSet rowset = new CachedRowSetImpl();
rowset.populate(preStatement.executeQuery());
c.close();
return rowset;
}
任何帮助/指导将不胜感激。
更新 1 (09/06/2015):
进一步调查,我发现你可以使用RowSetProvider.newFactory().createCachedRowSet();实现CachedRowSetImpl的功能
但是,Google 也限制使用 RowSetProvider()。
这给我留下了唯一一个列入白名单的库RowSetFactory。于是我自己做了一个,按照Oracle's implementation实现RowSetFactory:
public class CachedRowSetFactory implements RowSetFactory {
public CachedRowSet createCachedRowSet() throws SQLException {
return new CachedRowSetImpl();
}
public FilteredRowSet createFilteredRowSet() throws SQLException {
return null;
}
public JdbcRowSet createJdbcRowSet() throws SQLException {
return null;
}
public JoinRowSet createJoinRowSet() throws SQLException {
return null;
}
public WebRowSet createWebRowSet() throws SQLException {
return null;
}
}
然后像这样使用它:
CachedRowSet crs = new CachedRowSetFactory().createCachedRowSet();
但是,即使这样也失败了。上面的示例在我尝试使用工作结果集填充它时返回空指针异常。我猜工厂实现不是 100% 正确,或者我跳过了一些明显的东西。
更新 2(2015 年 11 月 6 日):
我尝试通过手动复制一些库并消除 App Engines 白名单中未涵盖的库来滚动我自己的 CachedRowSetImpl 和 RowSetProvider 实现。没有成功。我知道我需要放弃这一点,但我决心完成这项工作。
【问题讨论】:
标签: java google-app-engine jdbc resultset google-cloud-endpoints