use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDataTypeAttribute in project dbeaver by serge-rider.
the class PostgreStructValueHandler method convertStringToStruct.
private JDBCCompositeStatic convertStringToStruct(@NotNull DBCSession session, @NotNull PostgreDataType compType, @NotNull String value) throws DBException {
if (value.startsWith("(") && value.endsWith(")")) {
value = value.substring(1, value.length() - 1);
}
final Collection<PostgreDataTypeAttribute> attributes = compType.getAttributes(session.getProgressMonitor());
if (attributes == null) {
throw new DBException("Composite type '" + compType.getTypeName() + "' has no attributes");
}
String[] parsedValues = PostgreUtils.parseObjectString(value);
if (parsedValues.length != attributes.size()) {
log.debug("Number o attributes (" + attributes.size() + ") doesn't match actual number of parsed strings (" + parsedValues.length + ")");
}
Object[] attrValues = new Object[attributes.size()];
Iterator<PostgreDataTypeAttribute> attrIter = attributes.iterator();
for (int i = 0; i < parsedValues.length && attrIter.hasNext(); i++) {
final PostgreDataTypeAttribute itemAttr = attrIter.next();
attrValues[i] = PostgreUtils.convertStringToValue(itemAttr, parsedValues[i], true);
}
Struct contents = new JDBCStructImpl(compType.getTypeName(), attrValues);
return new JDBCCompositeStatic(session, compType, contents);
}
Aggregations