use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class ObjectEditorPageControl method isObjectEditable.
public boolean isObjectEditable() {
DBCExecutionContext context = getEditorPart().getEditorInput().getExecutionContext();
if (context == null) {
return false;
}
if (context.getDataSource().getInfo().isReadOnlyMetaData()) {
return false;
}
DBSObject databaseObject = getEditorPart().getEditorInput().getDatabaseObject();
return databaseObject != null && EntityEditorsRegistry.getInstance().getObjectManager(databaseObject.getClass(), DBEObjectManager.class) != null;
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class DataSourceAutoCommitHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
DBCExecutionContext context = getExecutionContext(event, true);
if (context != null) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
if (txnManager != null) {
try {
final DBPDataSourceContainer container = context.getDataSource().getContainer();
boolean newAutocommit = !container.isDefaultAutoCommit();
if (context.isConnected()) {
// Get flag from connection
newAutocommit = !txnManager.isAutoCommit();
}
container.setDefaultAutoCommit(newAutocommit, context, true, new Runnable() {
@Override
public void run() {
// Save config
container.persistConfiguration();
}
});
} catch (DBException e) {
UIUtils.showErrorDialog(null, "Auto-Commit", "Error while toggle auto-commit", e);
}
}
}
return null;
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class DatabaseEditorUtils method setPartBackground.
public static void setPartBackground(IEditorPart editor, Composite composite) {
CTabFolder tabFolder = null;
Composite rootComposite = null;
for (Composite c = composite; c != null; c = c.getParent()) {
if (c.getParent() instanceof CTabFolder) {
tabFolder = (CTabFolder) c.getParent();
rootComposite = c;
break;
}
}
if (tabFolder == null) {
return;
}
tabFolder.setBorderVisible(false);
Color bgColor = null;
if (editor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer container = ((IDataSourceContainerProvider) editor).getDataSourceContainer();
if (container != null) {
bgColor = UIUtils.getConnectionColor(container.getConnectionConfiguration());
}
} else if (editor instanceof DBPContextProvider) {
DBCExecutionContext context = ((DBPContextProvider) editor).getExecutionContext();
if (context != null) {
bgColor = UIUtils.getConnectionColor(context.getDataSource().getContainer().getConnectionConfiguration());
}
}
if (bgColor == null) {
rootComposite.setBackground(null);
} else {
rootComposite.setBackground(bgColor);
}
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class BaseSQLDialog method createSQLPanel.
protected Composite createSQLPanel(Composite parent) {
Composite panel = UIUtils.createPlaceholder(parent, 1);
panel.setLayoutData(new GridData(GridData.FILL_BOTH));
if (isLabelVisible()) {
UIUtils.createControlLabel(panel, "SQL Preview");
}
// new Label(panel, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Composite editorPH = new Composite(panel, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.verticalIndent = 3;
gd.horizontalSpan = 1;
gd.minimumHeight = 100;
gd.minimumWidth = 100;
editorPH.setLayoutData(gd);
editorPH.setLayout(new FillLayout());
sqlViewer = new SQLEditorBase() {
@NotNull
@Override
protected SQLDialect getSQLDialect() {
return BaseSQLDialog.this.getSQLDialect();
}
@Override
public DBCExecutionContext getExecutionContext() {
return BaseSQLDialog.this.getExecutionContext();
}
};
updateSQL();
sqlViewer.createPartControl(editorPH);
if (isWordWrap()) {
Object text = sqlViewer.getAdapter(Control.class);
if (text instanceof StyledText) {
((StyledText) text).setWordWrap(true);
}
}
sqlViewer.reloadSyntaxRules();
parent.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
sqlViewer.dispose();
}
});
return panel;
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext 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