Search in sources :

Example 1 with JDBCComposite

use of org.jkiss.dbeaver.model.impl.jdbc.data.JDBCComposite in project dbeaver by dbeaver.

the class PostgreStructValueHandler method bindParameter.

@Override
protected void bindParameter(JDBCSession session, JDBCPreparedStatement statement, DBSTypedObject paramType, int paramIndex, Object value) throws DBCException, SQLException {
    if (value == null) {
        statement.setNull(paramIndex, Types.STRUCT);
    } else if (value instanceof DBDComposite) {
        DBDComposite struct = (DBDComposite) value;
        if (struct.isNull()) {
            statement.setNull(paramIndex, Types.STRUCT);
        } else if (struct instanceof JDBCComposite) {
            final Object[] values = ((JDBCComposite) struct).getValues();
            final String string = PostgreValueParser.generateObjectString(values);
            statement.setObject(paramIndex, string, Types.OTHER);
        }
    } else {
        throw new DBCException("Struct parameter type '" + value.getClass().getName() + "' not supported");
    }
}
Also used : DBDComposite(org.jkiss.dbeaver.model.data.DBDComposite) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBCException(org.jkiss.dbeaver.model.exec.DBCException) JDBCComposite(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCComposite)

Example 2 with JDBCComposite

use of org.jkiss.dbeaver.model.impl.jdbc.data.JDBCComposite in project dbeaver by dbeaver.

the class JDBCStructValueHandler method getValueFromObject.

@Override
public Object getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy, boolean validateValue) throws DBCException {
    if (object instanceof JDBCComposite) {
        return copy ? ((JDBCComposite) object).cloneValue(session.getProgressMonitor()) : object;
    }
    String typeName;
    try {
        if (object instanceof Struct) {
            typeName = ((Struct) object).getSQLTypeName();
        } else {
            typeName = type.getTypeName();
        }
    } catch (SQLException e) {
        throw new DBCException(e, session.getExecutionContext());
    }
    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 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) JDBCComposite(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCComposite) Struct(java.sql.Struct)

Example 3 with JDBCComposite

use of org.jkiss.dbeaver.model.impl.jdbc.data.JDBCComposite 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, boolean validateValue) throws DBCException {
    if (object instanceof JDBCComposite) {
        return copy ? ((JDBCComposite) object).cloneValue(session.getProgressMonitor()) : object;
    }
    String typeName;
    try {
        if (object instanceof Struct) {
            typeName = ((Struct) object).getSQLTypeName();
        } else {
            typeName = type.getTypeName();
        }
    } catch (SQLException e) {
        throw new DBCException(e, session.getExecutionContext());
    }
    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 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) JDBCComposite(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCComposite) Struct(java.sql.Struct)

Example 4 with JDBCComposite

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

the class PostgreStructValueHandler method bindParameter.

@Override
protected void bindParameter(JDBCSession session, JDBCPreparedStatement statement, DBSTypedObject paramType, int paramIndex, Object value) throws DBCException, SQLException {
    if (value == null) {
        statement.setNull(paramIndex, Types.STRUCT);
    } else if (value instanceof DBDComposite) {
        DBDComposite struct = (DBDComposite) value;
        if (struct.isNull()) {
            statement.setNull(paramIndex, Types.STRUCT);
        } else if (struct instanceof JDBCComposite) {
            final Object[] values = ((JDBCComposite) struct).getValues();
            final String string = PostgreValueParser.generateObjectString(values);
            statement.setObject(paramIndex, string, Types.OTHER);
        }
    } else {
        throw new DBCException("Struct parameter type '" + value.getClass().getName() + "' not supported");
    }
}
Also used : DBDComposite(org.jkiss.dbeaver.model.data.DBDComposite) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBCException(org.jkiss.dbeaver.model.exec.DBCException) JDBCComposite(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCComposite)

Aggregations

DBCException (org.jkiss.dbeaver.model.exec.DBCException)4 JDBCComposite (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCComposite)4 SQLException (java.sql.SQLException)2 Struct (java.sql.Struct)2 DBException (org.jkiss.dbeaver.DBException)2 DBDComposite (org.jkiss.dbeaver.model.data.DBDComposite)2 JDBCStructImpl (org.jkiss.dbeaver.model.impl.jdbc.JDBCStructImpl)2 JDBCCompositeDynamic (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeDynamic)2 JDBCCompositeStatic (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeStatic)2 JDBCCompositeUnknown (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCompositeUnknown)2 DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)2 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)2