Search in sources :

Example 1 with IResultSetController

use of org.jkiss.dbeaver.ui.controls.resultset.IResultSetController in project dbeaver by serge-rider.

the class CursorViewDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final IValueController valueController = getValueController();
    value = (DBDCursor) valueController.getValue();
    Composite dialogGroup = (Composite) super.createDialogArea(parent);
    if (value != null) {
        DBPPreferenceStore globalPreferenceStore = DBeaverCore.getGlobalPreferenceStore();
        if (!globalPreferenceStore.getBoolean(DBeaverPreferences.KEEP_STATEMENT_OPEN)) {
            if (ConfirmationDialog.showConfirmDialog(getShell(), DBeaverPreferences.CONFIRM_KEEP_STATEMENT_OPEN, ConfirmationDialog.QUESTION) == IDialogConstants.YES_ID) {
                globalPreferenceStore.setValue(DBeaverPreferences.KEEP_STATEMENT_OPEN, true);
                if (valueController.getValueSite().getPart() instanceof IResultSetContainer) {
                    IResultSetController rsv = ((IResultSetContainer) valueController.getValueSite().getPart()).getResultSetController();
                    if (rsv != null) {
                        rsv.refresh();
                    }
                }
            }
            DBeaverUI.asyncExec(new Runnable() {

                @Override
                public void run() {
                    close();
                }
            });
        }
    }
    resultSetViewer = new ResultSetViewer(dialogGroup, valueController.getValueSite(), this);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 300;
    gd.grabExcessVerticalSpace = true;
    resultSetViewer.getControl().setLayoutData(gd);
    resultSetViewer.refresh();
    return dialogGroup;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IResultSetContainer(org.jkiss.dbeaver.ui.controls.resultset.IResultSetContainer) GridData(org.eclipse.swt.layout.GridData) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) IValueController(org.jkiss.dbeaver.ui.data.IValueController) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Example 2 with IResultSetController

use of org.jkiss.dbeaver.ui.controls.resultset.IResultSetController in project dbeaver by serge-rider.

the class SpreadsheetCommandHandler method getActiveSpreadsheet.

public static Spreadsheet getActiveSpreadsheet(ExecutionEvent event) {
    Object control = HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
    if (control instanceof Spreadsheet) {
        return (Spreadsheet) control;
    }
    IResultSetController rsv = ResultSetCommandHandler.getActiveResultSet(HandlerUtil.getActivePart(event));
    if (rsv != null) {
        IResultSetPresentation activePresentation = rsv.getActivePresentation();
        if (activePresentation instanceof SpreadsheetPresentation) {
            return ((SpreadsheetPresentation) activePresentation).getSpreadsheet();
        }
    }
    return null;
}
Also used : IResultSetPresentation(org.jkiss.dbeaver.ui.controls.resultset.IResultSetPresentation) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController)

Example 3 with IResultSetController

use of org.jkiss.dbeaver.ui.controls.resultset.IResultSetController in project dbeaver by serge-rider.

the class GenerateSQLContributor method makeResultSetContributions.

