Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
proper implementation of LocalSession.hasPendingTransaction(), replac…
Browse files Browse the repository at this point in the history
…e LocalSession.containsUncommitted()
  • Loading branch information
andreitokar committed Jun 13, 2021
1 parent e270127 commit 9f7a399
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions h2/src/main/org/h2/engine/SessionLocal.java
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public int getLockTimeout() {

public void setLockTimeout(int lockTimeout) {
this.lockTimeout = lockTimeout;
if (transaction != null) {
if (hasTransaction()) {
transaction.setTimeoutMillis(lockTimeout);
}
}
Expand Down Expand Up @@ -649,7 +649,7 @@ public Database getDatabase() {
*/
public void commit(boolean ddl) {
beforeCommitOrRollback();
if (transaction != null) {
if (hasTransaction()) {
try {
markUsedTablesAsUpdated();
transaction.commit();
Expand Down Expand Up @@ -749,7 +749,7 @@ private void endTransaction() {
database.releaseDatabaseObjectIds(idsToRelease);
idsToRelease = null;
}
if (transaction != null && !transaction.allowNonRepeatableRead()) {
if (hasTransaction() && !transaction.allowNonRepeatableRead()) {
snapshotDataModificationId = database.getNextModificationDataId();
}
}
Expand All @@ -769,7 +769,7 @@ public long getSnapshotDataModificationId() {
*/
public void rollback() {
beforeCommitOrRollback();
if (transaction != null) {
if (hasTransaction()) {
rollbackTo(null);
}
idsToRelease = null;
Expand All @@ -788,7 +788,7 @@ public void rollback() {
*/
public void rollbackTo(Savepoint savepoint) {
int index = savepoint == null ? 0 : savepoint.logIndex;
if (transaction != null) {
if (hasTransaction()) {
markUsedTablesAsUpdated();
if (savepoint == null) {
transaction.rollback();
Expand Down Expand Up @@ -818,7 +818,7 @@ public void rollbackTo(Savepoint savepoint) {

@Override
public boolean hasPendingTransaction() {
return false;
return hasTransaction() && transaction.hasChanges() && transaction.getStatus() != Transaction.STATUS_PREPARED;
}

/**
Expand Down Expand Up @@ -923,6 +923,11 @@ void unlock(Table t) {
locks.remove(t);
}


private boolean hasTransaction() {
return transaction != null;
}

private void unlockAll() {
if (!locks.isEmpty()) {
Table[] array = locks.toArray(new Table[0]);
Expand Down Expand Up @@ -1094,7 +1099,7 @@ public void rollbackToSavepoint(String name) {
* @param transactionName the name of the transaction
*/
public void prepareCommit(String transactionName) {
if (containsUncommitted()) {
if (hasPendingTransaction()) {
// need to commit even if rollback is not possible (create/drop
// table and so on)
database.prepareCommit(this, transactionName);
Expand Down Expand Up @@ -1713,7 +1718,7 @@ private static void addTableToDependencies(MVTable table, HashSet<MVMap<Object,V
*/
public void endStatement() {
setCurrentCommand(null);
if (transaction != null) {
if (hasTransaction()) {
transaction.markStatementEnd();
}
startStatement = -1;
Expand Down
2 changes: 1 addition & 1 deletion h2/src/main/org/h2/table/InformationSchemaTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2862,7 +2862,7 @@ private void sessions(SessionLocal session, ArrayList<Row> rows, SessionLocal s)
// EXECUTING_STATEMENT_START
command == null ? null : s.getCommandStartOrEnd(),
// CONTAINS_UNCOMMITTED
ValueBoolean.get(s.containsUncommitted()),
ValueBoolean.get(s.hasPendingTransaction()),
// SESSION_STATE
String.valueOf(s.getState()),
// BLOCKER_ID
Expand Down
2 changes: 1 addition & 1 deletion h2/src/main/org/h2/table/InformationSchemaTableLegacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ public ArrayList<Row> generateRows(SessionLocal session, SearchRow first, Search
// STATEMENT_START
command == null ? null : s.getCommandStartOrEnd(),
// CONTAINS_UNCOMMITTED
ValueBoolean.get(s.containsUncommitted()),
ValueBoolean.get(s.hasPendingTransaction()),
// STATE
String.valueOf(s.getState()),
// BLOCKER_ID
Expand Down

0 comments on commit 9f7a399

Please sign in to comment.