Search in sources :

Example 1 with QMMTransactionInfo

use of org.jkiss.dbeaver.model.qm.meta.QMMTransactionInfo in project dbeaver by serge-rider.

the class QMUtils method getTransactionState.

public static QMTransactionState getTransactionState(DBCExecutionContext executionContext) {
    int execCount = 0, updateCount = 0;
    final boolean txnMode;
    long txnStartTime = 0;
    if (executionContext == null || application == null) {
        txnMode = false;
    } else {
        QMMSessionInfo sessionInfo = getCurrentSession(executionContext);
        if (sessionInfo == null || sessionInfo.isClosed()) {
            txnMode = false;
        } else if (sessionInfo.isTransactional()) {
            QMMTransactionInfo txnInfo = sessionInfo.getTransaction();
            if (txnInfo != null) {
                txnMode = true;
                QMMTransactionSavepointInfo sp = txnInfo.getCurrentSavepoint();
                QMMStatementExecuteInfo execInfo = sp.getLastExecute();
                for (QMMStatementExecuteInfo exec = execInfo; exec != null && exec.getSavepoint() == sp; exec = exec.getPrevious()) {
                    execCount++;
                    if (exec.isTransactional() && !exec.hasError()) {
                        txnStartTime = exec.getOpenTime();
                        updateCount++;
                    }
                }
            } else {
                // No active transaction?
                txnMode = false;
            }
        } else {
            txnMode = false;
        }
    }
    return new QMTransactionState(execCount, updateCount, txnMode, txnStartTime);
}
Also used : QMMSessionInfo(org.jkiss.dbeaver.model.qm.meta.QMMSessionInfo) QMMStatementExecuteInfo(org.jkiss.dbeaver.model.qm.meta.QMMStatementExecuteInfo) QMMTransactionSavepointInfo(org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo) QMMTransactionInfo(org.jkiss.dbeaver.model.qm.meta.QMMTransactionInfo)

Example 2 with QMMTransactionInfo

use of org.jkiss.dbeaver.model.qm.meta.QMMTransactionInfo in project dbeaver by serge-rider.

the class QMUtils method isTransactionActive.

public static boolean isTransactionActive(DBCExecutionContext executionContext) {
    if (executionContext == null || application == null) {
        return false;
    } else {
        QMMSessionInfo sessionInfo = getCurrentSession(executionContext);
        if (sessionInfo != null) {
            QMMTransactionInfo txnInfo = sessionInfo.getTransaction();
            if (txnInfo != null) {
                QMMTransactionSavepointInfo sp = txnInfo.getCurrentSavepoint();
                QMMStatementExecuteInfo execInfo = sp.getLastExecute();
                for (QMMStatementExecuteInfo exec = execInfo; exec != null && exec.getSavepoint() == sp; exec = exec.getPrevious()) {
                    if (exec.isTransactional()) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : QMMSessionInfo(org.jkiss.dbeaver.model.qm.meta.QMMSessionInfo) QMMStatementExecuteInfo(org.jkiss.dbeaver.model.qm.meta.QMMStatementExecuteInfo) QMMTransactionSavepointInfo(org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo) QMMTransactionInfo(org.jkiss.dbeaver.model.qm.meta.QMMTransactionInfo)

Aggregations

QMMSessionInfo (org.jkiss.dbeaver.model.qm.meta.QMMSessionInfo)2 QMMStatementExecuteInfo (org.jkiss.dbeaver.model.qm.meta.QMMStatementExecuteInfo)2 QMMTransactionInfo (org.jkiss.dbeaver.model.qm.meta.QMMTransactionInfo)2 QMMTransactionSavepointInfo (org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo)2