use of org.jkiss.dbeaver.model.exec.DBCStatistics in project dbeaver by serge-rider.
the class ResultSetFilterPanel method getActiveQueryText.
@NotNull
private String getActiveQueryText() {
DBCStatistics statistics = viewer.getModel().getStatistics();
String queryText = statistics == null ? null : statistics.getQueryText();
if (queryText == null || queryText.isEmpty()) {
DBSDataContainer dataContainer = viewer.getDataContainer();
if (dataContainer != null) {
return dataContainer.getName();
}
queryText = DEFAULT_QUERY_TEXT;
}
return queryText;
}
use of org.jkiss.dbeaver.model.exec.DBCStatistics in project dbeaver by serge-rider.
the class WMIClass method readData.
@NotNull
@Override
public DBCStatistics readData(@NotNull DBCExecutionSource source, @NotNull DBCSession session, @NotNull DBDDataReceiver dataReceiver, DBDDataFilter dataFilter, long firstRow, long maxRows, long flags) throws DBCException {
DBCStatistics statistics = new DBCStatistics();
try {
long startTime = System.currentTimeMillis();
WMIObjectCollectorSink sink = new WMIObjectCollectorSink(session.getProgressMonitor(), getNamespace().getService(), firstRow, maxRows);
getNamespace().getService().enumInstances(getName(), sink, WMIConstants.WBEM_FLAG_SHALLOW);
statistics.setExecuteTime(System.currentTimeMillis() - startTime);
startTime = System.currentTimeMillis();
sink.waitForFinish();
WMIResultSet resultSet = new WMIResultSet(session, this, sink.getObjectList());
long resultCount = 0;
try {
dataReceiver.fetchStart(session, resultSet, firstRow, maxRows);
while (resultSet.nextRow()) {
resultCount++;
dataReceiver.fetchRow(session, resultSet);
}
} finally {
try {
dataReceiver.fetchEnd(session, resultSet);
} catch (DBCException e) {
//$NON-NLS-1$
log.error("Error while finishing result set fetch", e);
}
resultSet.close();
dataReceiver.close();
}
statistics.setFetchTime(System.currentTimeMillis() - startTime);
statistics.setRowsFetched(resultCount);
return statistics;
} catch (WMIException e) {
throw new DBCException(e, getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.DBCStatistics in project dbeaver by dbeaver.
the class WMIClass method readData.
@NotNull
@Override
public DBCStatistics readData(@NotNull DBCExecutionSource source, @NotNull DBCSession session, @NotNull DBDDataReceiver dataReceiver, DBDDataFilter dataFilter, long firstRow, long maxRows, long flags) throws DBCException {
DBCStatistics statistics = new DBCStatistics();
try {
long startTime = System.currentTimeMillis();
WMIObjectCollectorSink sink = new WMIObjectCollectorSink(session.getProgressMonitor(), getNamespace().getService(), firstRow, maxRows);
getNamespace().getService().enumInstances(getName(), sink, WMIConstants.WBEM_FLAG_SHALLOW);
statistics.setExecuteTime(System.currentTimeMillis() - startTime);
startTime = System.currentTimeMillis();
sink.waitForFinish();
WMIResultSet resultSet = new WMIResultSet(session, this, sink.getObjectList());
long resultCount = 0;
try {
dataReceiver.fetchStart(session, resultSet, firstRow, maxRows);
while (resultSet.nextRow()) {
resultCount++;
dataReceiver.fetchRow(session, resultSet);
}
} finally {
try {
dataReceiver.fetchEnd(session, resultSet);
} catch (DBCException e) {
// $NON-NLS-1$
log.error("Error while finishing result set fetch", e);
}
resultSet.close();
dataReceiver.close();
}
statistics.setFetchTime(System.currentTimeMillis() - startTime);
statistics.setRowsFetched(resultCount);
return statistics;
} catch (WMIException e) {
throw new DBCException(e, getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.DBCStatistics in project dbeaver by dbeaver.
the class ResultSetFilterPanel method getActiveQueryText.
@NotNull
private String getActiveQueryText() {
DBCStatistics statistics = viewer.getModel().getStatistics();
String queryText = statistics == null ? null : statistics.getQueryText();
if (queryText == null || queryText.isEmpty()) {
DBSDataContainer dataContainer = viewer.getDataContainer();
if (dataContainer != null) {
return dataContainer.getName();
}
queryText = DEFAULT_QUERY_TEXT;
}
return queryText;
}
use of org.jkiss.dbeaver.model.exec.DBCStatistics in project dbeaver by serge-rider.
the class GroupingResultsContainer method rebuildGrouping.
public void rebuildGrouping() throws DBException {
if (groupAttributes.isEmpty() || groupFunctions.isEmpty()) {
groupingViewer.showEmptyPresentation();
return;
}
DBCStatistics statistics = presentation.getController().getModel().getStatistics();
if (statistics == null) {
throw new DBException("No main query - can't perform grouping");
}
DBPDataSource dataSource = dataContainer.getDataSource();
if (dataSource == null) {
throw new DBException("No active datasource");
}
SQLDialect dialect = SQLUtils.getDialectFromDataSource(dataSource);
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
syntaxManager.init(dialect, presentation.getController().getPreferenceStore());
String queryText = statistics.getQueryText();
if (queryText == null || queryText.isEmpty()) {
DBSDataContainer dataContainer = presentation.getController().getDataContainer();
if (dataContainer != null) {
queryText = dataContainer.getName();
} else {
throw new DBException("Empty data container");
}
}
for (String delimiter : syntaxManager.getStatementDelimiters()) {
while (queryText.endsWith(delimiter)) {
queryText = queryText.substring(0, queryText.length() - delimiter.length());
}
}
StringBuilder sql = new StringBuilder();
sql.append("SELECT ");
for (int i = 0; i < groupAttributes.size(); i++) {
if (i > 0)
sql.append(", ");
sql.append(DBUtils.getQuotedIdentifier(dataSource, groupAttributes.get(i)));
}
for (String func : groupFunctions) {
sql.append(", ").append(func);
}
sql.append(" FROM (\n");
sql.append(queryText);
sql.append(") src");
sql.append("\nGROUP BY ");
for (int i = 0; i < groupAttributes.size(); i++) {
if (i > 0)
sql.append(", ");
sql.append(DBUtils.getQuotedIdentifier(dataSource, groupAttributes.get(i)));
}
boolean isDefaultGrouping = groupFunctions.size() == 1 && groupFunctions.get(0).equals(DEFAULT_FUNCTION);
boolean isShowDuplicatesOnly = dataSource.getContainer().getPreferenceStore().getBoolean(ResultSetPreferences.RS_GROUPING_SHOW_DUPLICATES_ONLY);
if (isDefaultGrouping && isShowDuplicatesOnly) {
sql.append("\nHAVING ").append(DEFAULT_FUNCTION).append(" > 1");
}
dataContainer.setGroupingQuery(sql.toString());
DBDDataFilter dataFilter;
if (presentation.getController().getModel().isMetadataChanged()) {
dataFilter = new DBDDataFilter();
} else {
dataFilter = new DBDDataFilter(groupingViewer.getModel().getDataFilter());
}
String defaultSorting = dataSource.getContainer().getPreferenceStore().getString(ResultSetPreferences.RS_GROUPING_DEFAULT_SORTING);
if (!CommonUtils.isEmpty(defaultSorting) && isDefaultGrouping) {
if (dialect.supportsOrderByIndex()) {
// By default sort by count in desc order
int countPosition = groupAttributes.size() + 1;
StringBuilder orderBy = new StringBuilder();
orderBy.append(countPosition).append(" ").append(defaultSorting);
for (int i = 0; i < groupAttributes.size(); i++) {
orderBy.append(",").append(i + 1);
}
dataFilter.setOrder(orderBy.toString());
} else {
dataFilter.setOrder(groupFunctions.get(groupFunctions.size() - 1) + " " + defaultSorting);
}
}
groupingViewer.setDataFilter(dataFilter, true);
// groupingViewer.refresh();
}
Aggregations