Skip to content

Commit f1f7052

Browse files
committed
Return concrete class as conn duplicate (1.4)
This is a backport of the PR #455 to `v1.4-andium` stable branch. This change makes the `DuckDBConnection#duplicate()` method to return the concrete class instead of the `Connection` interface to not require users to unwrap the result of the call. Fixes: #434
1 parent 9e9bff8 commit f1f7052

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/main/java/org/duckdb/DuckDBConnection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ public Statement createStatement() throws SQLException {
9696
return createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
9797
}
9898

99-
public Connection duplicate() throws SQLException {
99+
public DuckDBConnection duplicate() throws SQLException {
100100
checkOpen();
101101
connRefLock.lock();
102102
try {
103103
checkOpen();
104-
return new DuckDBConnection(DuckDBNative.duckdb_jdbc_connect(connRef), url, readOnly, sessionInitSQL,
105-
autoCommit);
104+
ByteBuffer dupRef = DuckDBNative.duckdb_jdbc_connect(connRef);
105+
return new DuckDBConnection(dupRef, url, readOnly, sessionInitSQL, autoCommit);
106106
} finally {
107107
connRefLock.unlock();
108108
}

src/test/java/org/duckdb/TestResults.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void test_result() throws Exception {
5757
assertFalse(rs.next());
5858
}
5959
// test duplication
60-
try (Connection conn2 = conn.unwrap(DuckDBConnection.class).duplicate();
60+
try (DuckDBConnection conn2 = conn.unwrap(DuckDBConnection.class).duplicate();
6161
Statement stmt2 = conn2.createStatement(); ResultSet rs_conn2 = stmt2.executeQuery("SELECT 42")) {
6262
rs_conn2.next();
6363
assertEquals(42, rs_conn2.getInt(1));

0 commit comments

Comments
 (0)