Inspired by Jean-Bernard, I came up with this:
public class WhereClause { public HashMap<String, String> queryValues; // [<"foo","bar">, <"baz","taz">] public String preparedString; // "WHERE foo=:foo AND bar=:baz" }
What is connected with the custom BindWhereClause middleware:
@BindingAnnotation(BindWhereClause.WhereClauseBinderFactory.class) @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.PARAMETER}) public @interface BindWhereClause { class WhereClauseBinderFactory implements BinderFactory { public Binder build(Annotation annotation) { return new Binder<BindWhereClause, WhereClause>() { public void bind(SQLStatement q, BindWhereClause bind, WhereClause clause) { clause.queryValues .keySet() .forEach(s -> q.bind(s, clause.queryValues.get(s))); } }; } } }
And the combination of @Define and @Bind :
@UseStringTemplate3StatementLocator public interface ThingDAO { @SqlQuery("SELECT * FROM things <where>) List<Thing> findThingsWhere(@Define("where") String where, @BindWhereClause() WhereClause whereClause); }
This should be proof of injection. (this is?)
source share