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