Skip to content

Commit

Permalink
dbeaver/pro#2542 Check SQL state in rollback errors and show warnings…
Browse files Browse the repository at this point in the history
… for 25P01 (#34264)

Co-authored-by: MashaKorax <84867187+MashaKorax@users.noreply.github.com>
  • Loading branch information
serge-rider and MashaKorax committed Jun 5, 2024
1 parent a604d02 commit 786cf80
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,11 @@ public void rollback(@NotNull DBCSession session, DBCSavepoint savepoint)
dbCon.rollback();
}
} catch (SQLException e) {
throw new JDBCException(e, this);
if (JDBCUtils.isRollbackWarning(e)) {
log.debug("Rollback warning: " + e.getMessage());
} else {
throw new JDBCException(e, this);
}
} finally {
if (session.isLoggingEnabled()) {
QMUtils.getDefaultHandler().handleTransactionRollback(this, savepoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLDialect;
import org.jkiss.dbeaver.model.sql.SQLState;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSObjectFilter;
Expand Down Expand Up @@ -862,4 +863,10 @@ public static void executeInMetaSession(@NotNull DBRProgressMonitor monitor, @No
public static String[] getColumnList(@NotNull String columnName) {
return new String[] {columnName.toLowerCase()};
}

public static boolean isRollbackWarning(SQLException sqlError) {
return
SQLState.SQL_25P01.getCode().equals(sqlError.getSQLState());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.jkiss.dbeaver.model.impl.jdbc.exec;

import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;

import java.sql.Connection;
import java.sql.SQLException;
Expand Down Expand Up @@ -44,7 +45,15 @@ public void commit() throws SQLException {
}

public void rollback() throws SQLException {
dbCon.rollback();
try {
dbCon.rollback();
} catch (SQLException e) {
if (JDBCUtils.isRollbackWarning(e)) {
log.debug("Rollback warning: " + e.getMessage());
} else {
throw e;
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ public static <T> boolean tryExecuteRecover(@NotNull T param, @NotNull DBPDataSo
}
if (lastError != null) {
recoveryState.recoveryFailed = true;
if (lastError instanceof DBException) {
throw (DBException) lastError;
if (lastError instanceof DBException dbe) {
throw dbe;
} else {
throw new DBException(lastError, dataSource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public enum SQLState {
SQL_23000("23000", "Integrity constraint violation"),
SQL_23505("23505", "Unique value constraint is violated"),
SQL_25000("25000", "Invalid transaction state"),
SQL_25P01("25P01", "No active SQL transaction"),
SQL_25P02("25P02", "In failed SQL transaction"),
SQL_25S02("25S02", "Transaction is still active"),
SQL_25S03("25S03", "Transaction has been rolled back"),
SQL_26000("26000", "Invalid SQL statement identifier"),
Expand Down Expand Up @@ -94,7 +96,7 @@ public enum SQLState {
SQL_HY010("HY010", "Function sequence error"),
SQL_HY011("HY011", "Operation invalid at this time"),
SQL_HY012("HY012", "Invalid transaction operation code"),
SQL_HY015("HY015", "No cursor name avilable"),
SQL_HY015("HY015", "No cursor name available"),
SQL_HY018("HY018", "Server declined cancel request"),
SQL_HY090("HY090", "Invalid string or buffer length"),
SQL_HY091("HY091", "Descriptor type out of range"),
Expand Down Expand Up @@ -146,7 +148,7 @@ public enum SQLState {
private final String code;
private final String description;

private SQLState(String code, String description) {
SQLState(String code, String description) {
this.code = code;
this.description = description;
}
Expand Down

0 comments on commit 786cf80

Please sign in to comment.