Compare commits

...

3 commits

Author SHA1 Message Date
Gravita
7f6a645dd7 [FIX] Compile fix 2024-06-01 23:16:34 +07:00
luckybl0ck
c6930ded74
[FIX] Set Java distrubution in Actions workflow (#714) 2024-06-01 23:11:50 +07:00
Gravita
c2a6a408c4 [FIX] Hikari getConnection() deadlock when with using user_permissions table 2024-06-01 23:10:56 +07:00
3 changed files with 11 additions and 8 deletions

View file

@ -20,6 +20,7 @@ jobs:
uses: actions/setup-java@v4 uses: actions/setup-java@v4
with: with:
java-version: 21 java-version: 21
distribution: temurin
- name: Grant execute permission for gradlew - name: Grant execute permission for gradlew
run: chmod +x gradlew run: chmod +x gradlew

View file

@ -276,7 +276,7 @@ public void close() {
protected SQLUser constructUser(ResultSet set) throws SQLException { protected SQLUser constructUser(ResultSet set) throws SQLException {
return set.next() ? new SQLUser(UUID.fromString(set.getString(uuidColumn)), set.getString(usernameColumn), return set.next() ? new SQLUser(UUID.fromString(set.getString(uuidColumn)), set.getString(usernameColumn),
set.getString(accessTokenColumn), set.getString(serverIDColumn), set.getString(passwordColumn), requestPermissions(set.getString(uuidColumn))) : null; set.getString(accessTokenColumn), set.getString(serverIDColumn), set.getString(passwordColumn)) : null;
} }
public ClientPermissions requestPermissions (String uuid) throws SQLException public ClientPermissions requestPermissions (String uuid) throws SQLException
@ -286,14 +286,17 @@ public ClientPermissions requestPermissions (String uuid) throws SQLException
} }
private SQLUser queryUser(String sql, String value) throws SQLException { private SQLUser queryUser(String sql, String value) throws SQLException {
SQLUser user;
try (Connection c = getSQLConfig().getConnection()) { try (Connection c = getSQLConfig().getConnection()) {
PreparedStatement s = c.prepareStatement(sql); PreparedStatement s = c.prepareStatement(sql);
s.setString(1, value); s.setString(1, value);
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
try (ResultSet set = s.executeQuery()) { try (ResultSet set = s.executeQuery()) {
return constructUser(set); user = constructUser(set);
} }
} }
user.permissions = requestPermissions(user.uuid.toString());
return user;
} }
private List<String> queryPermissions(String sql, String value) throws SQLException { private List<String> queryPermissions(String sql, String value) throws SQLException {
@ -340,15 +343,14 @@ public static class SQLUser implements User {
protected String accessToken; protected String accessToken;
protected String serverId; protected String serverId;
protected final String password; protected final String password;
protected final ClientPermissions permissions; protected ClientPermissions permissions;
public SQLUser(UUID uuid, String username, String accessToken, String serverId, String password, ClientPermissions permissions) { public SQLUser(UUID uuid, String username, String accessToken, String serverId, String password) {
this.uuid = uuid; this.uuid = uuid;
this.username = username; this.username = username;
this.accessToken = accessToken; this.accessToken = accessToken;
this.serverId = serverId; this.serverId = serverId;
this.password = password; this.password = password;
this.permissions = permissions;
} }
@Override @Override

View file

@ -72,7 +72,7 @@ protected String makeUserCols() {
@Override @Override
protected MySQLUser constructUser(ResultSet set) throws SQLException { protected MySQLUser constructUser(ResultSet set) throws SQLException {
return set.next() ? new MySQLUser(UUID.fromString(set.getString(uuidColumn)), set.getString(usernameColumn), return set.next() ? new MySQLUser(UUID.fromString(set.getString(uuidColumn)), set.getString(usernameColumn),
set.getString(accessTokenColumn), set.getString(serverIDColumn), set.getString(passwordColumn), requestPermissions(set.getString(uuidColumn)), set.getLong(hardwareIdColumn)) : null; set.getString(accessTokenColumn), set.getString(serverIDColumn), set.getString(passwordColumn), set.getLong(hardwareIdColumn)) : null;
} }
private MySQLUserHardware fetchHardwareInfo(ResultSet set) throws SQLException, IOException { private MySQLUserHardware fetchHardwareInfo(ResultSet set) throws SQLException, IOException {
@ -336,8 +336,8 @@ public String toString() {
public static class MySQLUser extends SQLUser { public static class MySQLUser extends SQLUser {
protected long hwidId; protected long hwidId;
public MySQLUser(UUID uuid, String username, String accessToken, String serverId, String password, ClientPermissions permissions, long hwidId) { public MySQLUser(UUID uuid, String username, String accessToken, String serverId, String password, long hwidId) {
super(uuid, username, accessToken, serverId, password, permissions); super(uuid, username, accessToken, serverId, password);
this.hwidId = hwidId; this.hwidId = hwidId;
} }