@@ -28,10 +28,12 @@ import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person
28
28
import org.apache.ibatis.session.ExecutorType
29
29
import org.apache.ibatis.session.SqlSessionFactory
30
30
import org.assertj.core.api.Assertions.assertThat
31
+ import org.assertj.core.api.Assertions.assertThatExceptionOfType
31
32
import org.junit.jupiter.api.BeforeAll
32
33
import org.junit.jupiter.api.Test
33
34
import org.junit.jupiter.api.TestInstance
34
35
import org.junit.jupiter.api.TestInstance.Lifecycle
36
+ import org.mybatis.dynamic.sql.exception.NonRenderingWhereClauseException
35
37
import org.mybatis.dynamic.sql.util.kotlin.elements.add
36
38
import org.mybatis.dynamic.sql.util.kotlin.elements.constant
37
39
import org.mybatis.dynamic.sql.util.kotlin.elements.isIn
@@ -824,4 +826,83 @@ class PersonMapperTest {
824
826
}
825
827
}
826
828
}
829
+
830
+ @Test
831
+ fun testMultiSelectWithNonRenderingWhereClauseDisAllowed () {
832
+ assertThatExceptionOfType(NonRenderingWhereClauseException ::class .java).isThrownBy {
833
+ multiSelect {
834
+ select(id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation, addressId) {
835
+ from(person)
836
+ where { id isLessThanOrEqualTo 2 }
837
+ orderBy(id)
838
+ limit(1 )
839
+ }
840
+ union {
841
+ select(id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation, addressId) {
842
+ from(person)
843
+ where { id isGreaterThanOrEqualToWhenPresent null }
844
+ orderBy(id.descending())
845
+ limit(1 )
846
+ }
847
+ }
848
+ orderBy(sortColumn(" A_ID" ))
849
+ limit(2 )
850
+ offset(1 )
851
+ }
852
+ }
853
+ }
854
+
855
+ @Test
856
+ fun testMultiSelectWithNonRenderingWhereClauseAllowed () {
857
+ val selectStatement = multiSelect {
858
+ select(id, firstName) {
859
+ from(person)
860
+ where { id isLessThanOrEqualTo 2 }
861
+ }
862
+ union {
863
+ select(id, firstName) {
864
+ from(person)
865
+ where { id isGreaterThanOrEqualToWhenPresent null }
866
+ // following should be ignored in favor of the statement configuration...
867
+ configureStatement { isNonRenderingWhereClauseAllowed = false }
868
+ }
869
+ }
870
+ configureStatement { isNonRenderingWhereClauseAllowed = true }
871
+ }
872
+
873
+ val expected = " (select id, first_name from Person where id <= #{parameters.p1,jdbcType=INTEGER}) " +
874
+ " union (select id, first_name from Person)"
875
+ assertThat(selectStatement.selectStatement).isEqualTo(expected)
876
+ }
877
+
878
+ @Test
879
+ fun testInsertSelectWithNonRenderingWhereClauseDisAllowed () {
880
+ assertThatExceptionOfType(NonRenderingWhereClauseException ::class .java).isThrownBy {
881
+ insertSelect {
882
+ into(person)
883
+ select(id, firstName, lastName, birthDate, employed, occupation, addressId) {
884
+ from(person)
885
+ where { id isGreaterThanOrEqualToWhenPresent null }
886
+ }
887
+ }
888
+ }
889
+ }
890
+
891
+ @Test
892
+ fun testInsertSelectWithNonRenderingWhereClauseAllowed () {
893
+ val insertStatement = insertSelect {
894
+ into(person)
895
+ select(id, firstName, lastName, birthDate, employed, occupation, addressId) {
896
+ from(person)
897
+ where { id isGreaterThanOrEqualToWhenPresent null }
898
+ // following should be ignored in favor of the statement configuration...
899
+ configureStatement { isNonRenderingWhereClauseAllowed = false }
900
+ }
901
+ configureStatement { isNonRenderingWhereClauseAllowed = true }
902
+ }
903
+
904
+ val expected = " insert into Person " +
905
+ " select id, first_name, last_name, birth_date, employed, occupation, address_id from Person"
906
+ assertThat(insertStatement.insertStatement).isEqualTo(expected)
907
+ }
827
908
}
0 commit comments