use of org.jkiss.dbeaver.model.net.DBWNetworkHandler in project dbeaver by serge-rider.
the class InvalidateJob method invalidateDataSource.
public static List<ContextInvalidateResult> invalidateDataSource(DBRProgressMonitor monitor, DBPDataSource dataSource) {
long timeSpent = 0;
List<ContextInvalidateResult> invalidateResults = new ArrayList<>();
DBPDataSourceContainer container = dataSource.getContainer();
DBWNetworkHandler[] activeHandlers = container.getActiveNetworkHandlers();
boolean networkOK = true;
boolean hasGoodContexts = false;
if (activeHandlers != null && activeHandlers.length > 0) {
for (DBWNetworkHandler nh : activeHandlers) {
monitor.subTask("Invalidate network [" + container.getName() + "]");
try {
nh.invalidateHandler(monitor);
} catch (Exception e) {
invalidateResults.add(new ContextInvalidateResult(DBCExecutionContext.InvalidateResult.ERROR, e));
networkOK = false;
break;
}
}
}
if (networkOK) {
// Invalidate datasource
monitor.subTask("Invalidate connections of [" + container.getName() + "]");
DBCExecutionContext[] allContexts = dataSource.getAllContexts();
for (DBCExecutionContext context : allContexts) {
long startTime = System.currentTimeMillis();
try {
final DBCExecutionContext.InvalidateResult result = context.invalidateContext(monitor);
if (result != DBCExecutionContext.InvalidateResult.ERROR) {
hasGoodContexts = true;
}
invalidateResults.add(new ContextInvalidateResult(result, null));
} catch (Exception e) {
invalidateResults.add(new ContextInvalidateResult(DBCExecutionContext.InvalidateResult.ERROR, e));
} finally {
timeSpent += (System.currentTimeMillis() - startTime);
}
}
}
if (!hasGoodContexts) {
// Close whole datasource. Target host seems to be unavailable
try {
container.disconnect(monitor);
} catch (Exception e) {
log.error("Error closing unaccessible datasource", e);
}
StringBuilder msg = new StringBuilder();
for (ContextInvalidateResult result : invalidateResults) {
if (result.error != null) {
if (msg.length() > 0)
msg.append("\n");
msg.append(result.error.getMessage());
}
}
UIUtils.showErrorDialog(null, "Forced disconnect", "Datasource '" + container.getName() + "' was disconnected: destination database unreachable.\n" + msg);
}
return invalidateResults;
}
Aggregations