Search in sources :

Example 1 with DBDValueError

use of org.jkiss.dbeaver.model.impl.data.DBDValueError in project dbeaver by dbeaver.

the class ResultSetDataReceiver method fetchRow.

@Override
public void fetchRow(DBCSession session, DBCResultSet resultSet) {
    Object[] row = new Object[columnsCount];
    for (int i = 0; i < columnsCount; i++) {
        try {
            DBSAttributeBase metaAttribute = metaColumns[i].getAttribute();
            if (metaAttribute == null) {
                continue;
            }
            row[i] = metaColumns[i].getValueHandler().fetchValueObject(session, resultSet, metaAttribute, metaColumns[i].getOrdinalPosition());
        } catch (Throwable e) {
            // Do not reports the same error multiple times
            // There are a lot of error could occur during result set fetch
            // We report certain error only once
            row[i] = new DBDValueError(e);
            List<String> attrErrors = this.attrErrors.computeIfAbsent(metaColumns[i].getMetaAttribute(), k -> new ArrayList<>());
            String errMessage = e.getClass().getName();
            if (!errMessage.startsWith("java.lang.")) {
                errMessage += ":" + e.getMessage();
            }
            if (!attrErrors.contains(errMessage)) {
                log.warn("Can't read column '" + metaColumns[i].getName() + "' value", e);
                attrErrors.add(errMessage);
                errorList.add(e);
            }
        }
    }
    rows.add(row);
}
Also used : DBDDataReceiverInteractive(org.jkiss.dbeaver.model.data.DBDDataReceiverInteractive) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBDValueError(org.jkiss.dbeaver.model.impl.data.DBDValueError) DBUtils(org.jkiss.dbeaver.model.DBUtils) org.jkiss.dbeaver.model.exec(org.jkiss.dbeaver.model.exec) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) List(java.util.List) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Map(java.util.Map) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) DBDDataReceiver(org.jkiss.dbeaver.model.data.DBDDataReceiver) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) ArrayList(java.util.ArrayList) DBDValueError(org.jkiss.dbeaver.model.impl.data.DBDValueError) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with DBDValueError

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

the class ValueViewerPanel method viewValue.