private void makeResultSetContributions(List<IContributionItem> menu, IResultSetSelection rss) {
    final IResultSetController rsv = rss.getController();
    DBSDataContainer dataContainer = rsv.getDataContainer();
    final List<DBDAttributeBinding> visibleAttributes = rsv.getModel().getVisibleAttributes();
    final DBSEntity entity = rsv.getModel().getSingleSource();
    if (dataContainer != null && !visibleAttributes.isEmpty() && entity != null) {
        final Collection<ResultSetRow> selectedRows = rss.getSelectedRows();
        if (!CommonUtils.isEmpty(selectedRows)) {
            menu.add(makeAction("SELECT by Unique Key", new ResultSetAnalysisRunner(dataContainer.getDataSource(), rsv.getModel()) {

                @Override
                public void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, ResultSetModel object) throws DBException {
                    for (ResultSetRow firstRow : selectedRows) {
                        Collection<DBDAttributeBinding> keyAttributes = getKeyAttributes(monitor, object);
                        sql.append("SELECT ");
                        boolean hasAttr = false;
                        for (DBSAttributeBase attr : getValueAttributes(monitor, object, keyAttributes)) {
                            if (hasAttr)
                                sql.append(", ");
                            sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML));
                            hasAttr = true;
                        }
                        sql.append("\nFROM ").append(DBUtils.getObjectFullName(entity, DBPEvaluationContext.DML));
                        sql.append("\nWHERE ");
                        hasAttr = false;
                        for (DBDAttributeBinding binding : keyAttributes) {
                            if (hasAttr)
                                sql.append(" AND ");
                            sql.append(DBUtils.getObjectFullName(binding.getAttribute(), DBPEvaluationContext.DML)).append("=");
                            appendAttributeValue(rsv, sql, binding, firstRow);
                            hasAttr = true;
                        }
                        sql.append(";\n");
                    }
                }
            }));
            menu.add(makeAction("INSERT", new ResultSetAnalysisRunner(dataContainer.getDataSource(), rsv.getModel()) {

                @Override
                public void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, ResultSetModel object) throws DBException {
                    for (ResultSetRow firstRow : selectedRows) {
                        Collection<? extends DBSAttributeBase> allAttributes = getAllAttributes(monitor, object);
                        sql.append("INSERT INTO ").append(DBUtils.getObjectFullName(entity, DBPEvaluationContext.DML));
                        sql.append("\n(");
                        boolean hasAttr = false;
                        for (DBSAttributeBase attr : allAttributes) {
                            if (DBUtils.isPseudoAttribute(attr) || DBUtils.isHiddenObject(attr)) {
                                continue;
                            }
                            if (hasAttr)
                                sql.append(", ");
                            sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML));
                            hasAttr = true;
                        }
                        sql.append(")\nVALUES(");
                        hasAttr = false;
                        for (DBSAttributeBase attr : allAttributes) {
                            if (DBUtils.isPseudoAttribute(attr) || DBUtils.isHiddenObject(attr)) {
                                continue;
                            }
                            if (hasAttr)
                                sql.append(", ");
                            DBDAttributeBinding binding = rsv.getModel().getAttributeBinding(attr);
                            if (binding == null) {
                                appendDefaultValue(sql, attr);
                            } else {
                                appendAttributeValue(rsv, sql, binding, firstRow);
                            }
                            hasAttr = true;
                        }
                        sql.append(");\n");
                    }
                }
            }));
            menu.add(makeAction("UPDATE", new ResultSetAnalysisRunner(dataContainer.getDataSource(), rsv.getModel()) {

                @Override
                public void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, ResultSetModel object) throws DBException {
                    for (ResultSetRow firstRow : selectedRows) {
                        Collection<DBDAttributeBinding> keyAttributes = getKeyAttributes(monitor, object);
                        Collection<? extends DBSAttributeBase> valueAttributes = getValueAttributes(monitor, object, keyAttributes);
                        sql.append("UPDATE ").append(DBUtils.getObjectFullName(entity, DBPEvaluationContext.DML));
                        sql.append("\nSET ");
                        boolean hasAttr = false;
                        for (DBSAttributeBase attr : valueAttributes) {
                            if (DBUtils.isPseudoAttribute(attr) || DBUtils.isHiddenObject(attr)) {
                                continue;
                            }
                            if (hasAttr)
                                sql.append(", ");
                            sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML)).append("=");
                            DBDAttributeBinding binding = rsv.getModel().getAttributeBinding(attr);
                            if (binding == null) {
                                appendDefaultValue(sql, attr);
                            } else {
                                appendAttributeValue(rsv, sql, binding, firstRow);
                            }
                            hasAttr = true;
                        }
                        sql.append("\nWHERE ");
                        hasAttr = false;
                        for (DBDAttributeBinding attr : keyAttributes) {
                            if (hasAttr)
                                sql.append(" AND ");
                            sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML)).append("=");
                            appendAttributeValue(rsv, sql, attr, firstRow);
                            hasAttr = true;
                        }
                        sql.append(";\n");
                    }
                }
            }));
            menu.add(makeAction("DELETE by Unique Key", new ResultSetAnalysisRunner(dataContainer.getDataSource(), rsv.getModel()) {

                @Override
                public void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, ResultSetModel object) throws DBException {
                    for (ResultSetRow firstRow : selectedRows) {
                        Collection<DBDAttributeBinding> keyAttributes = getKeyAttributes(monitor, object);
                        sql.append("DELETE FROM ").append(DBUtils.getObjectFullName(entity, DBPEvaluationContext.DML));
                        sql.append("\nWHERE ");
                        boolean hasAttr = false;
                        for (DBDAttributeBinding binding : keyAttributes) {
                            if (hasAttr)
                                sql.append(" AND ");
                            sql.append(DBUtils.getObjectFullName(binding.getAttribute(), DBPEvaluationContext.DML)).append("=");
                            appendAttributeValue(rsv, sql, binding, firstRow);
                            hasAttr = true;
                        }
                        sql.append(";\n");
                    }
                }
            }));
        }
    }
}
Also used : ResultSetModel(org.jkiss.dbeaver.ui.controls.resultset.ResultSetModel) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Aggregations

IResultSetController (org.jkiss.dbeaver.ui.controls.resultset.IResultSetController)3 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)1 DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 IResultSetContainer (org.jkiss.dbeaver.ui.controls.resultset.IResultSetContainer)1 IResultSetPresentation (org.jkiss.dbeaver.ui.controls.resultset.IResultSetPresentation)1 ResultSetModel (org.jkiss.dbeaver.ui.controls.resultset.ResultSetModel)1 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)1 ResultSetViewer (org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)1 IValueController (org.jkiss.dbeaver.ui.data.IValueController)1