Skip to content

Commit 0015d0d

Browse files
authored
Merge pull request #39 from jeffgbutler/master
Propagate custom parameter name to sub criteria
2 parents c89a1dc + 1dc198b commit 0015d0d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/main/java/org/mybatis/dynamic/sql/where/render/CriterionRenderer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ private <S> FragmentAndParameters renderSubCriterion(SqlCriterion<S> subCriterio
9898
.withSequence(sequence)
9999
.withRenderingStrategy(renderingStrategy)
100100
.withTableAliasCalculator(tableAliasCalculator)
101+
.withParameterName(parameterName)
101102
.build()
102103
.render();
103104
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2016-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.dynamic.sql.where;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.mybatis.dynamic.sql.SqlBuilder.*;
20+
21+
import java.sql.JDBCType;
22+
23+
import org.junit.jupiter.api.Test;
24+
import org.junit.platform.runner.JUnitPlatform;
25+
import org.junit.runner.RunWith;
26+
import org.mybatis.dynamic.sql.SqlColumn;
27+
import org.mybatis.dynamic.sql.SqlTable;
28+
import org.mybatis.dynamic.sql.render.RenderingStrategy;
29+
import org.mybatis.dynamic.sql.where.render.WhereClauseProvider;
30+
31+
@RunWith(JUnitPlatform.class)
32+
public class WhereModelTest {
33+
34+
@Test
35+
public void testThatParameterNameCarriesToSubCriteria() {
36+
SqlTable table = SqlTable.of("foo");
37+
SqlColumn<Integer> id = table.column("id", JDBCType.INTEGER);
38+
39+
WhereClauseProvider wc = where(id, isEqualTo(3), or(id, isEqualTo(4)))
40+
.build()
41+
.render(RenderingStrategy.MYBATIS3, "myName");
42+
43+
assertThat(wc.getWhereClause()).isEqualTo("where (id = #{myName.parameters.p1,jdbcType=INTEGER} or id = #{myName.parameters.p2,jdbcType=INTEGER})");
44+
}
45+
}

0 commit comments

Comments
 (0)