Search in sources :

Example 16 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.

the class GeometryPresentation method refreshData.

@Override
public void refreshData(boolean refreshMetadata, boolean append, boolean keepState) {
    controller.updateEditControls();
    List<GeometryDataUtils.GeomAttrs> result = GeometryDataUtils.extractGeometryAttributes(getController());
    ResultSetModel model = getController().getModel();
    // Now extract all geom values from data
    List<DBGeometry> geometries = new ArrayList<>();
    for (int i = 0; i < result.size(); i++) {
        GeometryDataUtils.GeomAttrs geomAttrs = result.get(i);
        Color attrColor;
        if (i == 0) {
            attrColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
        } else {
            attrColor = UIColors.getColor(i);
        }
        RGB rgb = attrColor.getRGB();
        String colorCode = String.format("#%02x%02x%02x", rgb.red, rgb.green, rgb.blue);
        for (ResultSetRow row : model.getAllRows()) {
            Object value = model.getCellValue(geomAttrs.geomAttr, row);
            DBGeometry geometry = GisTransformUtils.getGeometryValueFromObject(controller.getDataContainer(), geomAttrs.geomAttr.getValueHandler(), geomAttrs.geomAttr, value);
            if (geometry != null && !(geometry.getSRID() != 0 && geometry.isEmpty())) {
                geometries.add(geometry);
                // Now get description
                Map<String, Object> properties = new LinkedHashMap<>();
                properties.put("id", DBUtils.getObjectFullName(geomAttrs.geomAttr, DBPEvaluationContext.UI));
                properties.put("color", colorCode);
                if (!geomAttrs.descAttrs.isEmpty()) {
                    Map<String, Object> infoMap = new LinkedHashMap<>();
                    properties.put("info", infoMap);
                    for (DBDAttributeBinding da : geomAttrs.descAttrs) {
                        Object descValue = model.getCellValue(da, row);
                        if (!DBUtils.isNullValue(descValue) && !(descValue instanceof String && ((String) descValue).isEmpty())) {
                            infoMap.put(da.getName(), descValue);
                        }
                    }
                }
                geometry.setProperties(properties);
            }
        }
    }
    try {
        leafletViewer.setGeometryData(geometries.toArray(new DBGeometry[0]));
    } catch (DBException e) {
        DBWorkbench.getPlatformUI().showError("Error rendering GIS data", "Error while rendering geometry data", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) GeometryDataUtils(org.jkiss.dbeaver.ui.gis.GeometryDataUtils) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry)

Example 17 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.

the class SQLSemanticProcessor method isValidTableColumn.

private static boolean isValidTableColumn(DBRProgressMonitor monitor, DBPDataSource dataSource, Table table, DBDAttributeConstraint co) throws DBException {
    DBSAttributeBase attribute = co.getAttribute();
    if (attribute instanceof DBDAttributeBinding) {
        attribute = ((DBDAttributeBinding) attribute).getMetaAttribute();
    }
    if (table != null && attribute instanceof DBCAttributeMetaData) {
        DBSEntityAttribute entityAttribute = null;
        DBCEntityMetaData entityMetaData = ((DBCAttributeMetaData) attribute).getEntityMetaData();
        if (entityMetaData != null) {
            DBSEntity entity = DBUtils.getEntityFromMetaData(monitor, DBUtils.getDefaultContext(dataSource, true), entityMetaData);
            if (entity != null) {
                entityAttribute = entity.getAttribute(monitor, co.getAttributeName());
            }
        }
        // No such attribute in entity. Do not use table prefix (#6927)
        return entityAttribute != null;
    }
    return true;
}
Also used : DBCAttributeMetaData(org.jkiss.dbeaver.model.exec.DBCAttributeMetaData) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBCEntityMetaData(org.jkiss.dbeaver.model.exec.DBCEntityMetaData) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 18 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.

the class SQLSemanticProcessor method getConstraintTable.

/**
 * Extract alias (or source table name) for specified constraint from SQL select.
 * Searches in FROM and JOIN
 */
@Nullable
public static Table getConstraintTable(PlainSelect select, DBDAttributeConstraint constraint) {
    String constrTable;
    DBSAttributeBase ca = constraint.getAttribute();
    if (ca instanceof DBDAttributeBinding) {
        constrTable = ((DBDAttributeBinding) ca).getMetaAttribute().getEntityName();
    } else if (ca instanceof DBSEntityAttribute) {
        constrTable = ((DBSEntityAttribute) ca).getParentObject().getName();
    } else {
        return null;
    }
    if (constrTable == null) {
        return null;
    }
    FromItem fromItem = select.getFromItem();
    Table table = findTableInFrom(fromItem, constrTable);
    if (table == null) {
        // Maybe it is a join
        if (!CommonUtils.isEmpty(select.getJoins())) {
            for (Join join : select.getJoins()) {
                table = findTableInFrom(join.getRightItem(), constrTable);
                if (table != null) {
                    break;
                }
            }
        }
    }
    return table;
}
Also used : Table(net.sf.jsqlparser.schema.Table) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) Nullable(org.jkiss.code.Nullable)

