Search in sources :

Example 31 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 32 with DBDContent

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

the class ContentEditorInput method updateContentFromFile.

public void updateContentFromFile(IProgressMonitor monitor) throws DBException {
    if (valueController.isReadOnly()) {
        throw new DBCException("Can't update read-only value");
    }
    DBRProgressMonitor localMonitor = RuntimeUtils.makeMonitor(monitor);
    DBDContent content = getContent();
    DBDContentStorage storage = content.getContents(localMonitor);
    if (storage instanceof DBDContentStorageLocal) {
        // Nothing to update - we user content's storage
        contentDetached = true;
    } else if (storage instanceof DBDContentCached) {
        // Create new storage and pass it to content
        try (FileInputStream is = new FileInputStream(contentFile)) {
            if (storage instanceof StringContentStorage) {
                try (Reader reader = new InputStreamReader(is, fileCharset)) {
                    storage = StringContentStorage.createFromReader(reader);
                }
            } else {
                storage = BytesContentStorage.createFromStream(is, contentFile.length(), fileCharset);
            }
            //StringContentStorage.
            contentDetached = content.updateContents(localMonitor, storage);
        } catch (IOException e) {
            throw new DBException("Error reading content from file", e);
        }
    } else {
        // Create new storage and pass it to content
        storage = new TemporaryContentStorage(DBeaverCore.getInstance(), contentFile, fileCharset);
        contentDetached = content.updateContents(localMonitor, storage);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) TemporaryContentStorage(org.jkiss.dbeaver.model.impl.TemporaryContentStorage) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage) DBDContentCached(org.jkiss.dbeaver.model.data.DBDContentCached) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBDContentStorageLocal(org.jkiss.dbeaver.model.data.DBDContentStorageLocal) StringContentStorage(org.jkiss.dbeaver.model.impl.StringContentStorage)

Example 33 with DBDContent

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

the class ContentEditor method getContent.

@Nullable
DBDContent getContent() {
    IValueController valueController = getValueController();
    Object value = valueController == null ? null : valueController.getValue();
    if (value instanceof DBDContent) {
        return (DBDContent) value;
    } else {
        return null;
    }
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) IValueController(org.jkiss.dbeaver.ui.data.IValueController) Nullable(org.jkiss.code.Nullable)

Example 34 with DBDContent

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

the class ContentEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    setPartName(input.getName());
    DBDContent content = getContent();
    if (content == null) {
        return;
    }
    // Fill nested editorParts info
    IEditorPart[] editorParts = getEditorInput().getEditors();
    for (IEditorPart editorPart : editorParts) {
        contentParts.add(new ContentPartInfo(editorPart, editorPart == getEditorInput().getDefaultEditor()));
    //editorPart.init(site, input);
    }
    ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent)

Example 35 with DBDContent

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

the class ContentEditor method createPages.

@Override
protected void createPages() {
    super.createPages();
    DBDContent content = getContent();
    if (content == null) {
        return;
    }
    ContentPartInfo defaultPage = null;
    for (ContentPartInfo contentPart : contentParts) {
        if (contentPart.isDefault) {
            defaultPage = contentPart;
        }
        IEditorPart editorPart = contentPart.editorPart;
        try {
            int index = addPage(editorPart, getEditorInput());
            setPageText(index, editorPart.getTitle());
            setPageImage(index, editorPart.getTitleImage());
            contentPart.activated = true;
            contentPart.index = index;
        } catch (PartInitException e) {
            log.error(e);
        }
    }
    if (defaultPage != null) {
        setActiveEditor(defaultPage.editorPart);
    }
    this.partsLoaded = true;
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent)

Aggregations

DBDContent (org.jkiss.dbeaver.model.data.DBDContent)52 DBDContentStorage (org.jkiss.dbeaver.model.data.DBDContentStorage)33 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)23 Reader (java.io.Reader)15 DBException (org.jkiss.dbeaver.DBException)13 PrintWriter (java.io.PrintWriter)10 File (java.io.File)9 Date (java.util.Date)8 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)8 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 DBDContentStorageLocal (org.jkiss.dbeaver.model.data.DBDContentStorageLocal)6 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)6 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 DBDContentCached (org.jkiss.dbeaver.model.data.DBDContentCached)4 StringContentStorage (org.jkiss.dbeaver.model.data.storage.StringContentStorage)4 DBCException (org.jkiss.dbeaver.model.exec.DBCException)4