@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { DistributedTable table = getTable(req, resp); if (table == null) { return; } int diff; try { table.useTransaction(sessionID); diff = table.rollback(); table.removeTransaction(sessionID); } catch (IllegalStateException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); return; } finally { manager.deleteTableByID(sessionID); } resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF8"); resp.getWriter().println("diff=" + diff); }
public DistributedTable(File tableDirectory, String name) throws IOException { currentPath = new File(tableDirectory.getPath() + File.separator + name); tableName = name; if (!currentPath.exists()) { if (!currentPath.mkdir()) { throw new IOException(currentPath.getAbsolutePath() + ": couldn't create directory"); } } for (int i = 0; i < partsNumber; i++) { directoriesList[i] = new File(currentPath.getPath() + File.separator + i + ".dir"); for (int j = 0; j < partsNumber; j++) { filesList[i][j] = new File(directoriesList[i].getPath() + File.separator + j + ".dat"); } } oldRecordNumber = readTable(); cache = new HashMap<>(); changes = new HashMap<>(); rollback(); }