1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-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.
@@ -117,6 +117,7 @@ private void doTestTransactionCommitRestoringAutoCommit(
117
117
if (lazyConnection ) {
118
118
given (con .getAutoCommit ()).willReturn (autoCommit );
119
119
given (con .getTransactionIsolation ()).willReturn (Connection .TRANSACTION_READ_COMMITTED );
120
+ given (con .getWarnings ()).willThrow (new SQLException ());
120
121
}
121
122
122
123
if (!lazyConnection || createStatement ) {
@@ -142,6 +143,10 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run
142
143
if (createStatement ) {
143
144
tCon .createStatement ();
144
145
}
146
+ else {
147
+ tCon .getWarnings ();
148
+ tCon .clearWarnings ();
149
+ }
145
150
}
146
151
catch (SQLException ex ) {
147
152
throw new UncategorizedSQLException ("" , "" , ex );
@@ -209,7 +214,7 @@ private void doTestTransactionRollbackRestoringAutoCommit(
209
214
}
210
215
211
216
final DataSource dsToUse = (lazyConnection ? new LazyConnectionDataSourceProxy (ds ) : ds );
212
- tm = new DataSourceTransactionManager (dsToUse );
217
+ tm = new DataSourceTransactionManager (dsToUse );
213
218
TransactionTemplate tt = new TransactionTemplate (tm );
214
219
assertTrue ("Hasn't thread connection" , !TransactionSynchronizationManager .hasResource (dsToUse ));
215
220
assertTrue ("Synchronization not active" , !TransactionSynchronizationManager .isSynchronizationActive ());
@@ -669,7 +674,6 @@ public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedFailing
669
674
SQLException failure = new SQLException ();
670
675
given (ds2 .getConnection ()).willThrow (failure );
671
676
672
-
673
677
final TransactionTemplate tt = new TransactionTemplate (tm );
674
678
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_REQUIRES_NEW );
675
679
@@ -974,12 +978,12 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
974
978
ordered .verify (con ).setAutoCommit (false );
975
979
ordered .verify (con ).setAutoCommit (true );
976
980
verify (con ).close ();
977
-
978
981
}
979
982
980
983
@ Test
981
984
public void testTransactionAwareDataSourceProxy () throws Exception {
982
985
given (con .getAutoCommit ()).willReturn (true );
986
+ given (con .getWarnings ()).willThrow (new SQLException ());
983
987
984
988
TransactionTemplate tt = new TransactionTemplate (tm );
985
989
assertTrue ("Hasn't thread connection" , !TransactionSynchronizationManager .hasResource (ds ));
@@ -990,6 +994,9 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
990
994
assertEquals (con , DataSourceUtils .getConnection (ds ));
991
995
TransactionAwareDataSourceProxy dsProxy = new TransactionAwareDataSourceProxy (ds );
992
996
try {
997
+ Connection tCon = dsProxy .getConnection ();
998
+ tCon .getWarnings ();
999
+ tCon .clearWarnings ();
993
1000
assertEquals (con , ((ConnectionProxy ) dsProxy .getConnection ()).getTargetConnection ());
994
1001
// should be ignored
995
1002
dsProxy .getConnection ().close ();
@@ -1242,7 +1249,8 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run
1242
1249
assertTrue ("Hasn't thread connection" , !TransactionSynchronizationManager .hasResource (ds ));
1243
1250
}
1244
1251
1245
- @ Test public void testTransactionWithPropagationNotSupported () throws Exception {
1252
+ @ Test
1253
+ public void testTransactionWithPropagationNotSupported () throws Exception {
1246
1254
TransactionTemplate tt = new TransactionTemplate (tm );
1247
1255
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_NOT_SUPPORTED );
1248
1256
assertTrue ("Hasn't thread connection" , !TransactionSynchronizationManager .hasResource (ds ));
0 commit comments