提交 9ce856d8 编写于 作者: S serge-rider

#3278 Model refactoring (move to headles bundle). Reconnect notification config.

上级 a0c9fcc5
......@@ -3758,32 +3758,6 @@
</perspective>
</extension>
<!-- Notifications -->
<extension point="org.eclipse.mylyn.commons.notifications.ui.notifications">
<category id="org.jkiss.dbeaver.notifications.database.category" label="Database"/>
<sink id="org.jkiss.dbeaver.notifications.sink.Popup" class="org.jkiss.dbeaver.ui.notifications.DatabaseNotificationSink" label="Notify Popup"/>
<event categoryId="org.jkiss.dbeaver.notifications.database.category" id="org.jkiss.dbeaver.notifications.event.commit" label="Commit">
<defaultHandler sinkId="org.jkiss.dbeaver.notifications.sink.Popup"/>
<description>
This event is triggered when transaction was committed.
</description>
</event>
<event categoryId="org.jkiss.dbeaver.notifications.database.category" id="org.jkiss.dbeaver.notifications.event.rollback" label="Rollback">
<defaultHandler sinkId="org.jkiss.dbeaver.notifications.sink.Popup"/>
<description>
This event is triggered when transaction was rolled back.
</description>
</event>
<event categoryId="org.jkiss.dbeaver.notifications.database.category" id="org.jkiss.dbeaver.notifications.event.reconnect" label="Reconnect">
<defaultHandler sinkId="org.jkiss.dbeaver.notifications.sink.Popup"/>
<description>
This event is triggered when connection was automatically reconnected.
</description>
</event>
</extension>
<!-- FIXME: Disabled because it breaks dark theme. -->
<!--
<extension point="org.eclipse.e4.ui.css.core.propertyHandler">
......
......@@ -24,7 +24,7 @@ import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.qm.QMTransactionState;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.runtime.TasksJob;
import org.jkiss.dbeaver.ui.DBeaverNotifications;
import org.jkiss.dbeaver.runtime.DBeaverNotifications;
import org.jkiss.dbeaver.ui.actions.AbstractDataSourceHandler;
import org.jkiss.dbeaver.ui.controls.txn.TransactionLogDialog;
import org.jkiss.dbeaver.utils.RuntimeUtils;
......
......@@ -130,7 +130,7 @@ public class DataSourceInvalidateHandler extends AbstractDataSourceHandler
invalidateDataSource(dataSource);
}
} else {
log.info(message);
log.debug(message);
}
}
});
......
......@@ -23,10 +23,8 @@ import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.qm.QMTransactionState;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.runtime.TasksJob;
import org.jkiss.dbeaver.ui.DBeaverNotifications;
import org.jkiss.dbeaver.runtime.DBeaverNotifications;
import org.jkiss.dbeaver.ui.actions.AbstractDataSourceHandler;
import org.jkiss.dbeaver.ui.controls.txn.TransactionLogDialog;
import org.jkiss.dbeaver.utils.RuntimeUtils;
......
......@@ -65,6 +65,7 @@ Export-Package: org.jkiss.dbeaver,
org.jkiss.dbeaver.model.struct,
org.jkiss.dbeaver.model.struct.rdb,
org.jkiss.dbeaver.model.virtual,
org.jkiss.dbeaver.runtime,
org.jkiss.dbeaver.runtime.jobs,
org.jkiss.dbeaver.runtime.net,
org.jkiss.dbeaver.runtime.ui,
......
......@@ -15,11 +15,11 @@
* limitations under the License.
*/
package org.jkiss.dbeaver.ui;
package org.jkiss.dbeaver.runtime;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPMessageType;
import org.jkiss.dbeaver.ui.notifications.NotificationUtils;
/**
* Notifications utilities
......@@ -31,16 +31,36 @@ public class DBeaverNotifications
public static final String NT_ROLLBACK = "rollback";
public static final String NT_RECONNECT = "reconnect";
@NotNull
private static NotificationHandler notificationHandler = new ConsoleHandler();
public static void showNotification(DBPDataSource dataSource, String id, String text) {
NotificationUtils.sendNotification(dataSource, id, text, null, null);
showNotification(dataSource, id, text, null, null);
}
public static void showNotification(DBPDataSource dataSource, String id, String text, DBPMessageType messageType) {
NotificationUtils.sendNotification(dataSource, id, text, messageType, null);
showNotification(dataSource, id, text, messageType, null);
}
public static void showNotification(DBPDataSource dataSource, String id, String text, DBPMessageType messageType, Runnable feedback) {
NotificationUtils.sendNotification(dataSource, id, text, messageType, feedback);
notificationHandler.sendNotification(dataSource, id, text, messageType, feedback);
}
public static void setHandler(@NotNull NotificationHandler handler) {
notificationHandler = handler;
}
public interface NotificationHandler {
void sendNotification(DBPDataSource dataSource, String id, String text, DBPMessageType messageType, Runnable feedback);
}
private static class ConsoleHandler implements NotificationHandler {
@Override
public void sendNotification(DBPDataSource dataSource, String id, String text, DBPMessageType messageType, Runnable feedback) {
System.out.println(text);
}
}
}
......@@ -21,10 +21,13 @@ import org.eclipse.core.runtime.Status;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBPMessageType;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.net.DBWNetworkHandler;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.runtime.DBeaverNotifications;
import org.jkiss.dbeaver.runtime.ui.DBUserInterface;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import java.util.ArrayList;
import java.util.List;
......@@ -86,7 +89,7 @@ public class InvalidateJob extends DataSourceJob
DBPDataSourceContainer container = dataSource.getContainer();
DBWNetworkHandler[] activeHandlers = container.getActiveNetworkHandlers();
boolean networkOK = true;
boolean hasGoodContexts = false;
int goodContextsNumber = 0;
if (activeHandlers != null && activeHandlers.length > 0) {
for (DBWNetworkHandler nh : activeHandlers) {
monitor.subTask("Invalidate network [" + container.getName() + "]");
......@@ -108,7 +111,7 @@ public class InvalidateJob extends DataSourceJob
try {
final DBCExecutionContext.InvalidateResult result = context.invalidateContext(monitor, disconnectOnFailure);
if (result != DBCExecutionContext.InvalidateResult.ERROR) {
hasGoodContexts = true;
goodContextsNumber++;
}
invalidateResults.add(new ContextInvalidateResult(result, null));
} catch (Exception e) {
......@@ -118,7 +121,7 @@ public class InvalidateJob extends DataSourceJob
}
}
}
if (!hasGoodContexts && disconnectOnFailure) {
if (goodContextsNumber == 0 && disconnectOnFailure) {
// Close whole datasource. Target host seems to be unavailable
try {
container.disconnect(monitor);
......@@ -135,6 +138,21 @@ public class InvalidateJob extends DataSourceJob
DBUserInterface.getInstance().showError("Forced disconnect", "Datasource '" + container.getName() + "' was disconnected: destination database unreachable.\n" + msg);
}
if (goodContextsNumber == 0) {
DBeaverNotifications.showNotification(
dataSource,
DBeaverNotifications.NT_RECONNECT,
"Datasource invalidate failed",
DBPMessageType.ERROR);
} else {
DBeaverNotifications.showNotification(
dataSource,
DBeaverNotifications.NT_RECONNECT,
"Datasource was invalidated\n\n" +
"Live connection count: " + goodContextsNumber + "/" + dataSource.getAllContexts().length,
DBPMessageType.INFORMATION);
}
return invalidateResults;
}
......
......@@ -6,6 +6,8 @@ Bundle-SymbolicName: org.jkiss.dbeaver.ui;singleton:=true
Bundle-Version: 4.2.15
Bundle-Release-Date: 20180416
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Activator: org.jkiss.dbeaver.bundle.UIActivator
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.expressions,
org.eclipse.swt,
......@@ -18,6 +20,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.mylyn.commons.ui,
org.eclipse.mylyn.commons.notifications.core,
org.eclipse.mylyn.commons.notifications.ui,
org.eclipse.mylyn.commons.workbench,
org.jkiss.dbeaver.model
Export-Package: org.jkiss.dbeaver.ui,
org.jkiss.dbeaver.ui.notifications
......@@ -10,4 +10,30 @@
</definition>
</extension>
<!-- Notifications -->
<extension point="org.eclipse.mylyn.commons.notifications.ui.notifications">
<category id="org.jkiss.dbeaver.notifications.database.category" label="Database"/>
<sink id="org.jkiss.dbeaver.notifications.sink.Popup" class="org.jkiss.dbeaver.ui.notifications.DatabaseNotificationSink" label="Notify Popup"/>
<event categoryId="org.jkiss.dbeaver.notifications.database.category" id="org.jkiss.dbeaver.notifications.event.commit" label="Commit">
<defaultHandler sinkId="org.jkiss.dbeaver.notifications.sink.Popup"/>
<description>
This event is triggered when transaction was committed.
</description>
</event>
<event categoryId="org.jkiss.dbeaver.notifications.database.category" id="org.jkiss.dbeaver.notifications.event.rollback" label="Rollback">
<defaultHandler sinkId="org.jkiss.dbeaver.notifications.sink.Popup"/>
<description>
This event is triggered when transaction was rolled back.
</description>
</event>
<event categoryId="org.jkiss.dbeaver.notifications.database.category" id="org.jkiss.dbeaver.notifications.event.reconnect" label="Reconnect">
<defaultHandler sinkId="org.jkiss.dbeaver.notifications.sink.Popup"/>
<description>
This event is triggered when connection was automatically reconnected.
</description>
</event>
</extension>
</plugin>
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 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.bundle;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jkiss.dbeaver.runtime.DBeaverNotifications;
import org.jkiss.dbeaver.ui.notifications.NotificationUtils;
import org.osgi.framework.BundleContext;
public class UIActivator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.jkiss.dbeaver.ui";
// The shared instance
private static UIActivator plugin;
public UIActivator() {
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
// Set notifications handler
DBeaverNotifications.setHandler(NotificationUtils::sendNotification);
plugin = this;
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
public static UIActivator getDefault() {
return plugin;
}
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册