Example 19 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.

the class ContentPanelEditor method makeValueId.

private String makeValueId() {
    String valueId;
    DBSTypedObject valueType = valueController.getValueType();
    if (valueType instanceof DBDAttributeBinding) {
        valueType = ((DBDAttributeBinding) valueType).getAttribute();
    }
    if (valueType instanceof DBSObject) {
        DBSObject object = (DBSObject) valueType;
        valueId = DBUtils.getObjectFullName(object, DBPEvaluationContext.DDL);
        if (object.getParentObject() != null) {
            valueId = DBUtils.getObjectFullName(object.getParentObject(), DBPEvaluationContext.DDL) + ":" + valueId;
        }
    } else {
        valueId = valueController.getValueName();
    }
    String dsId = "unknown";
    if (valueController.getExecutionContext() != null) {
        dsId = valueController.getExecutionContext().getDataSource().getContainer().getId();
    }
    return dsId + ":" + valueId;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 20 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.

the class SQLGeneratorContributor 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 List<ResultSetRow> selectedRows = new ArrayList<>(rss.getSelectedRows());
        if (!CommonUtils.isEmpty(selectedRows)) {
            List<IResultSetController> objects = new ArrayList<>();
            objects.add(rsv);
            List<SQLGeneratorDescriptor> generators = SQLGeneratorConfigurationRegistry.getInstance().getApplicableGenerators(objects, rsv);
            for (SQLGeneratorDescriptor gen : generators) {
                if (gen.isMultiObject() && selectedRows.size() < 2) {
                    continue;
                }
                menu.add(makeAction(gen.getLabel(), gen, objects));
            }
        }
    } else {
        // if (dataContainer != null && !visibleAttributes.isEmpty() && entity != null)
        String message = dataContainer == null ? "no data container" : (visibleAttributes.isEmpty() ? "empty attribute list" : "can't resolve table");
        Action disabledAction = new Action("Not available - " + message) {
        };
        disabledAction.setEnabled(false);
        menu.add(new ActionContributionItem(disabledAction));
    }
}
Also used : ArrayList(java.util.ArrayList) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) SQLGeneratorDescriptor(org.jkiss.dbeaver.model.sql.registry.SQLGeneratorDescriptor) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer)

Aggregations

DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)147 ArrayList (java.util.ArrayList)32 DBException (org.jkiss.dbeaver.DBException)29 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)24 DBDContent (org.jkiss.dbeaver.model.data.DBDContent)23 DBDContentStorage (org.jkiss.dbeaver.model.data.DBDContentStorage)23 List (java.util.List)18 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)16 DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)14 Reader (java.io.Reader)13 PrintWriter (java.io.PrintWriter)12 GridData (org.eclipse.swt.layout.GridData)12 Nullable (org.jkiss.code.Nullable)12 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)12 Date (java.util.Date)10 SWT (org.eclipse.swt.SWT)10 NotNull (org.jkiss.code.NotNull)10 DBDDataFilter (org.jkiss.dbeaver.model.data.DBDDataFilter)10 DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)10 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)10