1
1
/**
2
- * Copyright 2010-2018 the original author or authors.
2
+ * Copyright 2010-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -418,59 +418,59 @@ public void afterPropertiesSet() throws Exception {
418
418
*/
419
419
protected SqlSessionFactory buildSqlSessionFactory () throws IOException {
420
420
421
- Configuration configuration ;
421
+ final Configuration targetConfiguration ;
422
422
423
423
XMLConfigBuilder xmlConfigBuilder = null ;
424
424
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 );
428
428
} else if (this .configurationProperties != null ) {
429
- configuration .getVariables ().putAll (this .configurationProperties );
429
+ targetConfiguration .getVariables ().putAll (this .configurationProperties );
430
430
}
431
431
} else if (this .configLocation != null ) {
432
432
xmlConfigBuilder = new XMLConfigBuilder (this .configLocation .getInputStream (), null , this .configurationProperties );
433
- configuration = xmlConfigBuilder .getConfiguration ();
433
+ targetConfiguration = xmlConfigBuilder .getConfiguration ();
434
434
} else {
435
435
LOGGER .debug (() -> "Property 'configuration' or 'configLocation' not specified, using default MyBatis Configuration" );
436
- configuration = new Configuration ();
436
+ targetConfiguration = new Configuration ();
437
437
if (this .configurationProperties != null ) {
438
- configuration .setVariables (this .configurationProperties );
438
+ targetConfiguration .setVariables (this .configurationProperties );
439
439
}
440
440
}
441
441
442
442
if (this .objectFactory != null ) {
443
- configuration .setObjectFactory (this .objectFactory );
443
+ targetConfiguration .setObjectFactory (this .objectFactory );
444
444
}
445
445
446
446
if (this .objectWrapperFactory != null ) {
447
- configuration .setObjectWrapperFactory (this .objectWrapperFactory );
447
+ targetConfiguration .setObjectWrapperFactory (this .objectWrapperFactory );
448
448
}
449
449
450
450
if (this .vfs != null ) {
451
- configuration .setVfsImpl (this .vfs );
451
+ targetConfiguration .setVfsImpl (this .vfs );
452
452
}
453
453
454
454
if (hasLength (this .typeAliasesPackage )) {
455
455
String [] typeAliasPackageArray = tokenizeToStringArray (this .typeAliasesPackage ,
456
456
ConfigurableApplicationContext .CONFIG_LOCATION_DELIMITERS );
457
457
for (String packageToScan : typeAliasPackageArray ) {
458
- configuration .getTypeAliasRegistry ().registerAliases (packageToScan ,
458
+ targetConfiguration .getTypeAliasRegistry ().registerAliases (packageToScan ,
459
459
typeAliasesSuperType == null ? Object .class : typeAliasesSuperType );
460
460
LOGGER .debug (() -> "Scanned package: '" + packageToScan + "' for aliases" );
461
461
}
462
462
}
463
463
464
464
if (!isEmpty (this .typeAliases )) {
465
465
for (Class <?> typeAlias : this .typeAliases ) {
466
- configuration .getTypeAliasRegistry ().registerAlias (typeAlias );
466
+ targetConfiguration .getTypeAliasRegistry ().registerAlias (typeAlias );
467
467
LOGGER .debug (() -> "Registered type alias: '" + typeAlias + "'" );
468
468
}
469
469
}
470
470
471
471
if (!isEmpty (this .plugins )) {
472
472
for (Interceptor plugin : this .plugins ) {
473
- configuration .addInterceptor (plugin );
473
+ targetConfiguration .addInterceptor (plugin );
474
474
LOGGER .debug (() -> "Registered plugin: '" + plugin + "'" );
475
475
}
476
476
}
@@ -479,28 +479,28 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
479
479
String [] typeHandlersPackageArray = tokenizeToStringArray (this .typeHandlersPackage ,
480
480
ConfigurableApplicationContext .CONFIG_LOCATION_DELIMITERS );
481
481
for (String packageToScan : typeHandlersPackageArray ) {
482
- configuration .getTypeHandlerRegistry ().register (packageToScan );
482
+ targetConfiguration .getTypeHandlerRegistry ().register (packageToScan );
483
483
LOGGER .debug (() -> "Scanned package: '" + packageToScan + "' for type handlers" );
484
484
}
485
485
}
486
486
487
487
if (!isEmpty (this .typeHandlers )) {
488
488
for (TypeHandler <?> typeHandler : this .typeHandlers ) {
489
- configuration .getTypeHandlerRegistry ().register (typeHandler );
489
+ targetConfiguration .getTypeHandlerRegistry ().register (typeHandler );
490
490
LOGGER .debug (() -> "Registered type handler: '" + typeHandler + "'" );
491
491
}
492
492
}
493
493
494
494
if (this .databaseIdProvider != null ) {//fix #64 set databaseId before parse mapper xmls
495
495
try {
496
- configuration .setDatabaseId (this .databaseIdProvider .getDatabaseId (this .dataSource ));
496
+ targetConfiguration .setDatabaseId (this .databaseIdProvider .getDatabaseId (this .dataSource ));
497
497
} catch (SQLException e ) {
498
498
throw new NestedIOException ("Failed getting a databaseId" , e );
499
499
}
500
500
}
501
501
502
502
if (this .cache != null ) {
503
- configuration .addCache (this .cache );
503
+ targetConfiguration .addCache (this .cache );
504
504
}
505
505
506
506
if (xmlConfigBuilder != null ) {
@@ -518,7 +518,7 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
518
518
this .transactionFactory = new SpringManagedTransactionFactory ();
519
519
}
520
520
521
- configuration .setEnvironment (new Environment (this .environment , this .transactionFactory , this .dataSource ));
521
+ targetConfiguration .setEnvironment (new Environment (this .environment , this .transactionFactory , this .dataSource ));
522
522
523
523
if (!isEmpty (this .mapperLocations )) {
524
524
for (Resource mapperLocation : this .mapperLocations ) {
@@ -528,7 +528,7 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
528
528
529
529
try {
530
530
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder (mapperLocation .getInputStream (),
531
- configuration , mapperLocation .toString (), configuration .getSqlFragments ());
531
+ targetConfiguration , mapperLocation .toString (), targetConfiguration .getSqlFragments ());
532
532
xmlMapperBuilder .parse ();
533
533
} catch (Exception e ) {
534
534
throw new NestedIOException ("Failed to parse mapping resource: '" + mapperLocation + "'" , e );
@@ -541,7 +541,7 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
541
541
LOGGER .debug (() -> "Property 'mapperLocations' was not specified or no matching resources found" );
542
542
}
543
543
544
- return this .sqlSessionFactoryBuilder .build (configuration );
544
+ return this .sqlSessionFactoryBuilder .build (targetConfiguration );
545
545
}
546
546
547
547
/**
0 commit comments