private void viewValue(boolean forceRefresh) {
    if (valueSaving) {
        return;
    }
    if (valueManager == null || valueEditor == null) {
        forceRefresh = true;
    }
    if (forceRefresh) {
        cleanupPanel();
        referenceValueEditor = new ReferenceValueEditor(previewController, valueEditor);
        final boolean referenceValue = referenceValueEditor.isReferenceValue();
        if (referenceValue) {
            previewController.setEditType(IValueController.EditType.INLINE);
        } else {
            previewController.setEditType(IValueController.EditType.PANEL);
        }
        // Create a new one
        valueManager = previewController.getValueManager();
        try {
            valueEditor = valueManager.createEditor(previewController);
        } catch (Throwable e) {
            DBWorkbench.getPlatformUI().showError("Value preview", "Can't create value viewer", e);
            return;
        }
        if (valueEditor != null) {
            try {
                valueEditor.createControl();
            } catch (Exception e) {
                log.error(e);
            }
            boolean singleLineEditor = false;
            Control control = valueEditor.getControl();
            if (control != null) {
                singleLineEditor = control instanceof Combo || control instanceof CCombo || control instanceof Button || (control instanceof Text && (control.getStyle() & SWT.MULTI) == 0);
                UIUtils.addFocusTracker(presentation.getController().getSite(), VALUE_VIEW_CONTROL_ID, control);
                presentation.getController().lockActionsByFocus(control);
            }
            if (referenceValue || singleLineEditor) {
                GridLayout gl = new GridLayout(1, false);
                viewPlaceholder.setLayout(gl);
                valueEditor.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                referenceValueEditor.setValueEditor(valueEditor);
                referenceValueEditor.createEditorSelector(viewPlaceholder);
            } else {
                viewPlaceholder.setLayout(new FillLayout());
            }
        } else {
            final Composite placeholder = UIUtils.createPlaceholder(viewPlaceholder, 1);
            placeholder.setBackground(placeholder.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            placeholder.addPaintListener(e -> {
                Rectangle bounds = placeholder.getBounds();
                String message = "No editor for [" + previewController.getValueType().getTypeName() + "]";
                Point ext = e.gc.textExtent(message);
                e.gc.drawText(message, (bounds.width - ext.x) / 2, bounds.height / 3 + 20);
            });
            referenceValueEditor = null;
        }
        viewPlaceholder.layout();
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(false);
    }
    if (valueEditor != null) {
        try {
            Object newValue = previewController.getValue();
            if (newValue instanceof DBDValueError) {
            // Error value. Do not populate it in value viewer
            } else if (newValue instanceof DBDValue) {
                // Do not check for difference
                valueEditor.primeEditorValue(newValue);
            } else {
                Object oldValue = null;
                try {
                    if (previewController.getExecutionContext() != null) {
                        oldValue = valueEditor.extractEditorValue();
                    }
                } catch (Throwable e) {
                // Some error extracting current value
                // This may happen if we were disconnected
                }
                if (forceRefresh || !CommonUtils.equalObjects(oldValue, newValue)) {
                    valueEditor.primeEditorValue(newValue);
                }
            }
        } catch (DBException e) {
            log.error(e);
        }
        valueEditor.setDirty(false);
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(true);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) Rectangle(org.eclipse.swt.graphics.Rectangle) CCombo(org.eclipse.swt.custom.CCombo) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) ReferenceValueEditor(org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor) DBException(org.jkiss.dbeaver.DBException) BaseValueEditor(org.jkiss.dbeaver.ui.data.editors.BaseValueEditor) GridLayout(org.eclipse.swt.layout.GridLayout) CCombo(org.eclipse.swt.custom.CCombo) DBDValue(org.jkiss.dbeaver.model.data.DBDValue) GridData(org.eclipse.swt.layout.GridData) DBDValueError(org.jkiss.dbeaver.model.impl.data.DBDValueError)

Example 3 with DBDValueError

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

the class ResultSetDataReceiver method fetchRow.

@Override
public void fetchRow(DBCSession session, DBCResultSet resultSet) {
    Object[] row = new Object[columnsCount];
    for (int i = 0; i < columnsCount; i++) {
        try {
            DBSAttributeBase metaAttribute = metaColumns[i].getAttribute();
            if (metaAttribute == null) {
                continue;
            }
            row[i] = metaColumns[i].getValueHandler().fetchValueObject(session, resultSet, metaAttribute, metaColumns[i].getOrdinalPosition());
        } catch (Throwable e) {
            // Do not reports the same error multiple times
            // There are a lot of error could occur during result set fetch
            // We report certain error only once
            row[i] = new DBDValueError(e);
            List<String> attrErrors = this.attrErrors.computeIfAbsent(metaColumns[i].getMetaAttribute(), k -> new ArrayList<>());
            String errMessage = e.getClass().getName();
            if (!errMessage.startsWith("java.lang.")) {
                errMessage += ":" + e.getMessage();
            }
            if (!attrErrors.contains(errMessage)) {
                log.warn("Can't read column '" + metaColumns[i].getName() + "' value", e);
                attrErrors.add(errMessage);
                errorList.add(e);
            }
        }
    }
    rows.add(row);
}
Also used : DBDDataReceiverInteractive(org.jkiss.dbeaver.model.data.DBDDataReceiverInteractive) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBDValueError(org.jkiss.dbeaver.model.impl.data.DBDValueError) DBUtils(org.jkiss.dbeaver.model.DBUtils) org.jkiss.dbeaver.model.exec(org.jkiss.dbeaver.model.exec) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) List(java.util.List) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Map(java.util.Map) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) DBDDataReceiver(org.jkiss.dbeaver.model.data.DBDDataReceiver) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) ArrayList(java.util.ArrayList) DBDValueError(org.jkiss.dbeaver.model.impl.data.DBDValueError) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with DBDValueError

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

