提交 3bd8d456 authored 作者: Thomas Mueller's avatar Thomas Mueller

New system property h2.selectForUpdateMvcc, the default is false (the feature is disabled).

上级 83b86da8
...@@ -28,6 +28,7 @@ import org.h2.index.IndexType; ...@@ -28,6 +28,7 @@ import org.h2.index.IndexType;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.result.ResultInterface; import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
import org.h2.result.SortOrder; import org.h2.result.SortOrder;
import org.h2.table.Column; import org.h2.table.Column;
...@@ -484,6 +485,10 @@ public class Select extends Query { ...@@ -484,6 +485,10 @@ public class Select extends Query {
} }
int rowNumber = 0; int rowNumber = 0;
setCurrentRowNumber(0); setCurrentRowNumber(0);
ArrayList<Row> forUpdateRows = null;
if (isForUpdateMvcc) {
forUpdateRows = New.arrayList();
}
while (topTableFilter.next()) { while (topTableFilter.next()) {
setCurrentRowNumber(rowNumber + 1); setCurrentRowNumber(rowNumber + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) { if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
...@@ -493,7 +498,7 @@ public class Select extends Query { ...@@ -493,7 +498,7 @@ public class Select extends Query {
row[i] = expr.getValue(session); row[i] = expr.getValue(session);
} }
if (isForUpdateMvcc) { if (isForUpdateMvcc) {
topTableFilter.lockRow(); topTableFilter.lockRow(forUpdateRows);
} }
result.addRow(row); result.addRow(row);
rowNumber++; rowNumber++;
...@@ -505,6 +510,9 @@ public class Select extends Query { ...@@ -505,6 +510,9 @@ public class Select extends Query {
} }
} }
} }
if (isForUpdateMvcc) {
topTableFilter.lockRows(forUpdateRows);
}
} }
private void queryQuick(int columnCount, LocalResult result) { private void queryQuick(int columnCount, LocalResult result) {
...@@ -544,6 +552,19 @@ public class Select extends Query { ...@@ -544,6 +552,19 @@ public class Select extends Query {
topTableFilter.reset(); topTableFilter.reset();
boolean exclusive = isForUpdate && !isForUpdateMvcc; boolean exclusive = isForUpdate && !isForUpdateMvcc;
topTableFilter.lock(session, exclusive, exclusive); topTableFilter.lock(session, exclusive, exclusive);
if (isForUpdateMvcc) {
if (isGroupQuery) {
throw DbException.getUnsupportedException("FOR UPDATE && GROUP");
} else if (distinct) {
throw DbException.getUnsupportedException("FOR UPDATE && DISTINCT");
} else if (isQuickAggregateQuery) {
throw DbException.getUnsupportedException("FOR UPDATE && AGGREGATE");
} else if (topTableFilter.getJoin() != null) {
throw DbException.getUnsupportedException("FOR UPDATE && JOIN");
} else if (topTableFilter.getJoin() != null) {
throw DbException.getUnsupportedException("FOR UPDATE && JOIN");
}
}
if (isQuickAggregateQuery) { if (isQuickAggregateQuery) {
queryQuick(columnCount, result); queryQuick(columnCount, result);
} else if (isGroupQuery) { } else if (isGroupQuery) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论