forked from duckdb/duckdb-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuckDBPendingQuery.java
More file actions
50 lines (45 loc) · 1.4 KB
/
DuckDBPendingQuery.java
File metadata and controls
50 lines (45 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package org.duckdb;
import java.nio.ByteBuffer;
import java.sql.SQLException;
import java.util.concurrent.locks.ReentrantLock;
class DuckDBPendingQuery {
private DuckDBConnection conn;
ByteBuffer pendingRef = null;
final ReentrantLock pendingRefLock = new ReentrantLock();
DuckDBPendingQuery(DuckDBConnection conn, ByteBuffer pendingRef) {
this.conn = conn;
this.pendingRef = pendingRef;
this.conn.connRefLock.lock();
try {
this.conn.pendingQueries.add(this);
} finally {
this.conn.connRefLock.unlock();
}
}
void close() throws SQLException {
if (pendingRef == null) {
return;
}
pendingRefLock.lock();
try {
if (pendingRef == null) {
return;
}
DuckDBNative.duckdb_jdbc_release_pending(pendingRef);
pendingRef = null;
} finally {
pendingRefLock.unlock();
}
// Untrack pending query from parent connection,
// if 'closing' flag is set it means that the parent connection itself
// is being closed and we don't need to untrack this instance
if (!conn.closing) {
conn.connRefLock.lock();
try {
conn.pendingQueries.remove(this);
} finally {
conn.connRefLock.unlock();
}
}
}
}