Search in sources :

Example 1 with PostgreDataType

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDataType in project dbeaver by serge-rider.

the class PostgreArrayValueHandler method getValueFromObject.

@Override
public DBDCollection getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy) throws DBCException {
    if (object != null) {
        String className = object.getClass().getName();
        if (object instanceof String || className.equals(PostgreConstants.PG_OBJECT_CLASS)) {
            PostgreDataType itemType = null;
            final PostgreDataType arrayType = PostgreUtils.findDataType((PostgreDataSource) session.getDataSource(), type);
            if (arrayType != null) {
                itemType = arrayType.getElementType();
            }
            if (itemType != null) {
                if (className.equals(PostgreConstants.PG_OBJECT_CLASS)) {
                    final Object value = PostgreUtils.extractPGObjectValue(object);
                    if (value == null) {
                        return null;
                    } else if (value instanceof String) {
                        return convertStringToArray(session, itemType, (String) value);
                    } else {
                        // Can't parse
                        return new JDBCCollection(itemType, DBUtils.findValueHandler(session, itemType), new Object[] { value });
                    }
                } else if (object instanceof String) {
                    return convertStringToArray(session, itemType, (String) object);
                }
            }
        }
    }
    return super.getValueFromObject(session, type, object, copy);
}
Also used : JDBCCollection(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection) PostgreDataType(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataType) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject)

Aggregations

PostgreDataType (org.jkiss.dbeaver.ext.postgresql.model.PostgreDataType)1 JDBCCollection (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection)1 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)1