Search in sources :

Example 71 with DBDAttributeBinding

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

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 72 with DBDAttributeBinding

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

the class ViewValuePanel method refreshValue.

private void refreshValue(boolean force) {
    DBDAttributeBinding attr = presentation.getCurrentAttribute();
    ResultSetRow row = presentation.getController().getCurrentRow();
    if (attr == null || row == null) {
        clearValue();
        return;
    }
    boolean updateActions;
    if (previewController == null) {
        previewController = new ResultSetValueController(presentation.getController(), attr, row, IValueController.EditType.PANEL, viewPlaceholder) {

            @Override
            public void updateValue(@Nullable Object value, boolean updatePresentation) {
                valueSaving = true;
                try {
                    super.updateValue(value, updatePresentation);
                } finally {
                    valueSaving = false;
                }
                presentation.updateValueView();
            }
        };
        updateActions = true;
        force = true;
    } else {
        updateActions = force = (force || previewController.getBinding() != attr);
        previewController.setCurRow(row);
        previewController.setBinding(attr);
    }
    viewValue(force);
    if (updateActions) {
        presentation.getController().updatePanelActions();
    }
}
Also used : DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 73 with DBDAttributeBinding

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

the class DataExporterJSON method exportRow.

@Override
public void exportRow(DBCSession session, Object[] row) throws DBException, IOException {
    if (rowNum > 0) {
        out.write(",\n");
    }
    rowNum++;
    out.write("\t{\n");
    for (int i = 0; i < row.length; i++) {
        DBDAttributeBinding column = columns.get(i);
        String columnName = column.getName();
        out.write("\t\t\"" + escapeJsonString(columnName) + "\" : ");
        Object cellValue = row[i];
        if (DBUtils.isNullValue(cellValue)) {
            writeTextCell(null);
        } else if (cellValue instanceof DBDContent) {
            // Content
            // Inline textual content and handle binaries in some special way
            DBDContent content = (DBDContent) cellValue;
            try {
                DBDContentStorage cs = content.getContents(session.getProgressMonitor());
                if (cs != null) {
                    if (ContentUtils.isTextContent(content)) {
                        try (Reader in = cs.getContentReader()) {
                            out.write("\"");
                            writeCellValue(in);
                            out.write("\"");
                        }
                    } else {
                        getSite().writeBinaryData(cs);
                    }
                }
            } finally {
                content.release();
            }
        } else {
            if (cellValue instanceof Number || cellValue instanceof Boolean) {
                out.write(cellValue.toString());
            } else if (cellValue instanceof Date && formatDateISO) {
                writeTextCell(dateFormat.format(cellValue));
            } else {
                writeTextCell(super.getValueDisplayString(column, cellValue));
            }
        }
        if (i < row.length - 1) {
            out.write(",");
        }
        out.write("\n");
    }
    out.write("\t}");
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) Reader(java.io.Reader) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage) Date(java.util.Date)

Example 74 with DBDAttributeBinding

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

the class StreamTransferConsumer method fetchStart.

@Override
public void fetchStart(DBCSession session, DBCResultSet resultSet, long offset, long maxRows) throws DBCException {
    if (!initialized) {
        // Can be invoked multiple times in case of per-segment transfer
        initExporter(session);
    }
    // Prepare columns
    metaColumns = new ArrayList<>();
    List<DBCAttributeMetaData> attributes = resultSet.getMeta().getAttributes();
    for (DBCAttributeMetaData attribute : attributes) {
        DBDAttributeBinding columnBinding = DBUtils.getAttributeBinding(session, attribute);
        metaColumns.add(columnBinding);
    }
    row = new Object[metaColumns.size()];
    if (!initialized) {
        try {
            processor.exportHeader(session);
        } catch (DBException e) {
            log.warn("Error while exporting table header", e);
        } catch (IOException e) {
            throw new DBCException("IO error", e);
        }
    }
    initialized = true;
}
Also used : DBCAttributeMetaData(org.jkiss.dbeaver.model.exec.DBCAttributeMetaData) DBException(org.jkiss.dbeaver.DBException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 75 with DBDAttributeBinding

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

the class DataExporterCSV method printHeader.

private void printHeader() {
    for (int i = 0, columnsSize = columns.size(); i < columnsSize; i++) {
        DBDAttributeBinding column = columns.get(i);
        String colName = column.getLabel();
        if (CommonUtils.isEmpty(colName)) {
            colName = column.getName();
        }
        writeCellValue(colName, true);
        if (i < columnsSize - 1) {
            writeDelimiter();
        }
    }
    writeRowLimit();
}
Also used : DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

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