forked from xerial/sqlite-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBusyHandler.java
More file actions
64 lines (55 loc) · 2.04 KB
/
Copy pathBusyHandler.java
File metadata and controls
64 lines (55 loc) · 2.04 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.sqlite;
import java.sql.Connection;
import java.sql.SQLException;
/** https://www.sqlite.org/c3ref/busy_handler.html */
public abstract class BusyHandler {
/**
* commit the busy handler for the connection.
*
* @param conn the SQLite connection
* @param busyHandler the busyHandler
* @throws SQLException
*/
private static void commitHandler(Connection conn, BusyHandler busyHandler)
throws SQLException {
if (conn == null || !(conn instanceof SQLiteConnection)) {
throw new SQLException("connection must be to an SQLite db");
}
if (conn.isClosed()) {
throw new SQLException("connection closed");
}
SQLiteConnection sqliteConnection = (SQLiteConnection) conn;
sqliteConnection.getDatabase().busy_handler(busyHandler);
}
/**
* Sets a busy handler for the connection.
*
* @param conn the SQLite connection
* @param busyHandler the busyHandler
* @throws SQLException
*/
public static final void setHandler(Connection conn, BusyHandler busyHandler)
throws SQLException {
commitHandler(conn, busyHandler);
}
/**
* Clears any busy handler registered with the connection.
*
* @param conn the SQLite connection
* @throws SQLException
*/
public static final void clearHandler(Connection conn) throws SQLException {
commitHandler(conn, null);
}
/**
* https://www.sqlite.org/c3ref/busy_handler.html
*
* @param nbPrevInvok number of times that the busy handler has been invoked previously for the
* same locking event
* @throws SQLException
* @return If the busy callback returns 0, then no additional attempts are made to access the
* database and SQLITE_BUSY is returned to the application. If the callback returns
* non-zero, then another attempt is made to access the database and the cycle repeats.
*/
protected abstract int callback(int nbPrevInvok) throws SQLException;
}