@@ -69,7 +69,7 @@ public void tearDown() throws Exception {
69
69
* Run a test with the default (auto-commit on) for sanity.
70
70
*/
71
71
@ Test
72
- void autoCommitOn () throws SQLException , IOException {
72
+ void autoCommitOn () throws SQLException {
73
73
try (RelationalConnection connection = DriverManager .getConnection (getTestDbUri ()).unwrap (RelationalConnection .class )) {
74
74
try (RelationalStatement statement = connection .createStatement ()) {
75
75
insertOneRow (statement );
@@ -80,6 +80,65 @@ void autoCommitOn() throws SQLException, IOException {
80
80
}
81
81
}
82
82
83
+ @ Test
84
+ void autoCommitWithNoTransactionInBetween () throws SQLException {
85
+ try (RelationalConnection connection = DriverManager .getConnection (getTestDbUri ()).unwrap (RelationalConnection .class )) {
86
+ connection .setAutoCommit (false );
87
+ connection .setAutoCommit (true );
88
+ }
89
+ }
90
+
91
+ @ Test
92
+ void autoCommitStayOn () throws SQLException {
93
+ try (RelationalConnection connection = DriverManager .getConnection (getTestDbUri ()).unwrap (RelationalConnection .class )) {
94
+ connection .setAutoCommit (true );
95
+ }
96
+ }
97
+
98
+ @ Test
99
+ void autoCommitStayOff () throws SQLException {
100
+ try (RelationalConnection connection = DriverManager .getConnection (getTestDbUri ()).unwrap (RelationalConnection .class )) {
101
+ connection .setAutoCommit (false );
102
+ connection .setAutoCommit (false );
103
+ }
104
+ }
105
+
106
+ @ Test
107
+ void commitEnableAutoCommit () throws SQLException {
108
+ try (RelationalConnection connection = DriverManager .getConnection (getTestDbUri ()).unwrap (RelationalConnection .class )) {
109
+ connection .setAutoCommit (false );
110
+
111
+ try (RelationalStatement statement = connection .createStatement ()) {
112
+ insertOneRow (statement );
113
+ }
114
+ connection .commit ();
115
+ connection .setAutoCommit (true );
116
+ try (RelationalStatement statement = connection .createStatement ()) {
117
+ RelationalResultSet resultSet = statement .executeQuery ("SELECT * FROM test_table" );
118
+ assertNextResult (resultSet , 100 , "one hundred" );
119
+ assertNoNextResult (resultSet );
120
+ }
121
+ }
122
+ }
123
+
124
+ @ Test
125
+ void rollbackThenEnableAutoCommit () throws SQLException {
126
+ try (RelationalConnection connection = DriverManager .getConnection (getTestDbUri ()).unwrap (RelationalConnection .class )) {
127
+ connection .setAutoCommit (false );
128
+
129
+ try (RelationalStatement statement = connection .createStatement ()) {
130
+ insertOneRow (statement );
131
+ }
132
+ connection .rollback ();
133
+ connection .setAutoCommit (true );
134
+ try (RelationalStatement statement = connection .createStatement ()) {
135
+ RelationalResultSet resultSet = statement .executeQuery ("SELECT * FROM test_table" );
136
+ assertNoNextResult (resultSet );
137
+ assertNoNextResult (resultSet );
138
+ }
139
+ }
140
+ }
141
+
83
142
/**
84
143
* Run a test with commit and then read.
85
144
*/
0 commit comments