the class DBUtils method getAttributeValue.

@Nullable
public static Object getAttributeValue(@NotNull DBDAttributeBinding attribute, DBDAttributeBinding[] allAttributes, Object[] row) {
    if (attribute.isCustom()) {
        return DBVUtils.executeExpression(((DBDAttributeBindingCustom) attribute).getEntityAttribute(), allAttributes, row);
    }
    int depth = attribute.getLevel();
    if (depth == 0) {
        final int index = attribute.getOrdinalPosition();
        if (index >= row.length) {
            log.debug("Bad attribute '" + attribute.getName() + "' index: " + index + " is out of row values' bounds (" + row.length + ")");
            return null;
        } else {
            return row[index];
        }
    }
    Object curValue = row[attribute.getTopParent().getOrdinalPosition()];
    for (int i = 0; i < depth; i++) {
        if (curValue == null) {
            break;
        }
        DBDAttributeBinding attr = attribute.getParent(depth - i - 1);
        assert attr != null;
        try {
            curValue = attr.extractNestedValue(curValue);
        } catch (Throwable e) {
            // log.debug("Error reading nested value of [" + attr.getName() + "]", e);
            curValue = new DBDValueError(e);
            break;
        }
    }
    return curValue;
}
Also used : DBDValueError(org.jkiss.dbeaver.model.impl.data.DBDValueError) DBVEntityConstraint(org.jkiss.dbeaver.model.virtual.DBVEntityConstraint) Nullable(org.jkiss.code.Nullable)

Example 5 with DBDValueError

use of org.jkiss.dbeaver.model.impl.data.DBDValueError in project dbeaver by dbeaver.

the class DBUtils method getAttributeValue.

@Nullable
public static Object getAttributeValue(@NotNull DBDAttributeBinding attribute, DBDAttributeBinding[] allAttributes, Object[] row) {
    if (attribute.isCustom()) {
        return DBVUtils.executeExpression(((DBDAttributeBindingCustom) attribute).getEntityAttribute(), allAttributes, row);
    }
    int depth = attribute.getLevel();
    if (depth == 0) {
        final int index = attribute.getOrdinalPosition();
        if (index >= row.length) {
            log.debug("Bad attribute '" + attribute.getName() + "' index: " + index + " is out of row values' bounds (" + row.length + ")");
            return null;
        } else {
            return row[index];
        }
    }
    Object curValue = row[attribute.getTopParent().getOrdinalPosition()];
    for (int i = 0; i < depth; i++) {
        if (curValue == null) {
            break;
        }
        DBDAttributeBinding attr = attribute.getParent(depth - i - 1);
        assert attr != null;
        try {
            curValue = attr.extractNestedValue(curValue);
        } catch (Throwable e) {
            // log.debug("Error reading nested value of [" + attr.getName() + "]", e);
            curValue = new DBDValueError(e);
            break;
        }
    }
    return curValue;
}
Also used : DBDValueError(org.jkiss.dbeaver.model.impl.data.DBDValueError) DBVEntityConstraint(org.jkiss.dbeaver.model.virtual.DBVEntityConstraint) Nullable(org.jkiss.code.Nullable)

Aggregations

DBDValueError (org.jkiss.dbeaver.model.impl.data.DBDValueError)6 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 CCombo (org.eclipse.swt.custom.CCombo)2 Point (org.eclipse.swt.graphics.Point)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Nullable (org.jkiss.code.Nullable)2 DBException (org.jkiss.dbeaver.DBException)2 Log (org.jkiss.dbeaver.Log)2 ModelPreferences (org.jkiss.dbeaver.ModelPreferences)2 DBUtils (org.jkiss.dbeaver.model.DBUtils)2 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)2 DBDDataReceiver (org.jkiss.dbeaver.model.data.DBDDataReceiver)2 DBDDataReceiverInteractive (org.jkiss.dbeaver.model.data.DBDDataReceiverInteractive)2 DBDValue (org.jkiss.dbeaver.model.data.DBDValue)2