Search in sources :

Example 6 with QMMTransactionSavepointInfo

use of org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo in project dbeaver by dbeaver.

the class QMUtils method getTransactionState.

@NotNull
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++;
                    DBCExecutionPurpose purpose = exec.getStatement().getPurpose();
                    if (!exec.hasError() && purpose != DBCExecutionPurpose.META && purpose != DBCExecutionPurpose.UTIL) {
                        txnStartTime = exec.getOpenTime();
                        updateCount++;
                    }
                }
            } else {
                // No active transaction?
                txnMode = false;
            }
        } else {
            txnMode = false;
        }
    }
    if (txnStartTime <= 0) {
        txnStartTime = System.currentTimeMillis();
    }
    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) DBCExecutionPurpose(org.jkiss.dbeaver.model.exec.DBCExecutionPurpose) QMMTransactionSavepointInfo(org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo) QMMTransactionInfo(org.jkiss.dbeaver.model.qm.meta.QMMTransactionInfo) NotNull(org.jkiss.code.NotNull)

Aggregations

QMMSessionInfo (org.jkiss.dbeaver.model.qm.meta.QMMSessionInfo)6 QMMStatementExecuteInfo (org.jkiss.dbeaver.model.qm.meta.QMMStatementExecuteInfo)6 QMMTransactionSavepointInfo (org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo)6 DBCExecutionPurpose (org.jkiss.dbeaver.model.exec.DBCExecutionPurpose)4 QMMTransactionInfo (org.jkiss.dbeaver.model.qm.meta.QMMTransactionInfo)4 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 Shell (org.eclipse.swt.widgets.Shell)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 NotNull (org.jkiss.code.NotNull)2 CoreMessages (org.jkiss.dbeaver.core.CoreMessages)2 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)2 QMEventFilter (org.jkiss.dbeaver.model.qm.QMEventFilter)2 QMUtils (org.jkiss.dbeaver.model.qm.QMUtils)2 QMMObject (org.jkiss.dbeaver.model.qm.meta.QMMObject)2 UIUtils (org.jkiss.dbeaver.ui.UIUtils)2