Skip to content

Commit a788a61

Browse files
authored
Merge pull request #1865 from hazendaz/copyright
Various pmd / checkstyle / sonar issues
2 parents a105516 + b18e132 commit a788a61

File tree

9 files changed

+200
-202
lines changed

9 files changed

+200
-202
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
derby.log
1616
/bin/
1717
.mvn/wrapper/maven-wrapper.jar
18+
.sts4-cache/

src/main/java/org/apache/ibatis/binding/MapperMethod.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -325,10 +325,6 @@ public ResultHandler extractResultHandler(Object[] args) {
325325
return hasResultHandler() ? (ResultHandler) args[resultHandlerIndex] : null;
326326
}
327327

328-
public String getMapKey() {
329-
return mapKey;
330-
}
331-
332328
public Class<?> getReturnType() {
333329
return returnType;
334330
}
@@ -373,6 +369,10 @@ private Integer getUniqueParamIndex(Method method, Class<?> paramType) {
373369
return index;
374370
}
375371

372+
public String getMapKey() {
373+
return mapKey;
374+
}
375+
376376
private String getMapKey(Method method) {
377377
String mapKey = null;
378378
if (Map.class.isAssignableFrom(method.getReturnType())) {

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

Lines changed: 104 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,61 @@ public MappedStatement addMappedStatement(
298298
return statement;
299299
}
300300

301+
/**
302+
* Backward compatibility signature 'addMappedStatement'.
303+
*
304+
* @param id
305+
* the id
306+
* @param sqlSource
307+
* the sql source
308+
* @param statementType
309+
* the statement type
310+
* @param sqlCommandType
311+
* the sql command type
312+
* @param fetchSize
313+
* the fetch size
314+
* @param timeout
315+
* the timeout
316+
* @param parameterMap
317+
* the parameter map
318+
* @param parameterType
319+
* the parameter type
320+
* @param resultMap
321+
* the result map
322+
* @param resultType
323+
* the result type
324+
* @param resultSetType
325+
* the result set type
326+
* @param flushCache
327+
* the flush cache
328+
* @param useCache
329+
* the use cache
330+
* @param resultOrdered
331+
* the result ordered
332+
* @param keyGenerator
333+
* the key generator
334+
* @param keyProperty
335+
* the key property
336+
* @param keyColumn
337+
* the key column
338+
* @param databaseId
339+
* the database id
340+
* @param lang
341+
* the lang
342+
* @return the mapped statement
343+
*/
344+
public MappedStatement addMappedStatement(String id, SqlSource sqlSource, StatementType statementType,
345+
SqlCommandType sqlCommandType, Integer fetchSize, Integer timeout, String parameterMap, Class<?> parameterType,
346+
String resultMap, Class<?> resultType, ResultSetType resultSetType, boolean flushCache, boolean useCache,
347+
boolean resultOrdered, KeyGenerator keyGenerator, String keyProperty, String keyColumn, String databaseId,
348+
LanguageDriver lang) {
349+
return addMappedStatement(
350+
id, sqlSource, statementType, sqlCommandType, fetchSize, timeout,
351+
parameterMap, parameterType, resultMap, resultType, resultSetType,
352+
flushCache, useCache, resultOrdered, keyGenerator, keyProperty,
353+
keyColumn, databaseId, lang, null);
354+
}
355+
301356
private <T> T valueOrDefault(T value, T defaultValue) {
302357
return value == null ? defaultValue : value;
303358
}
@@ -391,6 +446,55 @@ public ResultMapping buildResultMapping(
391446
.build();
392447
}
393448

449+
450+
/**
451+
* Backward compatibility signature 'buildResultMapping'.
452+
*
453+
* @param resultType
454+
* the result type
455+
* @param property
456+
* the property
457+
* @param column
458+
* the column
459+
* @param javaType
460+
* the java type
461+
* @param jdbcType
462+
* the jdbc type
463+
* @param nestedSelect
464+
* the nested select
465+
* @param nestedResultMap
466+
* the nested result map
467+
* @param notNullColumn
468+
* the not null column
469+
* @param columnPrefix
470+
* the column prefix
471+
* @param typeHandler
472+
* the type handler
473+
* @param flags
474+
* the flags
475+
* @return the result mapping
476+
*/
477+
public ResultMapping buildResultMapping(Class<?> resultType, String property, String column, Class<?> javaType,
478+
JdbcType jdbcType, String nestedSelect, String nestedResultMap, String notNullColumn, String columnPrefix,
479+
Class<? extends TypeHandler<?>> typeHandler, List<ResultFlag> flags) {
480+
return buildResultMapping(
481+
resultType, property, column, javaType, jdbcType, nestedSelect,
482+
nestedResultMap, notNullColumn, columnPrefix, typeHandler, flags, null, null, configuration.isLazyLoadingEnabled());
483+
}
484+
485+
/**
486+
* Gets the language driver.
487+
*
488+
* @param langClass
489+
* the lang class
490+
* @return the language driver
491+
* @deprecated Use {@link Configuration#getLanguageDriver(Class)}
492+
*/
493+
@Deprecated
494+
public LanguageDriver getLanguageDriver(Class<? extends LanguageDriver> langClass) {
495+
return configuration.getLanguageDriver(langClass);
496+
}
497+
394498
private Set<String> parseMultipleColumnNames(String columnName) {
395499
Set<String> columns = new HashSet<>();
396500
if (columnName != null) {
@@ -454,107 +558,4 @@ private Class<?> resolveParameterJavaType(Class<?> resultType, String property,
454558
return javaType;
455559
}
456560

457-
/**
458-
* Backward compatibility signature 'buildResultMapping'.
459-
*
460-
* @param resultType
461-
* the result type
462-
* @param property
463-
* the property
464-
* @param column
465-
* the column
466-
* @param javaType
467-
* the java type
468-
* @param jdbcType
469-
* the jdbc type
470-
* @param nestedSelect
471-
* the nested select
472-
* @param nestedResultMap
473-
* the nested result map
474-
* @param notNullColumn
475-
* the not null column
476-
* @param columnPrefix
477-
* the column prefix
478-
* @param typeHandler
479-
* the type handler
480-
* @param flags
481-
* the flags
482-
* @return the result mapping
483-
*/
484-
public ResultMapping buildResultMapping(Class<?> resultType, String property, String column, Class<?> javaType,
485-
JdbcType jdbcType, String nestedSelect, String nestedResultMap, String notNullColumn, String columnPrefix,
486-
Class<? extends TypeHandler<?>> typeHandler, List<ResultFlag> flags) {
487-
return buildResultMapping(
488-
resultType, property, column, javaType, jdbcType, nestedSelect,
489-
nestedResultMap, notNullColumn, columnPrefix, typeHandler, flags, null, null, configuration.isLazyLoadingEnabled());
490-
}
491-
492-
/**
493-
* Gets the language driver.
494-
*
495-
* @param langClass
496-
* the lang class
497-
* @return the language driver
498-
* @deprecated Use {@link Configuration#getLanguageDriver(Class)}
499-
*/
500-
@Deprecated
501-
public LanguageDriver getLanguageDriver(Class<? extends LanguageDriver> langClass) {
502-
return configuration.getLanguageDriver(langClass);
503-
}
504-
505-
/**
506-
* Backward compatibility signature 'addMappedStatement'.
507-
*
508-
* @param id
509-
* the id
510-
* @param sqlSource
511-
* the sql source
512-
* @param statementType
513-
* the statement type
514-
* @param sqlCommandType
515-
* the sql command type
516-
* @param fetchSize
517-
* the fetch size
518-
* @param timeout
519-
* the timeout
520-
* @param parameterMap
521-
* the parameter map
522-
* @param parameterType
523-
* the parameter type
524-
* @param resultMap
525-
* the result map
526-
* @param resultType
527-
* the result type
528-
* @param resultSetType
529-
* the result set type
530-
* @param flushCache
531-
* the flush cache
532-
* @param useCache
533-
* the use cache
534-
* @param resultOrdered
535-
* the result ordered
536-
* @param keyGenerator
537-
* the key generator
538-
* @param keyProperty
539-
* the key property
540-
* @param keyColumn
541-
* the key column
542-
* @param databaseId
543-
* the database id
544-
* @param lang
545-
* the lang
546-
* @return the mapped statement
547-
*/
548-
public MappedStatement addMappedStatement(String id, SqlSource sqlSource, StatementType statementType,
549-
SqlCommandType sqlCommandType, Integer fetchSize, Integer timeout, String parameterMap, Class<?> parameterType,
550-
String resultMap, Class<?> resultType, ResultSetType resultSetType, boolean flushCache, boolean useCache,
551-
boolean resultOrdered, KeyGenerator keyGenerator, String keyProperty, String keyColumn, String databaseId,
552-
LanguageDriver lang) {
553-
return addMappedStatement(
554-
id, sqlSource, statementType, sqlCommandType, fetchSize, timeout,
555-
parameterMap, parameterType, resultMap, resultType, resultSetType,
556-
flushCache, useCache, resultOrdered, keyGenerator, keyProperty,
557-
keyColumn, databaseId, lang, null);
558-
}
559-
560561
}

src/main/java/org/apache/ibatis/builder/xml/XMLMapperBuilder.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,11 @@ private ResultMapping buildResultMappingFromContext(XNode context, Class<?> resu
393393
}
394394

395395
private String processNestedResultMappings(XNode context, List<ResultMapping> resultMappings, Class<?> enclosingType) {
396-
if ("association".equals(context.getName())
397-
|| "collection".equals(context.getName())
398-
|| "case".equals(context.getName())) {
399-
if (context.getStringAttribute("select") == null) {
400-
validateCollection(context, enclosingType);
401-
ResultMap resultMap = resultMapElement(context, resultMappings, enclosingType);
402-
return resultMap.getId();
403-
}
396+
if (("association".equals(context.getName()) || "collection".equals(context.getName())
397+
|| "case".equals(context.getName())) && context.getStringAttribute("select") == null) {
398+
validateCollection(context, enclosingType);
399+
ResultMap resultMap = resultMapElement(context, resultMappings, enclosingType);
400+
return resultMap.getId();
404401
}
405402
return null;
406403
}
@@ -426,14 +423,12 @@ private void bindMapperForNamespace() {
426423
} catch (ClassNotFoundException e) {
427424
//ignore, bound type is not required
428425
}
429-
if (boundType != null) {
430-
if (!configuration.hasMapper(boundType)) {
431-
// Spring may not know the real resource name so we set a flag
432-
// to prevent loading again this resource from the mapper interface
433-
// look at MapperAnnotationBuilder#loadXmlResource
434-
configuration.addLoadedResource("namespace:" + namespace);
435-
configuration.addMapper(boundType);
436-
}
426+
if (boundType != null && !configuration.hasMapper(boundType)) {
427+
// Spring may not know the real resource name so we set a flag
428+
// to prevent loading again this resource from the mapper interface
429+
// look at MapperAnnotationBuilder#loadXmlResource
430+
configuration.addLoadedResource("namespace:" + namespace);
431+
configuration.addMapper(boundType);
437432
}
438433
}
439434
}

src/main/java/org/apache/ibatis/datasource/pooled/PooledDataSource.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -536,36 +536,33 @@ protected boolean pingConnection(PooledConnection conn) {
536536
result = false;
537537
}
538538

539-
if (result) {
540-
if (poolPingEnabled) {
541-
if (poolPingConnectionsNotUsedFor >= 0 && conn.getTimeElapsedSinceLastUse() > poolPingConnectionsNotUsedFor) {
542-
try {
543-
if (log.isDebugEnabled()) {
544-
log.debug("Testing connection " + conn.getRealHashCode() + " ...");
545-
}
546-
Connection realConn = conn.getRealConnection();
547-
try (Statement statement = realConn.createStatement()) {
548-
statement.executeQuery(poolPingQuery).close();
549-
}
550-
if (!realConn.getAutoCommit()) {
551-
realConn.rollback();
552-
}
553-
result = true;
554-
if (log.isDebugEnabled()) {
555-
log.debug("Connection " + conn.getRealHashCode() + " is GOOD!");
556-
}
557-
} catch (Exception e) {
558-
log.warn("Execution of ping query '" + poolPingQuery + "' failed: " + e.getMessage());
559-
try {
560-
conn.getRealConnection().close();
561-
} catch (Exception e2) {
562-
//ignore
563-
}
564-
result = false;
565-
if (log.isDebugEnabled()) {
566-
log.debug("Connection " + conn.getRealHashCode() + " is BAD: " + e.getMessage());
567-
}
568-
}
539+
if (result && poolPingEnabled && poolPingConnectionsNotUsedFor >= 0
540+
&& conn.getTimeElapsedSinceLastUse() > poolPingConnectionsNotUsedFor) {
541+
try {
542+
if (log.isDebugEnabled()) {
543+
log.debug("Testing connection " + conn.getRealHashCode() + " ...");
544+
}
545+
Connection realConn = conn.getRealConnection();
546+
try (Statement statement = realConn.createStatement()) {
547+
statement.executeQuery(poolPingQuery).close();
548+
}
549+
if (!realConn.getAutoCommit()) {
550+
realConn.rollback();
551+
}
552+
result = true;
553+
if (log.isDebugEnabled()) {
554+
log.debug("Connection " + conn.getRealHashCode() + " is GOOD!");
555+
}
556+
} catch (Exception e) {
557+
log.warn("Execution of ping query '" + poolPingQuery + "' failed: " + e.getMessage());
558+
try {
559+
conn.getRealConnection().close();
560+
} catch (Exception e2) {
561+
//ignore
562+
}
563+
result = false;
564+
if (log.isDebugEnabled()) {
565+
log.debug("Connection " + conn.getRealHashCode() + " is BAD: " + e.getMessage());
569566
}
570567
}
571568
}

src/main/java/org/apache/ibatis/executor/CachingExecutor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,19 +76,19 @@ public int update(MappedStatement ms, Object parameterObject) throws SQLExceptio
7676
return delegate.update(ms, parameterObject);
7777
}
7878

79+
@Override
80+
public <E> Cursor<E> queryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds) throws SQLException {
81+
flushCacheIfRequired(ms);
82+
return delegate.queryCursor(ms, parameter, rowBounds);
83+
}
84+
7985
@Override
8086
public <E> List<E> query(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException {
8187
BoundSql boundSql = ms.getBoundSql(parameterObject);
8288
CacheKey key = createCacheKey(ms, parameterObject, rowBounds, boundSql);
8389
return query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
8490
}
8591

86-
@Override
87-
public <E> Cursor<E> queryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds) throws SQLException {
88-
flushCacheIfRequired(ms);
89-
return delegate.queryCursor(ms, parameter, rowBounds);
90-
}
91-
9292
@Override
9393
public <E> List<E> query(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql)
9494
throws SQLException {

0 commit comments

Comments
 (0)