Search in sources :

Example 1 with QMMTransactionSavepointInfo

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

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 && sessionInfo.isTransactional()) {
            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)

Example 2 with QMMTransactionSavepointInfo

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

the class TransactionInfoDialog method createContextFilter.

protected QMEventFilter createContextFilter(DBCExecutionContext executionContext) {
    if (executionContext == null) {
        return VOID_FILTER;
    }
    final boolean showAll = showAllCheck != null && showAllCheck.getSelection();
    final boolean showPrevious = showPreviousCheck != null && showPreviousCheck.getSelection();
    final QMMSessionInfo currentSession = QMUtils.getCurrentSession(executionContext);
    final QMMTransactionSavepointInfo currentSP = QMUtils.getCurrentTransaction(executionContext);
    QMEventFilter filter = new QMEventFilter() {

        @Override
        public boolean accept(QMMetaEvent event) {
            QMMObject object = event.getObject();
            if (object instanceof QMMStatementExecuteInfo) {
                QMMStatementExecuteInfo exec = (QMMStatementExecuteInfo) object;
                if (!showPrevious && exec.getSavepoint() != currentSP) {
                    return false;
                }
                if (exec.getStatement().getSession() != currentSession) {
                    return false;
                }
                DBCExecutionPurpose purpose = exec.getStatement().getPurpose();
                if (purpose == DBCExecutionPurpose.META || purpose == DBCExecutionPurpose.UTIL) {
                    return false;
                }
                return (showAll || exec.isTransactional());
            }
            return false;
        }
    };
    return filter;
}
Also used : QMMSessionInfo(org.jkiss.dbeaver.model.qm.meta.QMMSessionInfo) QMEventFilter(org.jkiss.dbeaver.model.qm.QMEventFilter) QMMetaEvent(org.jkiss.dbeaver.model.qm.QMMetaEvent) QMMStatementExecuteInfo(org.jkiss.dbeaver.model.qm.meta.QMMStatementExecuteInfo) DBCExecutionPurpose(org.jkiss.dbeaver.model.exec.DBCExecutionPurpose) QMMObject(org.jkiss.dbeaver.model.qm.meta.QMMObject) QMMTransactionSavepointInfo(org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo)

Example 3 with QMMTransactionSavepointInfo

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

the class TransactionInfoDialog method createContextFilter.

protected QMEventFilter createContextFilter(DBCExecutionContext executionContext) {
    if (executionContext == null) {
        return VOID_FILTER;
    }
    final boolean showAll = showAllCheck != null && showAllCheck.getSelection();
    final boolean showPrevious = showPreviousCheck != null && showPreviousCheck.getSelection();
    final QMMSessionInfo currentSession = QMUtils.getCurrentSession(executionContext);
    final QMMTransactionSavepointInfo currentSP = QMUtils.getCurrentTransaction(executionContext);
    QMEventFilter filter = event -> {
        QMMObject object = event.getObject();
        if (object instanceof QMMStatementExecuteInfo) {
            QMMStatementExecuteInfo exec = (QMMStatementExecuteInfo) object;
            if (!showPrevious && !CommonUtils.equalObjects(exec.getSavepoint(), currentSP)) {
                return false;
            }
            if (!showAll && !CommonUtils.equalObjects(exec.getStatement().getSession(), currentSession)) {
                return false;
            }
            DBCExecutionPurpose purpose = exec.getStatement().getPurpose();
            if (purpose == DBCExecutionPurpose.META || purpose == DBCExecutionPurpose.UTIL) {
                return false;
            }
            return (showAll || exec.isTransactional());
        }
        return false;
    };
    return filter;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) QMMSessionInfo(org.jkiss.dbeaver.model.qm.meta.QMMSessionInfo) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) QMMStatementExecuteInfo(org.jkiss.dbeaver.model.qm.meta.QMMStatementExecuteInfo) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) CoreMessages(org.jkiss.dbeaver.core.CoreMessages) QueryLogViewer(org.jkiss.dbeaver.ui.controls.querylog.QueryLogViewer) DBCExecutionPurpose(org.jkiss.dbeaver.model.exec.DBCExecutionPurpose) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) QMUtils(org.jkiss.dbeaver.model.qm.QMUtils) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) QMEventFilter(org.jkiss.dbeaver.model.qm.QMEventFilter) QMMTransactionSavepointInfo(org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo) AbstractPopupPanel(org.jkiss.dbeaver.ui.dialogs.AbstractPopupPanel) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) QMMObject(org.jkiss.dbeaver.model.qm.meta.QMMObject) QMMSessionInfo(org.jkiss.dbeaver.model.qm.meta.QMMSessionInfo) QMEventFilter(org.jkiss.dbeaver.model.qm.QMEventFilter) QMMStatementExecuteInfo(org.jkiss.dbeaver.model.qm.meta.QMMStatementExecuteInfo) DBCExecutionPurpose(org.jkiss.dbeaver.model.exec.DBCExecutionPurpose) QMMObject(org.jkiss.dbeaver.model.qm.meta.QMMObject) QMMTransactionSavepointInfo(org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo)

Example 4 with QMMTransactionSavepointInfo

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

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)

Example 5 with QMMTransactionSavepointInfo

use of org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo 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)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 QMEventFilter (org.jkiss.dbeaver.model.qm.QMEventFilter)2 QMMObject (org.jkiss.dbeaver.model.qm.meta.QMMObject)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Shell (org.eclipse.swt.widgets.Shell)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 NotNull (org.jkiss.code.NotNull)1 CoreMessages (org.jkiss.dbeaver.core.CoreMessages)1 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)1 QMMetaEvent (org.jkiss.dbeaver.model.qm.QMMetaEvent)1 QMUtils (org.jkiss.dbeaver.model.qm.QMUtils)1