Re: [jdbi] Introduce @BindMap, binds Map entries as statement parameters (#70)

463 views
Skip to first unread message

Henning Schmiedehausen

unread,
Sep 10, 2013, 12:28:55 PM9/10/13
to brianm/jdbi, Brian McCallister

In src/main/java/org/skife/jdbi/v2/sqlobject/BindMapFactory.java:

> +                        if (allowedKeys.isEmpty() || allowedKeys.remove(key)) {
> +                            q.bind(prefix + key, e.getValue());
> +                        }
> +                    }
> +
> +                    // Any leftover keys were specified but not found in the map, so bind as null
> +                    for (String key : allowedKeys) {
> +                        final Object val = map.get(key);
> +                        if (val != null) {
> +                            throw new IllegalStateException("Internal error: map iteration missed key " + key);
> +                        }
> +                        q.bind(prefix + key, val);
> +                    }
> +                }
> +                catch (Exception e) {
> +                    throw new IllegalStateException("Unable to bind map properties", e);

rethrow the IllegalArgumentException you got from above (better yet, rethrow all RuntimeExceptions without wrapping).


Reply to this email directly or view it on GitHub.

Henning Schmiedehausen

unread,
Sep 10, 2013, 12:29:27 PM9/10/13
to brianm/jdbi, Brian McCallister

In src/main/java/org/skife/jdbi/v2/sqlobject/BindMapFactory.java:

> +class BindMapFactory implements BinderFactory
> +{
> +    @Override
> +    public Binder build(Annotation annotation)
> +    {
> +        return new Binder<BindMap, Object>()
> +        {
> +            @Override
> +            public void bind(SQLStatement q, BindMap bind, Object arg)
> +            {
> +                final String prefix;
> +                if (BindBean.BARE_BINDING.equals(bind.prefix())) {
> +                    prefix = "";
> +                }
> +                else {
> +                    prefix = bind.prefix() + ".";

possible NPE if bind is null. (if not here, then two lines down at the bind.value())

Christopher Currie

unread,
Nov 25, 2014, 2:28:27 PM11/25/14
to brianm/jdbi, Brian McCallister

Any chance this will get fixed up and merged?

Reply all
Reply to author
Forward
0 new messages