use of org.springframework.r2dbc.core.binding.BindTarget in project spring-framework by spring-projects.
the class NamedParameterUtilsUnitTests method multipleEqualCollectionParameterReferencesBindsValueOnce.
@Test
public void multipleEqualCollectionParameterReferencesBindsValueOnce() {
String sql = "SELECT * FROM person where name IN (:ids) or lastname IN (:ids)";
BindMarkersFactory factory = BindMarkersFactory.indexed("$", 0);
MultiValueMap<Integer, Object> bindings = new LinkedMultiValueMap<>();
PreparedOperation<String> operation = NamedParameterUtils.substituteNamedParameters(sql, factory, new MapBindParameterSource(Collections.singletonMap("ids", Parameter.from(Arrays.asList("foo", "bar", "baz")))));
assertThat(operation.toQuery()).isEqualTo("SELECT * FROM person where name IN ($0, $1, $2) or lastname IN ($0, $1, $2)");
operation.bindTo(new BindTarget() {
@Override
public void bind(String identifier, Object value) {
throw new UnsupportedOperationException();
}
@Override
public void bind(int index, Object value) {
assertThat(index).isIn(0, 1, 2);
assertThat(value).isIn("foo", "bar", "baz");
bindings.add(index, value);
}
@Override
public void bindNull(String identifier, Class<?> type) {
throw new UnsupportedOperationException();
}
@Override
public void bindNull(int index, Class<?> type) {
throw new UnsupportedOperationException();
}
});
//
assertThat(bindings).containsEntry(0, Collections.singletonList("foo")).containsEntry(1, //
Collections.singletonList("bar")).containsEntry(2, Collections.singletonList("baz"));
}
Aggregations