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