提交 3d85a5bc authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use try-with-resources for RowList and do not use autoDelete() in it

上级 beb14085
......@@ -76,7 +76,6 @@ public class Delete extends Prepared {
session.getUser().checkRight(table, Right.DELETE);
table.fire(session, Trigger.DELETE, true);
table.lock(session, true, false);
RowList rows = new RowList(session);
int limitRows = -1;
if (limitExpr != null) {
Value v = limitExpr.getValue(session);
......@@ -84,7 +83,7 @@ public class Delete extends Prepared {
limitRows = v.getInt();
}
}
try {
try (RowList rows = new RowList(session)) {
setCurrentRowNumber(0);
int count = 0;
while (limitRows != 0 && targetTableFilter.next()) {
......@@ -128,8 +127,6 @@ public class Delete extends Prepared {
}
table.fire(session, Trigger.DELETE, false);
return count;
} finally {
rows.close();
}
}
......
......@@ -102,8 +102,7 @@ public class Update extends Prepared {
public int update() {
targetTableFilter.startQuery(session);
targetTableFilter.reset();
RowList rows = new RowList(session);
try {
try (RowList rows = new RowList(session)) {
Table table = targetTableFilter.getTable();
session.getUser().checkRight(table, Right.UPDATE);
table.fire(session, Trigger.UPDATE, true);
......@@ -207,8 +206,6 @@ public class Update extends Prepared {
}
table.fire(session, Trigger.UPDATE, false);
return count;
} finally {
rows.close();
}
}
......
......@@ -20,7 +20,7 @@ import org.h2.value.Value;
* A list of rows. If the list grows too large, it is buffered to disk
* automatically.
*/
public class RowList {
public class RowList implements AutoCloseable {
private final Session session;
private final ArrayList<Row> list = Utils.newSmallArrayList();
......@@ -104,7 +104,6 @@ public class RowList {
writeRow(buff, r);
}
flushBuffer(buff);
file.autoDelete();
list.clear();
memory = 0;
}
......@@ -242,9 +241,9 @@ public class RowList {
/**
* Close the result list and delete the temporary file.
*/
@Override
public void close() {
if (file != null) {
file.autoDelete();
file.closeAndDeleteSilently();
file = null;
rowBuff = null;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论