Search in sources :

Example 1 with DBDCollection

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

the class PostgreArrayValueHandler method getValueDisplayString.

@NotNull
@Override
public String getValueDisplayString(@NotNull DBSTypedObject column, Object value, @NotNull DBDDisplayFormat format) {
    DBDCollection collection = (DBDCollection) value;
    if (!DBUtils.isNullValue(value)) {
        DBDValueHandler valueHandler = collection.getComponentValueHandler();
        StringBuilder str = new StringBuilder();
        str.append("{");
        for (int i = 0; i < collection.getItemCount(); i++) {
            if (i > 0) {
                //$NON-NLS-1$
                str.append(',');
            }
            final Object item = collection.getItem(i);
            String itemString;
            if (item instanceof JDBCCollection) {
                // Multi-dimensional arrays case
                itemString = getValueDisplayString(column, item, format);
            } else {
                itemString = valueHandler.getValueDisplayString(collection.getComponentType(), item, DBDDisplayFormat.NATIVE);
            }
            str.append(itemString);
        }
        str.append("}");
        return str.toString();
    }
    return super.getValueDisplayString(column, value, format);
}
Also used : JDBCCollection(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection) DBDCollection(org.jkiss.dbeaver.model.data.DBDCollection) DBDValueHandler(org.jkiss.dbeaver.model.data.DBDValueHandler) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) NotNull(org.jkiss.code.NotNull)

Example 2 with DBDCollection

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

the class PostgreArrayValueHandler method getValueDisplayString.

@NotNull
@Override
public String getValueDisplayString(@NotNull DBSTypedObject column, Object value, @NotNull DBDDisplayFormat format) {
    DBDCollection collection = (DBDCollection) value;
    if (!DBUtils.isNullValue(value)) {
        DBDValueHandler valueHandler = collection.getComponentValueHandler();
        StringBuilder str = new StringBuilder();
        if (format == DBDDisplayFormat.NATIVE) {
            str.append("'");
        }
        str.append("{");
        for (int i = 0; i < collection.getItemCount(); i++) {
            if (i > 0) {
                // $NON-NLS-1$
                str.append(',');
            }
            final Object item = collection.getItem(i);
            String itemString;
            if (item instanceof JDBCCollection) {
                // Multi-dimensional arrays case
                itemString = getValueDisplayString(column, item, format);
            } else {
                itemString = valueHandler.getValueDisplayString(collection.getComponentType(), item, DBDDisplayFormat.NATIVE);
            }
            str.append(itemString);
        }
        str.append("}");
        if (format == DBDDisplayFormat.NATIVE) {
            str.append("'");
        }
        return str.toString();
    }
    return super.getValueDisplayString(column, value, format);
}
Also used : JDBCCollection(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection) DBDCollection(org.jkiss.dbeaver.model.data.DBDCollection) DBDValueHandler(org.jkiss.dbeaver.model.data.DBDValueHandler) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) NotNull(org.jkiss.code.NotNull)

Example 3 with DBDCollection

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

the class PostgreArrayValueHandler method convertArrayToString.

private String convertArrayToString(@NotNull DBSTypedObject column, Object value, @NotNull DBDDisplayFormat format, boolean nested) {
    if (!DBUtils.isNullValue(value) && value instanceof DBDCollection) {
        DBDCollection collection = (DBDCollection) value;
        boolean isNativeFormat = format == DBDDisplayFormat.NATIVE;
        boolean isStringArray = collection.getComponentType().getDataKind() == DBPDataKind.STRING;
        DBDValueHandler valueHandler = collection.getComponentValueHandler();
        StringBuilder str = new StringBuilder();
        if (isNativeFormat && !nested) {
            str.append("'");
        }
        str.append("{");
        for (int i = 0; i < collection.getItemCount(); i++) {
            if (i > 0) {
                // $NON-NLS-1$
                str.append(',');
            }
            final Object item = collection.getItem(i);
            String itemString;
            if (item instanceof JDBCCollection) {
                // Multi-dimensional arrays case
                itemString = convertArrayToString(column, item, format, true);
            } else {
                itemString = valueHandler.getValueDisplayString(collection.getComponentType(), item, format);
            }
            if (isNativeFormat) {
                if (item instanceof String)
                    str.append('"');
                str.append(SQLUtils.escapeString(collection.getComponentType().getDataSource(), itemString));
                if (item instanceof String)
                    str.append('"');
            } else {
                str.append(itemString);
            }
        }
        str.append("}");
        if (isNativeFormat && !nested) {
            str.append("'");
        }
        return str.toString();
    }
    return super.getValueDisplayString(column, value, format);
}
Also used : JDBCCollection(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection) DBDCollection(org.jkiss.dbeaver.model.data.DBDCollection) DBDValueHandler(org.jkiss.dbeaver.model.data.DBDValueHandler) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject)

Aggregations

DBDCollection (org.jkiss.dbeaver.model.data.DBDCollection)3 DBDValueHandler (org.jkiss.dbeaver.model.data.DBDValueHandler)3 JDBCCollection (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection)3 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)3 NotNull (org.jkiss.code.NotNull)2