Skip to content

Commit c834135

Browse files
authored
Merge pull request mybatis#343 from kazuki43zoo/fix-some-sonar-reports
Fix some sonar reports
2 parents 903ec7a + df5b7f4 commit c834135

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

src/main/java/org/mybatis/logging/LoggerFactory.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2017 the original author or authors.
2+
* Copyright 2010-2019 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.
@@ -24,6 +24,10 @@
2424
*/
2525
public class LoggerFactory {
2626

27+
private LoggerFactory() {
28+
// NOP
29+
}
30+
2731
public static Logger getLogger(Class<?> aClass) {
2832
return new Logger(LogFactory.getLog(aClass));
2933
}

src/main/java/org/mybatis/spring/MyBatisSystemException.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2016 the original author or authors.
2+
* Copyright 2010-2019 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.
@@ -27,6 +27,7 @@
2727
*
2828
* @author Hunter Presnall
2929
*/
30+
@SuppressWarnings("squid:MaximumInheritanceDepth") // It is the intended design
3031
public class MyBatisSystemException extends UncategorizedDataAccessException {
3132

3233
private static final long serialVersionUID = -5284728621670758939L;

src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2018 the original author or authors.
2+
* Copyright 2010-2019 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.
@@ -418,59 +418,59 @@ public void afterPropertiesSet() throws Exception {
418418
*/
419419
protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
420420

421-
Configuration configuration;
421+
final Configuration targetConfiguration;
422422

423423
XMLConfigBuilder xmlConfigBuilder = null;
424424
if (this.configuration != null) {
425-
configuration = this.configuration;
426-
if (configuration.getVariables() == null) {
427-
configuration.setVariables(this.configurationProperties);
425+
targetConfiguration = this.configuration;
426+
if (targetConfiguration.getVariables() == null) {
427+
targetConfiguration.setVariables(this.configurationProperties);
428428
} else if (this.configurationProperties != null) {
429-
configuration.getVariables().putAll(this.configurationProperties);
429+
targetConfiguration.getVariables().putAll(this.configurationProperties);
430430
}
431431
} else if (this.configLocation != null) {
432432
xmlConfigBuilder = new XMLConfigBuilder(this.configLocation.getInputStream(), null, this.configurationProperties);
433-
configuration = xmlConfigBuilder.getConfiguration();
433+
targetConfiguration = xmlConfigBuilder.getConfiguration();
434434
} else {
435435
LOGGER.debug(() -> "Property 'configuration' or 'configLocation' not specified, using default MyBatis Configuration");
436-
configuration = new Configuration();
436+
targetConfiguration = new Configuration();
437437
if (this.configurationProperties != null) {
438-
configuration.setVariables(this.configurationProperties);
438+
targetConfiguration.setVariables(this.configurationProperties);
439439
}
440440
}
441441

442442
if (this.objectFactory != null) {
443-
configuration.setObjectFactory(this.objectFactory);
443+
targetConfiguration.setObjectFactory(this.objectFactory);
444444
}
445445

446446
if (this.objectWrapperFactory != null) {
447-
configuration.setObjectWrapperFactory(this.objectWrapperFactory);
447+
targetConfiguration.setObjectWrapperFactory(this.objectWrapperFactory);
448448
}
449449

450450
if (this.vfs != null) {
451-
configuration.setVfsImpl(this.vfs);
451+
targetConfiguration.setVfsImpl(this.vfs);
452452
}
453453

454454
if (hasLength(this.typeAliasesPackage)) {
455455
String[] typeAliasPackageArray = tokenizeToStringArray(this.typeAliasesPackage,
456456
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
457457
for (String packageToScan : typeAliasPackageArray) {
458-
configuration.getTypeAliasRegistry().registerAliases(packageToScan,
458+
targetConfiguration.getTypeAliasRegistry().registerAliases(packageToScan,
459459
typeAliasesSuperType == null ? Object.class : typeAliasesSuperType);
460460
LOGGER.debug(() -> "Scanned package: '" + packageToScan + "' for aliases");
461461
}
462462
}
463463

464464
if (!isEmpty(this.typeAliases)) {
465465
for (Class<?> typeAlias : this.typeAliases) {
466-
configuration.getTypeAliasRegistry().registerAlias(typeAlias);
466+
targetConfiguration.getTypeAliasRegistry().registerAlias(typeAlias);
467467
LOGGER.debug(() -> "Registered type alias: '" + typeAlias + "'");
468468
}
469469
}
470470

471471
if (!isEmpty(this.plugins)) {
472472
for (Interceptor plugin : this.plugins) {
473-
configuration.addInterceptor(plugin);
473+
targetConfiguration.addInterceptor(plugin);
474474
LOGGER.debug(() -> "Registered plugin: '" + plugin + "'");
475475
}
476476
}
@@ -479,28 +479,28 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
479479
String[] typeHandlersPackageArray = tokenizeToStringArray(this.typeHandlersPackage,
480480
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
481481
for (String packageToScan : typeHandlersPackageArray) {
482-
configuration.getTypeHandlerRegistry().register(packageToScan);
482+
targetConfiguration.getTypeHandlerRegistry().register(packageToScan);
483483
LOGGER.debug(() -> "Scanned package: '" + packageToScan + "' for type handlers");
484484
}
485485
}
486486

487487
if (!isEmpty(this.typeHandlers)) {
488488
for (TypeHandler<?> typeHandler : this.typeHandlers) {
489-
configuration.getTypeHandlerRegistry().register(typeHandler);
489+
targetConfiguration.getTypeHandlerRegistry().register(typeHandler);
490490
LOGGER.debug(() -> "Registered type handler: '" + typeHandler + "'");
491491
}
492492
}
493493

494494
if (this.databaseIdProvider != null) {//fix #64 set databaseId before parse mapper xmls
495495
try {
496-
configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
496+
targetConfiguration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
497497
} catch (SQLException e) {
498498
throw new NestedIOException("Failed getting a databaseId", e);
499499
}
500500
}
501501

502502
if (this.cache != null) {
503-
configuration.addCache(this.cache);
503+
targetConfiguration.addCache(this.cache);
504504
}
505505

506506
if (xmlConfigBuilder != null) {
@@ -518,7 +518,7 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
518518
this.transactionFactory = new SpringManagedTransactionFactory();
519519
}
520520

521-
configuration.setEnvironment(new Environment(this.environment, this.transactionFactory, this.dataSource));
521+
targetConfiguration.setEnvironment(new Environment(this.environment, this.transactionFactory, this.dataSource));
522522

523523
if (!isEmpty(this.mapperLocations)) {
524524
for (Resource mapperLocation : this.mapperLocations) {
@@ -528,7 +528,7 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
528528

529529
try {
530530
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
531-
configuration, mapperLocation.toString(), configuration.getSqlFragments());
531+
targetConfiguration, mapperLocation.toString(), targetConfiguration.getSqlFragments());
532532
xmlMapperBuilder.parse();
533533
} catch (Exception e) {
534534
throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
@@ -541,7 +541,7 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
541541
LOGGER.debug(() -> "Property 'mapperLocations' was not specified or no matching resources found");
542542
}
543543

544-
return this.sqlSessionFactoryBuilder.build(configuration);
544+
return this.sqlSessionFactoryBuilder.build(targetConfiguration);
545545
}
546546

547547
/**

0 commit comments

Comments
 (0)