Skip to content

Commit 032335b

Browse files
authored
Merge pull request #2798 from hazendaz/formatting
[ci] formatting
2 parents a0f8d36 + 233a4b8 commit 032335b

35 files changed

+879
-763
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ Essentials
2121
* [See the docs](https://mybatis.org/mybatis-3)
2222
* [Download Latest](https://github.com/mybatis/mybatis-3/releases)
2323
* [Download Snapshot](https://oss.sonatype.org/content/repositories/snapshots/org/mybatis/mybatis/)
24+
25+
Contributions
26+
-------------
27+
28+
Mybatis-core is now being auto formatted. Given nature of some code logic with mybatis, it is more appropriate to force a formatting structure manually for snippets such as sql statements. To do so, add following blocks around code.
29+
30+
```// @formatter:off``` to start the block of unformatted code
31+
```// @formatter:off``` to end the block of unformatted code
32+
33+
If comment sections need same behaviour such as javadocs, note that the entire block must be around entire comment as direct usage does not properly indicate that formatter treats it all as one comment block regardless.

format.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2009-2023 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
https://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<!DOCTYPE Format>
20+
<Format>
21+
<!-- Dummy format file -->
22+
</Format>

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,13 @@
447447
</testExcludes>
448448
</configuration>
449449
</plugin>
450+
<plugin>
451+
<groupId>net.revelc.code</groupId>
452+
<artifactId>impsort-maven-plugin</artifactId>
453+
<configuration>
454+
<skip>true</skip>
455+
</configuration>
456+
</plugin>
450457
</plugins>
451458
</pluginManagement>
452459
</build>

src/main/java/org/apache/ibatis/annotations/SelectProvider.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
* Specify a type that implements an SQL provider method.
6666
* <p>
6767
* This attribute is alias of {@link #value()}.
68-
* </p>
6968
*
7069
* @return a type that implements an SQL provider method
7170
*
@@ -77,18 +76,24 @@
7776
* Specify a method for providing an SQL.
7877
* <p>
7978
* Since 3.5.1, this attribute can omit.
79+
* <p>
8080
* If this attribute omit, the MyBatis will call a method that decide by following rules.
81+
*
82+
* <pre>
8183
* <ul>
8284
* <li>
8385
* If class that specified the {@link #type()} attribute implements the
8486
* {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver},
85-
* the MyBatis use a method that returned by it
87+
* the MyBatis use a method that returned by it.
8688
* </li>
8789
* <li>
88-
* If cannot resolve a method by {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver}(= not implement it or it was returned {@code null}),
89-
* the MyBatis will search and use a fallback method that named {@code provideSql} from specified type
90+
* If cannot resolve a method by {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver}
91+
* (= not implement it or it was returned <code>null</code>,
92+
* the MyBatis will search and use a fallback method that named <code>provideSql</code> from
93+
* specified type.
9094
* </li>
9195
* </ul>
96+
* </pre>
9297
*
9398
* @return a method name of method for providing an SQL
9499
*/

src/main/java/org/apache/ibatis/annotations/TypeDiscriminator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.ibatis.type.TypeHandler;
2626
import org.apache.ibatis.type.UnknownTypeHandler;
2727

28+
// @formatter:off
2829
/**
2930
* The annotation that be grouping conditional mapping definitions.
3031
* <p>
@@ -48,6 +49,7 @@
4849
*
4950
* @author Clinton Begin
5051
*/
52+
// @formatter:on
5153
@Documented
5254
@Retention(RetentionPolicy.RUNTIME)
5355
@Target(ElementType.METHOD)

src/main/java/org/apache/ibatis/annotations/UpdateProvider.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,21 @@
7878
* <p>
7979
* Since 3.5.1, this attribute can omit. If this attribute omit, the MyBatis will call a method that decide by
8080
* following rules.
81+
*
82+
* <pre>
8183
* <ul>
8284
* <li>
8385
* If class that specified the {@link #type()} attribute implements the
8486
* {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver},
8587
* the MyBatis use a method that returned by it
8688
* </li>
8789
* <li>
88-
* If cannot resolve a method by {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver}(= not implement it or it was returned {@code null}),
89-
* the MyBatis will search and use a fallback method that named {@code provideSql} from specified type
90+
* If cannot resolve a method by {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver}
91+
* (= not implement it or it was returned <code>null</code>,
92+
* the MyBatis will search and use a fallback method that named <code>provideSql</code> from specified type
9093
* </li>
9194
* </ul>
95+
* </pre>
9296
*
9397
* @return a method name of method for providing an SQL
9498
*/

src/main/java/org/apache/ibatis/builder/MapperBuilderAssistant.java

Lines changed: 30 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,11 @@ public Cache useCacheRef(String namespace) {
121121
}
122122
}
123123

124-
public Cache useNewCache(Class<? extends Cache> typeClass,
125-
Class<? extends Cache> evictionClass,
126-
Long flushInterval,
127-
Integer size,
128-
boolean readWrite,
129-
boolean blocking,
130-
Properties props) {
131-
Cache cache = new CacheBuilder(currentNamespace)
132-
.implementation(valueOrDefault(typeClass, PerpetualCache.class))
133-
.addDecorator(valueOrDefault(evictionClass, LruCache.class))
134-
.clearInterval(flushInterval)
135-
.size(size)
136-
.readWrite(readWrite)
137-
.blocking(blocking)
138-
.properties(props)
139-
.build();
124+
public Cache useNewCache(Class<? extends Cache> typeClass, Class<? extends Cache> evictionClass, Long flushInterval,
125+
Integer size, boolean readWrite, boolean blocking, Properties props) {
126+
Cache cache = new CacheBuilder(currentNamespace).implementation(valueOrDefault(typeClass, PerpetualCache.class))
127+
.addDecorator(valueOrDefault(evictionClass, LruCache.class)).clearInterval(flushInterval).size(size)
128+
.readWrite(readWrite).blocking(blocking).properties(props).build();
140129
configuration.addCache(cache);
141130
currentCache = cache;
142131
return cache;
@@ -149,37 +138,21 @@ public ParameterMap addParameterMap(String id, Class<?> parameterClass, List<Par
149138
return parameterMap;
150139
}
151140

152-
public ParameterMapping buildParameterMapping(
153-
Class<?> parameterType,
154-
String property,
155-
Class<?> javaType,
156-
JdbcType jdbcType,
157-
String resultMap,
158-
ParameterMode parameterMode,
159-
Class<? extends TypeHandler<?>> typeHandler,
141+
public ParameterMapping buildParameterMapping(Class<?> parameterType, String property, Class<?> javaType,
142+
JdbcType jdbcType, String resultMap, ParameterMode parameterMode, Class<? extends TypeHandler<?>> typeHandler,
160143
Integer numericScale) {
161144
resultMap = applyCurrentNamespace(resultMap, true);
162145

163146
// Class parameterType = parameterMapBuilder.type();
164147
Class<?> javaTypeClass = resolveParameterJavaType(parameterType, property, javaType, jdbcType);
165148
TypeHandler<?> typeHandlerInstance = resolveTypeHandler(javaTypeClass, typeHandler);
166149

167-
return new ParameterMapping.Builder(configuration, property, javaTypeClass)
168-
.jdbcType(jdbcType)
169-
.resultMapId(resultMap)
170-
.mode(parameterMode)
171-
.numericScale(numericScale)
172-
.typeHandler(typeHandlerInstance)
173-
.build();
150+
return new ParameterMapping.Builder(configuration, property, javaTypeClass).jdbcType(jdbcType)
151+
.resultMapId(resultMap).mode(parameterMode).numericScale(numericScale).typeHandler(typeHandlerInstance).build();
174152
}
175153

176-
public ResultMap addResultMap(
177-
String id,
178-
Class<?> type,
179-
String extend,
180-
Discriminator discriminator,
181-
List<ResultMapping> resultMappings,
182-
Boolean autoMapping) {
154+
public ResultMap addResultMap(String id, Class<?> type, String extend, Discriminator discriminator,
155+
List<ResultMapping> resultMappings, Boolean autoMapping) {
183156
id = applyCurrentNamespace(id, false);
184157
extend = applyCurrentNamespace(extend, true);
185158

@@ -209,28 +182,10 @@ public ResultMap addResultMap(
209182
return resultMap;
210183
}
211184

212-
public Discriminator buildDiscriminator(
213-
Class<?> resultType,
214-
String column,
215-
Class<?> javaType,
216-
JdbcType jdbcType,
217-
Class<? extends TypeHandler<?>> typeHandler,
218-
Map<String, String> discriminatorMap) {
219-
ResultMapping resultMapping = buildResultMapping(
220-
resultType,
221-
null,
222-
column,
223-
javaType,
224-
jdbcType,
225-
null,
226-
null,
227-
null,
228-
null,
229-
typeHandler,
230-
new ArrayList<>(),
231-
null,
232-
null,
233-
false);
185+
public Discriminator buildDiscriminator(Class<?> resultType, String column, Class<?> javaType, JdbcType jdbcType,
186+
Class<? extends TypeHandler<?>> typeHandler, Map<String, String> discriminatorMap) {
187+
ResultMapping resultMapping = buildResultMapping(resultType, null, column, javaType, jdbcType, null, null, null,
188+
null, typeHandler, new ArrayList<>(), null, null, false);
234189
Map<String, String> namespaceDiscriminatorMap = new HashMap<>();
235190
for (Map.Entry<String, String> e : discriminatorMap.entrySet()) {
236191
String resultMap = e.getValue();
@@ -240,28 +195,11 @@ public Discriminator buildDiscriminator(
240195
return new Discriminator.Builder(configuration, resultMapping, namespaceDiscriminatorMap).build();
241196
}
242197

243-
public MappedStatement addMappedStatement(
244-
String id,
245-
SqlSource sqlSource,
246-
StatementType statementType,
247-
SqlCommandType sqlCommandType,
248-
Integer fetchSize,
249-
Integer timeout,
250-
String parameterMap,
251-
Class<?> parameterType,
252-
String resultMap,
253-
Class<?> resultType,
254-
ResultSetType resultSetType,
255-
boolean flushCache,
256-
boolean useCache,
257-
boolean resultOrdered,
258-
KeyGenerator keyGenerator,
259-
String keyProperty,
260-
String keyColumn,
261-
String databaseId,
262-
LanguageDriver lang,
263-
String resultSets,
264-
boolean dirtySelect) {
198+
public MappedStatement addMappedStatement(String id, SqlSource sqlSource, StatementType statementType,
199+
SqlCommandType sqlCommandType, Integer fetchSize, Integer timeout, String parameterMap, Class<?> parameterType,
200+
String resultMap, Class<?> resultType, ResultSetType resultSetType, boolean flushCache, boolean useCache,
201+
boolean resultOrdered, KeyGenerator keyGenerator, String keyProperty, String keyColumn, String databaseId,
202+
LanguageDriver lang, String resultSets, boolean dirtySelect) {
265203

266204
if (unresolvedCacheRef) {
267205
throw new IncompleteElementException("Cache-ref not yet resolved");
@@ -270,23 +208,11 @@ public MappedStatement addMappedStatement(
270208
id = applyCurrentNamespace(id, false);
271209

272210
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType)
273-
.resource(resource)
274-
.fetchSize(fetchSize)
275-
.timeout(timeout)
276-
.statementType(statementType)
277-
.keyGenerator(keyGenerator)
278-
.keyProperty(keyProperty)
279-
.keyColumn(keyColumn)
280-
.databaseId(databaseId)
281-
.lang(lang)
282-
.resultOrdered(resultOrdered)
283-
.resultSets(resultSets)
284-
.resultMaps(getStatementResultMaps(resultMap, resultType, id))
285-
.resultSetType(resultSetType)
286-
.flushCacheRequired(flushCache)
287-
.useCache(useCache)
288-
.cache(currentCache)
289-
.dirtySelect(dirtySelect);
211+
.resource(resource).fetchSize(fetchSize).timeout(timeout).statementType(statementType)
212+
.keyGenerator(keyGenerator).keyProperty(keyProperty).keyColumn(keyColumn).databaseId(databaseId).lang(lang)
213+
.resultOrdered(resultOrdered).resultSets(resultSets)
214+
.resultMaps(getStatementResultMaps(resultMap, resultType, id)).resultSetType(resultSetType)
215+
.flushCacheRequired(flushCache).useCache(useCache).cache(currentCache).dirtySelect(dirtySelect);
290216

291217
ParameterMap statementParameterMap = getStatementParameterMap(parameterMap, parameterType, id);
292218
if (statementParameterMap != null) {
@@ -418,19 +344,12 @@ public ResultMapping buildResultMapping(Class<?> resultType, String property, St
418344
} else {
419345
composites = parseCompositeColumnName(column);
420346
}
421-
return new ResultMapping.Builder(configuration, property, column, javaTypeClass)
422-
.jdbcType(jdbcType)
347+
return new ResultMapping.Builder(configuration, property, column, javaTypeClass).jdbcType(jdbcType)
423348
.nestedQueryId(applyCurrentNamespace(nestedSelect, true))
424-
.nestedResultMapId(applyCurrentNamespace(nestedResultMap, true))
425-
.resultSet(resultSet)
426-
.typeHandler(typeHandlerInstance)
427-
.flags(flags == null ? new ArrayList<>() : flags)
428-
.composites(composites)
429-
.notNullColumns(parseMultipleColumnNames(notNullColumn))
430-
.columnPrefix(columnPrefix)
431-
.foreignColumn(foreignColumn)
432-
.lazy(lazy)
433-
.build();
349+
.nestedResultMapId(applyCurrentNamespace(nestedResultMap, true)).resultSet(resultSet)
350+
.typeHandler(typeHandlerInstance).flags(flags == null ? new ArrayList<>() : flags).composites(composites)
351+
.notNullColumns(parseMultipleColumnNames(notNullColumn)).columnPrefix(columnPrefix).foreignColumn(foreignColumn)
352+
.lazy(lazy).build();
434353
}
435354

436355
/**

0 commit comments

Comments
 (0)