Search in sources :

Example 1 with JDBCReference

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

the class JDBCReferenceValueHandler method bindParameter.

@Override
protected void bindParameter(JDBCSession session, JDBCPreparedStatement statement, DBSTypedObject paramType, int paramIndex, Object value) throws DBCException, SQLException {
    JDBCReference reference = (JDBCReference) value;
    statement.setRef(paramIndex, reference.getValue());
}
Also used : JDBCReference(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCReference)

Example 2 with JDBCReference

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

the class JDBCReferenceValueHandler method getValueFromObject.

@Override
public JDBCReference getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy) throws DBCException {
    String typeName;
    try {
        if (object instanceof Ref) {
            typeName = ((Ref) object).getBaseTypeName();
        } 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.error("Error resolving data type '" + typeName + "'", e);
    }
    if (dataType == null) {
        dataType = new JDBCDataType(session.getDataSource().getContainer(), Types.REF, typeName, "Synthetic struct type for reference '" + typeName + "'", false, false, 0, 0, 0);
    }
    if (object == null) {
        return new JDBCReference(dataType, null);
    } else if (object instanceof JDBCReference) {
        return (JDBCReference) object;
    } else if (object instanceof Ref) {
        return new JDBCReference(dataType, (Ref) object);
    } else {
        throw new DBCException("Unsupported struct type: " + object.getClass().getName());
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) JDBCDataType(org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCDataType) Ref(java.sql.Ref) SQLException(java.sql.SQLException) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) DBCException(org.jkiss.dbeaver.model.exec.DBCException) JDBCReference(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCReference)

Aggregations

JDBCReference (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCReference)2 Ref (java.sql.Ref)1 SQLException (java.sql.SQLException)1 DBException (org.jkiss.dbeaver.DBException)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 JDBCDataType (org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCDataType)1 DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)1