@@ -857,6 +857,7 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run
857
857
public void testTransactionWithIsolationAndReadOnly () throws Exception {
858
858
given (con .getTransactionIsolation ()).willReturn (Connection .TRANSACTION_READ_COMMITTED );
859
859
given (con .getAutoCommit ()).willReturn (true );
860
+ given (con .isReadOnly ()).willReturn (true );
860
861
861
862
TransactionTemplate tt = new TransactionTemplate (tm );
862
863
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_REQUIRES_NEW );
@@ -874,11 +875,13 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
874
875
875
876
assertTrue ("Hasn't thread connection" , !TransactionSynchronizationManager .hasResource (ds ));
876
877
InOrder ordered = inOrder (con );
878
+ ordered .verify (con ).setReadOnly (true );
877
879
ordered .verify (con ).setTransactionIsolation (Connection .TRANSACTION_SERIALIZABLE );
878
880
ordered .verify (con ).setAutoCommit (false );
879
881
ordered .verify (con ).commit ();
880
882
ordered .verify (con ).setAutoCommit (true );
881
883
ordered .verify (con ).setTransactionIsolation (Connection .TRANSACTION_READ_COMMITTED );
884
+ ordered .verify (con ).setReadOnly (false );
882
885
verify (con ).close ();
883
886
}
884
887
@@ -889,6 +892,7 @@ public void testTransactionWithEnforceReadOnly() throws Exception {
889
892
given (con .getAutoCommit ()).willReturn (true );
890
893
Statement stmt = mock (Statement .class );
891
894
given (con .createStatement ()).willReturn (stmt );
895
+ given (con .isReadOnly ()).willReturn (true );
892
896
893
897
TransactionTemplate tt = new TransactionTemplate (tm );
894
898
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_REQUIRES_NEW );
@@ -905,11 +909,13 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
905
909
906
910
assertTrue ("Hasn't thread connection" , !TransactionSynchronizationManager .hasResource (ds ));
907
911
InOrder ordered = inOrder (con , stmt );
912
+ ordered .verify (con ).setReadOnly (true );
908
913
ordered .verify (con ).setAutoCommit (false );
909
914
ordered .verify (stmt ).executeUpdate ("SET TRANSACTION READ ONLY" );
910
915
ordered .verify (stmt ).close ();
911
916
ordered .verify (con ).commit ();
912
917
ordered .verify (con ).setAutoCommit (true );
918
+ ordered .verify (con ).setReadOnly (false );
913
919
ordered .verify (con ).close ();
914
920
}
915
921
0 commit comments