rest - 可以在 Restful Web 服务中使用 JDBC 保存点吗?
问题描述
我的 Web 应用程序中有一个网格,其中数据是使用 jQuery API 直接从 Web 服务获取的。要求是
- 允许用户对其数据进行一些更改
- 如果他们想撤消
- 最后提交他们的更改
为了实现这一点,我使用了 JDBC 保存点并将它们保存在一个堆栈中,这个堆栈是为了允许撤消操作。我在更新语句之前设置了一个保存点,在撤消时我希望它回滚到最后一个保存点并且提交很简单。
我首先在桌面应用程序上对其进行了测试,它运行良好,但在基于 Web 的应用程序中它不起作用。
数据库连接类
private static Map<String, Connection> userConnections;
public static Connection getConnection(configsJson) {
... //getdata from json
if (userConnections == null) {
userConnections = new HashMap<>();
} else {
userConnection = userConnections.get(userKey);
}
if (userConnection == null) {
userConnection = DriverManager.getConnection("jdbc:oracle:thin:@" + sourceIP + ":" + sourcePort + ":" + sourceInstance, sourceUser, sourcePass);
userConnection.setAutoCommit(false);
userConnections.put(userKey, userConnection);
}
return userConnection;
}
我的更新功能
private static Map<String, Stack<Savepoint>> userSavePoints = new HashMap<>();
@ResponseBody
@RequestMapping(value = "/webservice/updateRecord", method = RequestMethod.POST)
public int updateRecord(HttpServletRequest request, @RequestParam String configs) throws SQLException, JSONException, ParseException {
Connection con = DBService.getConnection(configJson);
...
userSavePoints.get(userKey).push(con.setSavepoint());
return statement.executeUpdate(sql);
}
如果这里没有保存点语句,那么更新后我可以在我的网页上看到更改的记录,这些记录尚未保存在数据库中,因为自动提交设置为 false。这个保存点语句的问题是网格不显示更改的记录。在我看来,记录似乎没有更新,或者它们自动回滚到这个保存点。
我的逻辑有问题吗?或者这些保存点不适用于restful api?
解决方案
有一个愚蠢的错误,我什至没有调查,这条线返回 null 并且没有进一步处理。控制台也没有显示任何异常。
userSavePoints.get(userKey)
我只需要初始化它来解决我的问题。
推荐阅读
- javascript - 电子产生异常
- python - python串行读取的CPU负载
- c# - 如何在 Vue 实例中使用 @ViewBag?
- android - 哪个框架最适合混合 android 应用程序
- android-studio - initState() 不显示在自动建议中
- javascript - 如何从 Jade / Pug 中的脚本中读取参数?
- python-3.x - 我想将我的 python 输出从代码内部定向到特定的文本文件
- javascript - 如何更改 HTML5 视频控制栏的背景颜色
- windows - “在 pkg-config 搜索路径中找不到包”。但实际上是存在的
- flask - 如何删除烧瓶迁移文件夹和表