use of org.jkiss.dbeaver.model.struct.DBSInstance in project dbeaver by serge-rider.
the class InvalidateJob method invalidateDataSource.
public static List<ContextInvalidateResult> invalidateDataSource(DBRProgressMonitor monitor, DBPDataSource dataSource, boolean disconnectOnFailure, boolean showErrors, Runnable feedback) {
List<ContextInvalidateResult> invalidateResults = new ArrayList<>();
DBPDataSourceContainer container = dataSource.getContainer();
boolean networkOK;
int goodContextsNumber, aliveContextsNumber;
monitor.beginTask("Invalidate datasource '" + dataSource.getContainer().getName() + "'", 1);
monitor.subTask("Obtain exclusive datasource lock");
Object dsLock = container.getExclusiveLock().acquireTaskLock(TASK_INVALIDATE, true);
if (dsLock == DBPExclusiveResource.TASK_PROCESED) {
// Already invalidated
monitor.done();
log.debug("Datasource was already invalidated");
return invalidateResults;
}
try {
long timeSpent = 0;
monitor.subTask("Invalidate network connection");
DBWNetworkHandler[] activeHandlers = container.getActiveNetworkHandlers();
networkOK = true;
aliveContextsNumber = 0;
goodContextsNumber = 0;
if (activeHandlers != null && activeHandlers.length > 0) {
for (DBWNetworkHandler nh : activeHandlers) {
monitor.subTask("Invalidate handler [" + container.getClass().getSimpleName() + "]");
try {
nh.invalidateHandler(monitor, dataSource);
} catch (Exception e) {
invalidateResults.add(new ContextInvalidateResult(DBCExecutionContext.InvalidateResult.ERROR, e));
networkOK = false;
break;
}
}
}
// Invalidate datasource
int totalContexts = 0;
monitor.subTask("Invalidate connections of [" + container.getName() + "]");
for (DBSInstance instance : dataSource.getAvailableInstances()) {
for (DBCExecutionContext context : instance.getAllContexts()) {
totalContexts++;
if (networkOK) {
long startTime = System.currentTimeMillis();
Object exclusiveLock = instance.getExclusiveLock().acquireExclusiveLock();
try {
final DBCExecutionContext.InvalidateResult result = context.invalidateContext(monitor, disconnectOnFailure);
if (result != DBCExecutionContext.InvalidateResult.ERROR) {
goodContextsNumber++;
}
if (result == DBCExecutionContext.InvalidateResult.ALIVE) {
aliveContextsNumber++;
}
invalidateResults.add(new ContextInvalidateResult(result, null));
} catch (Exception e) {
invalidateResults.add(new ContextInvalidateResult(DBCExecutionContext.InvalidateResult.ERROR, e));
} finally {
timeSpent += (System.currentTimeMillis() - startTime);
instance.getExclusiveLock().releaseExclusiveLock(exclusiveLock);
}
}
}
}
if (goodContextsNumber > 0 && goodContextsNumber == aliveContextsNumber) {
// Nothing to reinit, all contexts are alive. Why we are here??
return invalidateResults;
}
if (goodContextsNumber == 0 && disconnectOnFailure) {
// Close whole datasource. Target host seems to be unavailable
try {
container.disconnect(monitor);
} catch (Exception e) {
log.error("Error closing inaccessible 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());
}
}
DBWorkbench.getPlatformUI().showError("Forced disconnect", "Datasource '" + container.getName() + "' was disconnected: destination database unreachable.\n" + msg);
}
if (totalContexts > 0) {
if (goodContextsNumber == 0) {
if (showErrors) {
DBeaverNotifications.showNotification(dataSource, DBeaverNotifications.NT_RECONNECT, "Datasource invalidate failed", DBPMessageType.ERROR, feedback);
}
} else {
DBeaverNotifications.showNotification(dataSource, DBeaverNotifications.NT_RECONNECT, "Datasource was invalidated\n\n" + "Live connection count: " + goodContextsNumber + "/" + totalContexts, DBPMessageType.INFORMATION);
}
}
} finally {
container.getExclusiveLock().releaseTaskLock(TASK_INVALIDATE, dsLock);
monitor.done();
}
return invalidateResults;
}
use of org.jkiss.dbeaver.model.struct.DBSInstance in project dbeaver by dbeaver.
the class PendingTransactionsDialog method loadContexts.
private void loadContexts(boolean showAllContexts) {
contextTree.removeAll();
// Load all open context
for (DBPDataSourceContainer dataSource : DataSourceRegistry.getAllDataSources()) {
if (!dataSource.isConnected() || dataSource.getDataSource() == null) {
continue;
}
for (DBSInstance instance : dataSource.getDataSource().getAvailableInstances()) {
DBCExecutionContext[] allContexts = instance.getAllContexts();
if (ArrayUtils.isEmpty(allContexts)) {
continue;
}
List<DBCExecutionContext> txnContexts = new ArrayList<>();
for (DBCExecutionContext context : allContexts) {
if (showAllContexts || QMUtils.isTransactionActive(context, false)) {
txnContexts.add(context);
}
}
if (txnContexts.isEmpty()) {
continue;
}
TreeItem dsItem = new TreeItem(contextTree, SWT.NONE);
dsItem.setText(dataSource.getName());
dsItem.setImage(DBeaverIcons.getImage(dataSource.getDriver().getIcon()));
dsItem.setData(dataSource);
for (DBCExecutionContext context : txnContexts) {
QMTransactionState txnState = QMUtils.getTransactionState(context);
TreeItem contextItem = new TreeItem(dsItem, SWT.NONE);
contextItem.setText(0, context.getContextName());
String stateString = String.valueOf(txnState.getUpdateCount()) + "/" + String.valueOf(txnState.getExecuteCount());
contextItem.setText(1, stateString);
contextItem.setData(context);
}
dsItem.setExpanded(true);
}
}
UIUtils.asyncExec(new Runnable() {
@Override
public void run() {
UIUtils.packColumns(contextTree);
}
});
}
use of org.jkiss.dbeaver.model.struct.DBSInstance in project dbeaver by dbeaver.
the class FilterMapping method getFilterContainerUniqueID.
public static String getFilterContainerUniqueID(@Nullable DBSObject parentObject) {
String objectFullName = DBUtils.getObjectFullName(parentObject, DBPEvaluationContext.UI);
DBSInstance ownerInstance = DBUtils.getObjectOwnerInstance(parentObject);
if (!CommonUtils.equalObjects(ownerInstance.getName(), parentObject.getDataSource().getName())) {
return ownerInstance.getName() + ":" + objectFullName;
} else {
return objectFullName;
}
}
use of org.jkiss.dbeaver.model.struct.DBSInstance in project dbeaver by serge-rider.
the class PendingTransactionsDialog method loadContexts.
private void loadContexts(boolean showAllContexts) {
contextTree.removeAll();
// Load all open context
for (DBPDataSourceContainer dataSource : DataSourceRegistry.getAllDataSources()) {
if (!dataSource.isConnected() || dataSource.getDataSource() == null) {
continue;
}
for (DBSInstance instance : dataSource.getDataSource().getAvailableInstances()) {
DBCExecutionContext[] allContexts = instance.getAllContexts();
if (ArrayUtils.isEmpty(allContexts)) {
continue;
}
List<DBCExecutionContext> txnContexts = new ArrayList<>();
for (DBCExecutionContext context : allContexts) {
if (showAllContexts || QMUtils.isTransactionActive(context, false)) {
txnContexts.add(context);
}
}
if (txnContexts.isEmpty()) {
continue;
}
TreeItem dsItem = new TreeItem(contextTree, SWT.NONE);
dsItem.setText(dataSource.getName());
dsItem.setImage(DBeaverIcons.getImage(dataSource.getDriver().getIcon()));
dsItem.setData(dataSource);
for (DBCExecutionContext context : txnContexts) {
QMTransactionState txnState = QMUtils.getTransactionState(context);
TreeItem contextItem = new TreeItem(dsItem, SWT.NONE);
contextItem.setText(0, context.getContextName());
String stateString = String.valueOf(txnState.getUpdateCount()) + "/" + String.valueOf(txnState.getExecuteCount());
contextItem.setText(1, stateString);
contextItem.setData(context);
}
dsItem.setExpanded(true);
}
}
UIUtils.asyncExec(new Runnable() {
@Override
public void run() {
UIUtils.packColumns(contextTree);
}
});
}
use of org.jkiss.dbeaver.model.struct.DBSInstance in project dbeaver by serge-rider.
the class FilterMapping method getFilterContainerUniqueID.
public static String getFilterContainerUniqueID(@Nullable DBSObject parentObject) {
String objectFullName = DBUtils.getObjectFullName(parentObject, DBPEvaluationContext.UI);
DBSInstance ownerInstance = DBUtils.getObjectOwnerInstance(parentObject);
if (!CommonUtils.equalObjects(ownerInstance.getName(), parentObject.getDataSource().getName())) {
return ownerInstance.getName() + ":" + objectFullName;
} else {
return objectFullName;
}
}
Aggregations