Search in sources :

Example 11 with DBDAttributeBinding

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

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

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

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)

Example 13 with DBDAttributeBinding

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

the class DataExporterHTML method exportRow.

@Override
public void exportRow(DBCSession session, Object[] row) throws DBException, IOException {
    out.write("<tr" + (rowCount++ % 2 == 0 ? " class=\"odd\"" : "") + ">");
    for (int i = 0; i < row.length; i++) {
        DBDAttributeBinding column = columns.get(i);
        if (DBUtils.isNullValue(row[i])) {
            writeTextCell(null, false);
        } else if (row[i] instanceof DBDContent) {
            // Content
            // Inline textual content and handle binaries in some special way
            DBDContent content = (DBDContent) row[i];
            try {
                DBDContentStorage cs = content.getContents(session.getProgressMonitor());
                out.write("<td>");
                if (cs != null) {
                    if (ContentUtils.isTextContent(content)) {
                        writeCellValue(cs.getContentReader());
                    } else {
                        getSite().writeBinaryData(cs);
                    }
                }
                out.write("</td>");
            } finally {
                content.release();
            }
        } else {
            String stringValue = super.getValueDisplayString(column, row[i]);
            boolean isImage = row[i] instanceof File && stringValue != null && stringValue.endsWith(".jpg");
            if (isImage) {
                writeImageCell((File) row[i]);
            } else {
                writeTextCell(stringValue, false);
            }
        }
    }
    out.write("</tr>\n");
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) File(java.io.File) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage)

Example 14 with DBDAttributeBinding

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

the class GISLeafletViewer method saveAttributeSettings.

private void saveAttributeSettings() {
    if (valueController instanceof IAttributeController) {
        DBDAttributeBinding binding = ((IAttributeController) valueController).getBinding();
        if (binding.getEntityAttribute() != null) {
            DBVEntity vEntity = DBVUtils.getVirtualEntity(binding, true);
            DBVEntityAttribute vAttr = vEntity.getVirtualAttribute(binding, true);
            if (vAttr != null) {
                vAttr.setProperty(PROP_FLIP_COORDINATES, String.valueOf(flipCoordinates));
                vAttr.setProperty(PROP_SRID, String.valueOf(getValueSRID()));
            }
            valueController.getExecutionContext().getDataSource().getContainer().getRegistry().flushConfig();
        }
    }
}
Also used : DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) IAttributeController(org.jkiss.dbeaver.ui.data.IAttributeController) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Example 15 with DBDAttributeBinding

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

the class GeometryDataUtils method setGeometryProperties.

public static void setGeometryProperties(IResultSetController controller, GeomAttrs geomAttrs, DBGeometry geometry, ResultSetRow row) {
    // Now extract all geom values from data
    ResultSetModel model = controller.getModel();
    if (row != null) {
        // Now get description
        if (!geomAttrs.descAttrs.isEmpty()) {
            Map<String, Object> properties = new LinkedHashMap<>();
            for (DBDAttributeBinding da : geomAttrs.descAttrs) {
                Object descValue = model.getCellValue(da, row);
                if (!DBUtils.isNullValue(descValue)) {
                    properties.put(da.getName(), descValue);
                }
            }
            geometry.setProperties(properties);
        }
    }
}
Also used : ResultSetModel(org.jkiss.dbeaver.ui.controls.resultset.ResultSetModel) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) LinkedHashMap(java.util.LinkedHashMap)

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