Search in sources :

Example 1 with Pair

use of org.jkiss.utils.Pair in project dbeaver by serge-rider.

the class MapAttributeTransformer method resolveMapsFromData.

static void resolveMapsFromData(DBCSession session, DBDAttributeBinding attribute, List<Object[]> rows) throws DBException {
    // Analyse rows and extract meta information from values
    List<Pair<DBSAttributeBase, Object[]>> valueAttributes = null;
    for (int i = 0; i < rows.size(); i++) {
        Object value = rows.get(i)[attribute.getOrdinalPosition()];
        if (value instanceof DBDCollection) {
            // Use first element to discover structure
            DBDCollection collection = (DBDCollection) value;
            if (collection.getItemCount() > 0) {
                value = collection.getItem(0);
            }
        }
        if (value instanceof DBDComposite) {
            DBSAttributeBase[] attributes = ((DBDComposite) value).getAttributes();
            for (DBSAttributeBase attr : attributes) {
                Pair<DBSAttributeBase, Object[]> attrValue = null;
                if (valueAttributes != null) {
                    for (Pair<DBSAttributeBase, Object[]> pair : valueAttributes) {
                        if (pair.getFirst().getName().equals(attr.getName())) {
                            attrValue = pair;
                            break;
                        }
                    }
                }
                if (attrValue != null) {
                    // Update attr value
                    attrValue.getSecond()[i] = ((DBDComposite) value).getAttributeValue(attr);
                } else {
                    Object[] valueList = new Object[rows.size()];
                    valueList[i] = ((DBDComposite) value).getAttributeValue(attr);
                    if (valueAttributes == null) {
                        valueAttributes = new ArrayList<>();
                    }
                    valueAttributes.add(new Pair<>(attr, valueList));
                }
            }
        }
    }
    if (valueAttributes != null && !valueAttributes.isEmpty()) {
        createNestedMapBindings(session, attribute, valueAttributes);
    }
}
Also used : DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) Pair(org.jkiss.utils.Pair)

Aggregations

DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)1 Pair (org.jkiss.utils.Pair)1