Skip to content

Commit a9ec867

Browse files
committed
Fix for Bug#114846 (Bug#36574322), Auto-closeable X dev session.
Change-Id: Iae79e3ddf89daaa68a58d58bfe2a08c801ab377a
1 parent 223dfaf commit a9ec867

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
Version 9.0.0
55

6+
- Fix for Bug#114846 (Bug#36574322), Auto-closeable X dev session.
7+
Thanks to Daniel Kec for his contribution.
8+
69
- Fix for Bug#114989 (Bug#36612566), Setting null value in setClientInfo throws an NPE.
710

811
- WL#16376, Set 'caching_sha2_password' as default fallback authentication plugin.

src/main/user-api/java/com/mysql/cj/xdevapi/Client.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* <p>
2626
* The Client object is obtained via {@link ClientFactory#getClient(String, java.util.Properties)} or {@link ClientFactory#getClient(String, String)} methods.
2727
*/
28-
public interface Client {
28+
public interface Client extends AutoCloseable {
2929

3030
/**
3131
* Get <code>Session</code> from pool or the new one.
@@ -41,6 +41,7 @@ public interface Client {
4141
* Calling the method <code>close</code> on a <code>Client</code>
4242
* object that is already closed is a no-op.
4343
*/
44+
@Override
4445
public void close();
4546

4647
public enum ClientProperty {

src/main/user-api/java/com/mysql/cj/xdevapi/Session.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
* <p>
6666
* Users of the CRUD API do not need to escape identifiers. This is true for working with collections and for working with relational tables.
6767
*/
68-
public interface Session {
68+
public interface Session extends AutoCloseable {
6969

7070
/**
7171
* Retrieve the list of Schema objects for which the current user has access.
@@ -143,6 +143,7 @@ public interface Session {
143143
/**
144144
* Close this session.
145145
*/
146+
@Override
146147
void close();
147148

148149
/**

src/test/java/testsuite/x/devapi/SessionTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,4 +2533,41 @@ public void testBug97269() throws Exception {
25332533
}
25342534
}
25352535

2536+
@Test
2537+
void testAutoCloseableSession() throws Exception {
2538+
final Session testSessionRef;
2539+
2540+
try (Session testSession = this.fact.getSession(this.baseUrl)) {
2541+
assertTrue(testSession.isOpen());
2542+
testSessionRef = testSession;
2543+
}
2544+
2545+
assertNotNull(testSessionRef);
2546+
assertFalse(testSessionRef.isOpen());
2547+
}
2548+
2549+
@Test
2550+
void testAutoCloseableClient() throws Exception {
2551+
final ClientFactory testClientFactory = new ClientFactory();
2552+
final Client testClientRef;
2553+
final Session testSessionRef1;
2554+
final Session testSessionRef2;
2555+
2556+
try (Client testClient = testClientFactory.getClient(this.baseUrl, new Properties())) {
2557+
testSessionRef1 = testClient.getSession();
2558+
assertTrue(testSessionRef1.isOpen());
2559+
testSessionRef2 = testClient.getSession();
2560+
assertTrue(testSessionRef2.isOpen());
2561+
testClientRef = testClient;
2562+
}
2563+
2564+
assertNotNull(testSessionRef1);
2565+
assertFalse(testSessionRef1.isOpen());
2566+
assertNotNull(testSessionRef2);
2567+
assertFalse(testSessionRef2.isOpen());
2568+
2569+
assertNotNull(testClientRef);
2570+
assertThrows(XDevAPIError.class, "Client is closed\\.", testClientRef::getSession);
2571+
}
2572+
25362573
}

0 commit comments

Comments
 (0)