@@ -767,6 +767,36 @@ void testStringConstant() {
767767 }
768768 }
769769
770+ @ Test
771+ void testDeprecatedAdd () {
772+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
773+ AnimalDataMapper mapper = sqlSession .getMapper (AnimalDataMapper .class );
774+
775+ SelectStatementProvider selectStatement = select (id , animalName , DeprecatedAdd .of (bodyWeight , brainWeight ).as ("calculated_weight" ))
776+ .from (animalData , "a" )
777+ .where (DeprecatedAdd .of (bodyWeight , brainWeight ), isGreaterThan (10000.0 ))
778+ .build ()
779+ .render (RenderingStrategies .MYBATIS3 );
780+
781+ String expected = "select a.id, a.animal_name, (a.body_weight + a.brain_weight) as calculated_weight "
782+ + "from AnimalData a "
783+ + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}" ;
784+
785+ List <Map <String , Object >> animals = mapper .generalSelect (selectStatement );
786+
787+ assertAll (
788+ () -> assertThat (selectStatement .getSelectStatement ()).isEqualTo (expected ),
789+ () -> assertThat (animals ).hasSize (3 ),
790+ () -> assertThat (animals .get (0 )).containsEntry ("ANIMAL_NAME" , "African elephant" ),
791+ () -> assertThat (animals .get (0 )).containsEntry ("CALCULATED_WEIGHT" , 12366.0 ),
792+ () -> assertThat (animals .get (1 )).containsEntry ("ANIMAL_NAME" , "Dipliodocus" ),
793+ () -> assertThat (animals .get (1 )).containsEntry ("CALCULATED_WEIGHT" , 11750.0 ),
794+ () -> assertThat (animals .get (2 )).containsEntry ("ANIMAL_NAME" , "Brachiosaurus" ),
795+ () -> assertThat (animals .get (2 )).containsEntry ("CALCULATED_WEIGHT" , 87154.5 )
796+ );
797+ }
798+ }
799+
770800 @ Test
771801 void testAdd () {
772802 try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
@@ -827,6 +857,36 @@ void testAddConstant() {
827857 }
828858 }
829859
860+ @ Test
861+ void testAddConstantWithConstantFirst () {
862+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
863+ AnimalDataMapper mapper = sqlSession .getMapper (AnimalDataMapper .class );
864+
865+ SelectStatementProvider selectStatement = select (id , animalName , add (constant ("22" ), bodyWeight , constant ("33" )).as ("calculated_weight" ))
866+ .from (animalData , "a" )
867+ .where (add (bodyWeight , brainWeight ), isGreaterThan (10000.0 ))
868+ .build ()
869+ .render (RenderingStrategies .MYBATIS3 );
870+
871+ String expected = "select a.id, a.animal_name, (22 + a.body_weight + 33) as calculated_weight "
872+ + "from AnimalData a "
873+ + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}" ;
874+
875+ List <Map <String , Object >> animals = mapper .generalSelect (selectStatement );
876+
877+ assertAll (
878+ () -> assertThat (selectStatement .getSelectStatement ()).isEqualTo (expected ),
879+ () -> assertThat (animals ).hasSize (3 ),
880+ () -> assertThat (animals .get (0 )).containsEntry ("ANIMAL_NAME" , "African elephant" ),
881+ () -> assertThat (animals .get (0 )).containsEntry ("CALCULATED_WEIGHT" , 5767.0 ),
882+ () -> assertThat (animals .get (1 )).containsEntry ("ANIMAL_NAME" , "Dipliodocus" ),
883+ () -> assertThat (animals .get (1 )).containsEntry ("CALCULATED_WEIGHT" , 105.0 ),
884+ () -> assertThat (animals .get (2 )).containsEntry ("ANIMAL_NAME" , "Brachiosaurus" ),
885+ () -> assertThat (animals .get (2 )).containsEntry ("CALCULATED_WEIGHT" , 209.5 )
886+ );
887+ }
888+ }
889+
830890 @ Test
831891 void testConcatenate () {
832892 try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
@@ -854,6 +914,33 @@ void testConcatenate() {
854914 }
855915 }
856916
917+ @ Test
918+ void testConcatenateConstantFirst () {
919+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
920+ AnimalDataMapper mapper = sqlSession .getMapper (AnimalDataMapper .class );
921+
922+ SelectStatementProvider selectStatement = select (id , concatenate (stringConstant ("Name: " ), animalName ).as ("display_name" ))
923+ .from (animalData , "a" )
924+ .where (add (bodyWeight , brainWeight ), isGreaterThan (10000.0 ))
925+ .build ()
926+ .render (RenderingStrategies .MYBATIS3 );
927+
928+ String expected = "select a.id, ('Name: ' || a.animal_name) as display_name "
929+ + "from AnimalData a "
930+ + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}" ;
931+
932+ List <Map <String , Object >> animals = mapper .generalSelect (selectStatement );
933+
934+ assertAll (
935+ () -> assertThat (selectStatement .getSelectStatement ()).isEqualTo (expected ),
936+ () -> assertThat (animals ).hasSize (3 ),
937+ () -> assertThat (animals .get (0 )).containsEntry ("DISPLAY_NAME" , "Name: African elephant" ),
938+ () -> assertThat (animals .get (1 )).containsEntry ("DISPLAY_NAME" , "Name: Dipliodocus" ),
939+ () -> assertThat (animals .get (2 )).containsEntry ("DISPLAY_NAME" , "Name: Brachiosaurus" )
940+ );
941+ }
942+ }
943+
857944 @ Test
858945 void testDivide () {
859946 try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
@@ -1034,6 +1121,36 @@ void testSubtractConstant() {
10341121 }
10351122 }
10361123
1124+ @ Test
1125+ void testGeneralOperator () {
1126+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
1127+ AnimalDataMapper mapper = sqlSession .getMapper (AnimalDataMapper .class );
1128+
1129+ SelectStatementProvider selectStatement = select (id , animalName , applyOperator ("-" , bodyWeight , brainWeight ).as ("calculated_weight" ))
1130+ .from (animalData , "a" )
1131+ .where (add (bodyWeight , brainWeight ), isGreaterThan (10000.0 ))
1132+ .build ()
1133+ .render (RenderingStrategies .MYBATIS3 );
1134+
1135+ String expected = "select a.id, a.animal_name, (a.body_weight - a.brain_weight) as calculated_weight "
1136+ + "from AnimalData a "
1137+ + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}" ;
1138+
1139+ List <Map <String , Object >> animals = mapper .generalSelect (selectStatement );
1140+
1141+ assertAll (
1142+ () -> assertThat (selectStatement .getSelectStatement ()).isEqualTo (expected ),
1143+ () -> assertThat (animals ).hasSize (3 ),
1144+ () -> assertThat (animals .get (0 )).containsEntry ("ANIMAL_NAME" , "African elephant" ),
1145+ () -> assertThat (animals .get (0 )).containsEntry ("CALCULATED_WEIGHT" , -942.0 ),
1146+ () -> assertThat (animals .get (1 )).containsEntry ("ANIMAL_NAME" , "Dipliodocus" ),
1147+ () -> assertThat (animals .get (1 )).containsEntry ("CALCULATED_WEIGHT" , -11650.0 ),
1148+ () -> assertThat (animals .get (2 )).containsEntry ("ANIMAL_NAME" , "Brachiosaurus" ),
1149+ () -> assertThat (animals .get (2 )).containsEntry ("CALCULATED_WEIGHT" , -86845.5 )
1150+ );
1151+ }
1152+ }
1153+
10371154 @ Test
10381155 void testComplexExpression () {
10391156 try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
0 commit comments