我的 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?