提交 003fb6e8 编写于 作者: S serge-rider

QMDB: history reading

上级 642c24e5
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
* Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -18,11 +18,12 @@ package org.jkiss.dbeaver.runtime.qm;
import org.eclipse.core.runtime.Adapters;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.qm.*;
import org.jkiss.dbeaver.model.qm.meta.*;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
import java.lang.reflect.InvocationHandler;
......@@ -30,6 +31,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
......@@ -168,17 +170,41 @@ public class QMControllerImpl implements QMController {
@Override
public QMEventCursor getQueryHistoryCursor(
@NotNull DBRProgressMonitor monitor,
@Nullable String containerId,
@Nullable String sessionId,
@Nullable String searchString)
@NotNull QMEventCriteria criteria)
throws DBException
{
if (CommonUtils.isEmpty(searchString)) {
return new QMUtils.ListCursorImpl(metaHandler.getPastEvents());
List<QMMetaEvent> pastEvents = metaHandler.getPastEvents();
if (criteria.getObjectTypes() != null || criteria.getQueryTypes() != null) {
// Filter by query type and object type
for (Iterator<QMMetaEvent> iter = pastEvents.iterator(); iter.hasNext(); ) {
QMMetaEvent event = iter.next();
if (criteria.getObjectTypes() != null) {
if (!matchesObjectType(event.getObject(), criteria.getObjectTypes())) {
iter.remove();
continue;
}
}
if (criteria.getQueryTypes() != null) {
QMMStatementInfo statementInfo = null;
if (event.getObject() instanceof QMMStatementInfo) {
statementInfo = (QMMStatementInfo) event.getObject();
} else if (event.getObject() instanceof QMMStatementExecuteInfo) {
statementInfo = ((QMMStatementExecuteInfo) event.getObject()).getStatement();
}
if (statementInfo != null &&
!ArrayUtils.contains(criteria.getQueryTypes(), ((QMMStatementInfo) event.getObject()).getPurpose()))
{
iter.remove();
}
}
}
}
if (CommonUtils.isEmpty(criteria.getSearchString())) {
return new QMUtils.ListCursorImpl(pastEvents);
} else {
searchString = searchString.toLowerCase();
String searchString = criteria.getSearchString().toLowerCase();
List<QMMetaEvent> filtered = new ArrayList<>();
for (QMMetaEvent event : metaHandler.getPastEvents()) {
for (QMMetaEvent event : pastEvents) {
if (event.getObject().getText().toLowerCase().contains(searchString)) {
filtered.add(event);
}
......@@ -186,5 +212,14 @@ public class QMControllerImpl implements QMController {
return new QMUtils.ListCursorImpl(filtered);
}
}
private boolean matchesObjectType(QMMObject object, QMObjectType[] objectTypes) {
if (object instanceof QMMSessionInfo)
return ArrayUtils.contains(objectTypes, QMObjectType.session);
else if (object instanceof QMMTransactionInfo || object instanceof QMMTransactionSavepointInfo)
return ArrayUtils.contains(objectTypes, QMObjectType.txn);
else
return ArrayUtils.contains(objectTypes, QMObjectType.query);
}
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
* Copyright (C) 2011-2012 Eugene Fradkin (eugene.fradkin@gmail.com)
* Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -620,8 +619,9 @@ public class QueryLogViewer extends Viewer implements QMMetaListener, DBPPrefere
try {
QMEventBrowser eventBrowser = QMUtils.getEventBrowser();
if (eventBrowser != null) {
String searchPattern = CommonUtils.isEmptyTrimmed(searchString) ? null : searchString.trim();
try (QMEventCursor cursor = eventBrowser.getQueryHistoryCursor(monitor, null, null, searchPattern)) {
QMEventCriteria criteria = new QMEventCriteria();
criteria.setSearchString(CommonUtils.isEmptyTrimmed(searchString) ? null : searchString.trim());
try (QMEventCursor cursor = eventBrowser.getQueryHistoryCursor(monitor, criteria)) {
while (events.size() < this.entriesPerPage && cursor.hasNextEvent(monitor)) {
events.add(cursor.nextEvent(monitor));
}
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
* Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -18,7 +18,6 @@
package org.jkiss.dbeaver.model.qm;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
......@@ -29,9 +28,7 @@ public interface QMEventBrowser {
QMEventCursor getQueryHistoryCursor(
@NotNull DBRProgressMonitor monitor,
@Nullable String containerId,
@Nullable String sessionId,
@Nullable String searchString)
@NotNull QMEventCriteria criteria)
throws DBException;
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.qm;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
/**
* QM event criteria
*/
public class QMEventCriteria {
@Nullable
String containerId;
@Nullable
String sessionId;
@Nullable
QMObjectType[] objectTypes;
@Nullable
DBCExecutionPurpose[] queryTypes;
@Nullable
String searchString;
public String getContainerId() {
return containerId;
}
public void setContainerId(String containerId) {
this.containerId = containerId;
}
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public QMObjectType[] getObjectTypes() {
return objectTypes;
}
public void setObjectTypes(QMObjectType[] objectTypes) {
this.objectTypes = objectTypes;
}
public DBCExecutionPurpose[] getQueryTypes() {
return queryTypes;
}
public void setQueryTypes(DBCExecutionPurpose[] queryTypes) {
this.queryTypes = queryTypes;
}
public String getSearchString() {
return searchString;
}
public void setSearchString(String searchString) {
this.searchString = searchString;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册