Search in sources :

Example 1 with PostgreDataTypeAttribute

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);
}
Also used : DBException(org.jkiss.dbeaver.DBException) JDBCCompositeStatic(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeStatic) PostgreDataTypeAttribute(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataTypeAttribute) JDBCStructImpl(org.jkiss.dbeaver.model.impl.jdbc.JDBCStructImpl) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) Struct(java.sql.Struct)

Aggregations

Struct (java.sql.Struct)1 DBException (org.jkiss.dbeaver.DBException)1 PostgreDataTypeAttribute (org.jkiss.dbeaver.ext.postgresql.model.PostgreDataTypeAttribute)1 JDBCStructImpl (org.jkiss.dbeaver.model.impl.jdbc.JDBCStructImpl)1 JDBCCompositeStatic (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeStatic)1 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)1