Hi!
> In ConnectionManagerDataSource, method isWrapperFor currently returns
> false. Perhaps it should throw UnsupportedOperationException instead?
And what about a solution using reflection?
Maybe the most correct solution could be:

    public Object unwrap(Class iface) throws SQLException
    {
        try
        {
            if (iface.isAssignableFrom(dataSource.getClass()))
            {
                return dataSource;
            }

            Method method = dataSource.getClass().getMethod("unwrap",
new Class[]{Class.class});
            return method.invoke(dataSource, new Object[] { iface });
        }
        catch (NoSuchMethodException e)
        {
            throw new UnsupportedOperationException();
        }
        catch (IllegalAccessException e)
        {
            throw new SQLException(e);
        }
        catch (InvocationTargetException e)
        {
            throw new SQLException(e);
        }
    }

    public boolean isWrapperFor(Class iface) throws SQLException
    {
        try
        {
            if (iface.isAssignableFrom(dataSource.getClass()))
            {
                return true;
            }
            Method method =
dataSource.getClass().getMethod("isWrapperFor", new Class[]{Class.class});
            return Boolean.TRUE.equals(method.invoke(dataSource, new
Object[] { iface }));
        }
        catch (NoSuchMethodException e)
        {
            throw new UnsupportedOperationException();
        }
        catch (IllegalAccessException e)
        {
            throw new SQLException(e);
        }
        catch (InvocationTargetException e)
        {
            throw new SQLException(e);
        }
    }

What do you think?
If you don't like it, simply change the "return false" to the Exception
you proposed.

Ciao,
Mario

Reply via email to