Search in sources :

Example 1 with DBSTypedObjectEx

use of org.jkiss.dbeaver.model.struct.DBSTypedObjectEx in project dbeaver by serge-rider.

the class ArrayAttributeTransformer method transformAttribute.

@Override
public void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows, @NotNull Map<String, String> options) throws DBException {
    DBSDataType collectionType;
    if (attribute.getAttribute() instanceof DBSTypedObjectEx) {
        collectionType = ((DBSTypedObjectEx) attribute.getAttribute()).getDataType();
    } else {
        collectionType = DBUtils.resolveDataType(session.getProgressMonitor(), session.getDataSource(), attribute.getTypeName());
    }
    if (collectionType != null) {
        DBSDataType componentType = collectionType.getComponentType(session.getProgressMonitor());
        if (componentType instanceof DBSEntity) {
            ComplexTypeAttributeTransformer.createNestedTypeBindings(session, attribute, rows, (DBSEntity) componentType);
            return;
        }
    }
    // No component type found.
    // Array items should be resolved in a lazy mode
    MapAttributeTransformer.resolveMapsFromData(session, attribute, rows);
}
Also used : DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) DBSTypedObjectEx(org.jkiss.dbeaver.model.struct.DBSTypedObjectEx) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity)

Example 2 with DBSTypedObjectEx

use of org.jkiss.dbeaver.model.struct.DBSTypedObjectEx in project dbeaver by serge-rider.

the class JDBCCollection method makeCollectionFromArray.

/////////////////////////////////////////////////////////////////////////////////////
// Utilities
/////////////////////////////////////////////////////////////////////////////////////
@NotNull
public static JDBCCollection makeCollectionFromArray(@NotNull JDBCSession session, @NotNull DBSTypedObject column, Array array) throws DBCException {
    DBRProgressMonitor monitor = session.getProgressMonitor();
    DBSDataType elementType = null;
    if (column instanceof DBSTypedObjectEx) {
        DBSDataType arrayType = ((DBSTypedObjectEx) column).getDataType();
        if (arrayType != null) {
            elementType = arrayType.getComponentType(monitor);
        }
    }
    if (elementType == null) {
        try {
            if (array == null) {
                String arrayTypeName = column.getTypeName();
                DBSDataType arrayType = session.getDataSource().resolveDataType(monitor, arrayTypeName);
                if (arrayType != null) {
                    elementType = arrayType.getComponentType(monitor);
                }
            } else {
                String baseTypeName = array.getBaseTypeName();
                elementType = session.getDataSource().resolveDataType(monitor, baseTypeName);
            }
        } catch (Exception e) {
            throw new DBCException("Error resolving data type", e);
        }
    }
    try {
        if (elementType == null) {
            if (array == null) {
                throw new DBCException("Can't resolve NULL array data type");
            }
            try {
                return makeCollectionFromResultSet(session, array, null);
            } catch (SQLException e) {
                //$NON-NLS-1$
                throw new DBCException(e, session.getDataSource());
            }
        }
        try {
            return makeCollectionFromArray(session, array, elementType);
        } catch (SQLException e) {
            if (array == null) {
                //$NON-NLS-1$
                throw new DBCException(e, session.getDataSource());
            }
            try {
                return makeCollectionFromResultSet(session, array, elementType);
            } catch (SQLException e1) {
                //$NON-NLS-1$
                throw new DBCException(e1, session.getDataSource());
            }
        }
    } catch (DBException e) {
        //$NON-NLS-1$
        throw new DBCException("Can't extract array data from JDBC array", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) SQLException(java.sql.SQLException) DBSTypedObjectEx(org.jkiss.dbeaver.model.struct.DBSTypedObjectEx) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) DBException(org.jkiss.dbeaver.DBException) NotNull(org.jkiss.code.NotNull)

Aggregations

DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)2 DBSTypedObjectEx (org.jkiss.dbeaver.model.struct.DBSTypedObjectEx)2 SQLException (java.sql.SQLException)1 NotNull (org.jkiss.code.NotNull)1 DBException (org.jkiss.dbeaver.DBException)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)1