Search in sources :

Example 1 with DBCAttributeMetaData

use of org.jkiss.dbeaver.model.exec.DBCAttributeMetaData in project dbeaver by serge-rider.

the class DBVUtils method readDictionaryRows.

@NotNull
public static List<DBDLabelValuePair> readDictionaryRows(DBCSession session, DBSEntityAttribute valueAttribute, DBDValueHandler valueHandler, DBCResultSet dbResult) throws DBCException {
    List<DBDLabelValuePair> values = new ArrayList<>();
    List<DBCAttributeMetaData> metaColumns = dbResult.getMeta().getAttributes();
    List<DBDValueHandler> colHandlers = new ArrayList<>(metaColumns.size());
    for (DBCAttributeMetaData col : metaColumns) {
        colHandlers.add(DBUtils.findValueHandler(session, col));
    }
    // Extract enumeration values and (optionally) their descriptions
    while (dbResult.nextRow()) {
        // Check monitor
        if (session.getProgressMonitor().isCanceled()) {
            break;
        }
        // Get value and description
        Object keyValue = valueHandler.fetchValueObject(session, dbResult, valueAttribute, 0);
        if (keyValue == null) {
            continue;
        }
        String keyLabel = valueHandler.getValueDisplayString(valueAttribute, keyValue, DBDDisplayFormat.NATIVE);
        if (metaColumns.size() > 1) {
            keyLabel = "";
            for (int i = 1; i < colHandlers.size(); i++) {
                Object descValue = colHandlers.get(i).fetchValueObject(session, dbResult, metaColumns.get(i), i);
                if (!keyLabel.isEmpty()) {
                    keyLabel += " ";
                }
                keyLabel += colHandlers.get(i).getValueDisplayString(metaColumns.get(i), descValue, DBDDisplayFormat.NATIVE);
            }
        }
        values.add(new DBDLabelValuePair(keyLabel, keyValue));
    }
    return values;
}
Also used : DBCAttributeMetaData(org.jkiss.dbeaver.model.exec.DBCAttributeMetaData) ArrayList(java.util.ArrayList) NotNull(org.jkiss.code.NotNull)

Example 2 with DBCAttributeMetaData

use of org.jkiss.dbeaver.model.exec.DBCAttributeMetaData in project dbeaver by serge-rider.

the class ResultSetValueController method getColumnId.

@NotNull
@Override
public String getColumnId() {
    DBCExecutionContext context = getExecutionContext();
    DBCAttributeMetaData metaAttribute = binding.getMetaAttribute();
    return DBUtils.getSimpleQualifiedName(context == null ? null : context.getDataSource().getContainer().getName(), metaAttribute.getEntityName(), metaAttribute.getName());
}
Also used : DBCAttributeMetaData(org.jkiss.dbeaver.model.exec.DBCAttributeMetaData) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) NotNull(org.jkiss.code.NotNull)

Example 3 with DBCAttributeMetaData

use of org.jkiss.dbeaver.model.exec.DBCAttributeMetaData 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)

Aggregations

DBCAttributeMetaData (org.jkiss.dbeaver.model.exec.DBCAttributeMetaData)3 NotNull (org.jkiss.code.NotNull)2 ArrayList (java.util.ArrayList)1 DBException (org.jkiss.dbeaver.DBException)1 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)1