Search in sources :

Example 6 with DBDContent

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

the class ContentPanelEditor method createControl.

@Override
protected Control createControl(Composite editPlaceholder) {
    final DBDContent content = (DBDContent) valueController.getValue();
    if (curStreamManager == null) {
        detectStreamManager(content);
    }
    if (curStreamManager != null) {
        try {
            streamEditor = curStreamManager.getInstance().createPanelEditor(valueController);
        } catch (Throwable e) {
            UIUtils.showErrorDialog(editPlaceholder.getShell(), "No stream editor", "Can't create stream editor", e);
        }
    }
    if (streamEditor == null) {
        return UIUtils.createInfoLabel(editPlaceholder, "No Editor");
    }
    editorControl = streamEditor.createControl(valueController);
    return editorControl;
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent)

Example 7 with DBDContent

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

the class ContentInlineEditor method extractEditorValue.

@Override
public Object extractEditorValue() {
    String newValue = control.getText();
    final DBDContent content = (DBDContent) valueController.getValue();
    assert content != null;
    try {
        if (isText) {
            content.updateContents(VoidProgressMonitor.INSTANCE, new StringContentStorage(newValue));
        } else {
            content.updateContents(VoidProgressMonitor.INSTANCE, new BytesContentStorage(newValue.getBytes(GeneralUtils.getDefaultFileEncoding()), GeneralUtils.getDefaultFileEncoding()));
        }
    } catch (Exception e) {
        log.error(e);
    }
    return content;
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) BytesContentStorage(org.jkiss.dbeaver.model.impl.BytesContentStorage) StringContentStorage(org.jkiss.dbeaver.model.impl.StringContentStorage) DBException(org.jkiss.dbeaver.DBException)

Example 8 with DBDContent

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

the class ContentPanelEditor method primeEditorValue.

@Override
public void primeEditorValue(@Nullable final Object value) throws DBException {
    final DBDContent content = (DBDContent) valueController.getValue();
    if (content == null) {
        valueController.showMessage("NULL content value. Must be DBDContent.", DBPMessageType.ERROR);
        return;
    }
    if (streamEditor == null) {
        valueController.showMessage("NULL content editor.", DBPMessageType.ERROR);
        return;
    }
    DBeaverUI.runInUI(valueController.getValueSite().getWorkbenchWindow(), new DBRRunnableWithProgress() {

        @Override
        public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                streamEditor.primeEditorValue(monitor, control, content);
            } catch (Throwable e) {
                log.debug(e);
                valueController.showMessage(e.getMessage(), DBPMessageType.ERROR);
            }
        }
    });
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with DBDContent

use of org.jkiss.dbeaver.model.data.DBDContent 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 10 with DBDContent

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

the class StreamTransferConsumer method fetchRow.

@Override
public void fetchRow(DBCSession session, DBCResultSet resultSet) throws DBCException {
    try {
        // Get values
        for (int i = 0; i < metaColumns.size(); i++) {
            DBDAttributeBinding column = metaColumns.get(i);
            Object value = column.getValueHandler().fetchValueObject(session, resultSet, column.getAttribute(), column.getOrdinalPosition());
            if (value instanceof DBDContent && !settings.isOutputClipboard()) {
                // Check for binary type export
                if (!ContentUtils.isTextContent((DBDContent) value)) {
                    switch(settings.getLobExtractType()) {
                        case SKIP:
                            // Set it it null
                            value = null;
                            break;
                        case INLINE:
                            // Just pass content to exporter
                            break;
                        case FILES:
                            // Save content to file and pass file reference to exporter
                            value = saveContentToFile(session.getProgressMonitor(), (DBDContent) value);
                            break;
                    }
                }
            }
            row[i] = value;
        }
        // Export row
        processor.exportRow(session, row);
    } catch (DBException e) {
        throw new DBCException("Error while exporting table row", e);
    } catch (IOException e) {
        throw new DBCException("IO error", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Aggregations

DBDContent (org.jkiss.dbeaver.model.data.DBDContent)17 DBDContentStorage (org.jkiss.dbeaver.model.data.DBDContentStorage)7 DBException (org.jkiss.dbeaver.DBException)5 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)4 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)4 File (java.io.File)3 Reader (java.io.Reader)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)3 DBDContentStorageLocal (org.jkiss.dbeaver.model.data.DBDContentStorageLocal)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 StringContentStorage (org.jkiss.dbeaver.model.impl.StringContentStorage)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 Action (org.eclipse.jface.action.Action)1 Separator (org.eclipse.jface.action.Separator)1 Nullable (org.jkiss.code.Nullable)1 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)1