Search in sources :

Example 1 with JDBCCompositeUnknown

use of org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeUnknown in project dbeaver by serge-rider.

the class JDBCStructValueHandler method getValueFromObject.

@Override
public Object getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy) throws DBCException {
    String typeName;
    try {
        if (object instanceof Struct) {
            typeName = ((Struct) object).getSQLTypeName();
        } else {
            typeName = type.getTypeName();
        }
    } catch (SQLException e) {
        throw new DBCException(e, session.getDataSource());
    }
    DBSDataType dataType = null;
    try {
        dataType = DBUtils.resolveDataType(session.getProgressMonitor(), session.getDataSource(), typeName);
    } catch (DBException e) {
        log.debug("Error resolving data type '" + typeName + "'", e);
    }
    if (dataType == null) {
        if (object instanceof Struct) {
            return new JDBCCompositeDynamic(session, (Struct) object, null);
        } else {
            return new JDBCCompositeUnknown(session, object);
        }
    }
    if (object == null) {
        return new JDBCCompositeStatic(session, dataType, new JDBCStructImpl(dataType.getTypeName(), null));
    } else if (object instanceof JDBCCompositeStatic) {
        return copy ? ((JDBCCompositeStatic) object).cloneValue(session.getProgressMonitor()) : object;
    } else if (object instanceof Struct) {
        return new JDBCCompositeStatic(session, dataType, (Struct) object);
    } else {
        return new JDBCCompositeUnknown(session, object);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) JDBCCompositeStatic(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeStatic) SQLException(java.sql.SQLException) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) JDBCCompositeDynamic(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeDynamic) JDBCStructImpl(org.jkiss.dbeaver.model.impl.jdbc.JDBCStructImpl) JDBCCompositeUnknown(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeUnknown) DBCException(org.jkiss.dbeaver.model.exec.DBCException) Struct(java.sql.Struct)

Aggregations

SQLException (java.sql.SQLException)1 Struct (java.sql.Struct)1 DBException (org.jkiss.dbeaver.DBException)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 JDBCStructImpl (org.jkiss.dbeaver.model.impl.jdbc.JDBCStructImpl)1 JDBCCompositeDynamic (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeDynamic)1 JDBCCompositeStatic (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeStatic)1 JDBCCompositeUnknown (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeUnknown)1 DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)1