File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
src/test/java/examples/animal/data Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -1825,6 +1825,25 @@ void testAvg() {
1825
1825
}
1826
1826
}
1827
1827
1828
+ @ Test
1829
+ void testDeprecatedAvg () {
1830
+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
1831
+ GeneralMapper mapper = sqlSession .getMapper (GeneralMapper .class );
1832
+
1833
+ SelectStatementProvider selectStatement = select (DeprecatedAverage .of (brainWeight ).as ("average" ))
1834
+ .from (animalData , "a" )
1835
+ .build ()
1836
+ .render (RenderingStrategies .MYBATIS3 );
1837
+
1838
+ Double average = mapper .selectOneDouble (selectStatement );
1839
+
1840
+ assertAll (
1841
+ () -> assertThat (selectStatement .getSelectStatement ()).isEqualTo ("select avg(a.brain_weight) as average from AnimalData a" ),
1842
+ () -> assertThat (average ).isEqualTo (1852.69 , within (.01 ))
1843
+ );
1844
+ }
1845
+ }
1846
+
1828
1847
@ Test
1829
1848
void testSum () {
1830
1849
try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2016-2020 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 examples .animal .data ;
17
+
18
+ import org .mybatis .dynamic .sql .BasicColumn ;
19
+ import org .mybatis .dynamic .sql .select .aggregate .AbstractAggregate ;
20
+
21
+ public class DeprecatedAverage extends AbstractAggregate <DeprecatedAverage > {
22
+ private DeprecatedAverage (BasicColumn column ) {
23
+ super (column );
24
+ }
25
+
26
+ @ Override
27
+ protected String render (String columnName ) {
28
+ return "avg(" + columnName + ")" ; //$NON-NLS-1$ //$NON-NLS-2$
29
+ }
30
+
31
+ @ Override
32
+ protected DeprecatedAverage copy () {
33
+ return new DeprecatedAverage (column );
34
+ }
35
+
36
+ public static DeprecatedAverage of (BasicColumn column ) {
37
+ return new DeprecatedAverage (column );
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments