Search in sources :

Example 1 with ResultSetRow

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

the class StatisticsPresentation method refreshData.

@Override
public void refreshData(boolean refreshMetadata, boolean append, boolean keepState) {
    table.removeAll();
    ResultSetRow row = controller.getModel().getRow(0);
    java.util.List<DBDAttributeBinding> visibleAttributes = controller.getModel().getVisibleAttributes();
    for (int i = 0; i < visibleAttributes.size(); i++) {
        DBDAttributeBinding attr = visibleAttributes.get(i);
        Object value = row.getValues()[i];
        TableItem item = new TableItem(table, SWT.LEFT);
        item.setText(0, attr.getName());
        item.setText(1, DBValueFormatting.getDefaultValueDisplayString(value, DBDDisplayFormat.UI));
    }
    UIUtils.packColumns(table);
}
Also used : ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 2 with ResultSetRow

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

the class SpreadsheetFindReplaceTarget method replaceSelection.

@Override
public void replaceSelection(String text, boolean regExReplace) {
    GridPos selection = (GridPos) owner.getSelection().getFirstElement();
    if (selection == null) {
        return;
    }
    GridCell cell = owner.getSpreadsheet().posToCell(selection);
    if (cell == null) {
        return;
    }
    String oldValue = owner.getSpreadsheet().getContentProvider().getCellText(cell.col, cell.row);
    String newValue = text;
    if (searchPattern != null) {
        newValue = searchPattern.matcher(oldValue).replaceAll(newValue);
    }
    boolean recordMode = owner.getController().isRecordMode();
    final DBDAttributeBinding attr = (DBDAttributeBinding) (recordMode ? cell.row : cell.col);
    final ResultSetRow row = (ResultSetRow) (recordMode ? cell.col : cell.row);
    owner.getController().getModel().updateCellValue(attr, row, newValue);
    owner.getController().updatePanelsContent(false);
}
Also used : GridPos(org.jkiss.dbeaver.ui.controls.lightgrid.GridPos) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) GridCell(org.jkiss.dbeaver.ui.controls.lightgrid.GridCell)

Example 3 with ResultSetRow

use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow 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

DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)3 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)3 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 GridCell (org.jkiss.dbeaver.ui.controls.lightgrid.GridCell)1 GridPos (org.jkiss.dbeaver.ui.controls.lightgrid.GridPos)1 IResultSetController (org.jkiss.dbeaver.ui.controls.resultset.IResultSetController)1 ResultSetModel (org.jkiss.dbeaver.ui.controls.resultset.ResultSetModel)1