|
16 | 16 | */ |
17 | 17 | package com.djrapitops.plan.storage.database.transactions.events; |
18 | 18 |
|
| 19 | +import com.djrapitops.plan.exceptions.database.DBOpException; |
19 | 20 | import com.djrapitops.plan.identification.ServerUUID; |
20 | 21 | import com.djrapitops.plan.storage.database.sql.tables.AllowlistBounceTable; |
21 | 22 | import com.djrapitops.plan.storage.database.transactions.ExecStatement; |
@@ -48,25 +49,41 @@ public StoreAllowlistBounceTransaction(UUID playerUUID, @Untrusted String player |
48 | 49 |
|
49 | 50 | @Override |
50 | 51 | protected void performOperations() { |
51 | | - boolean updated = execute(new ExecStatement(AllowlistBounceTable.INCREMENT_TIMES_STATEMENT) { |
| 52 | + boolean updated = update(); |
| 53 | + if (!updated) { |
| 54 | + try { |
| 55 | + insert(); |
| 56 | + } catch (DBOpException e) { |
| 57 | + if (e.isDuplicateKeyViolation()) { |
| 58 | + update(); |
| 59 | + return; |
| 60 | + } |
| 61 | + throw e; |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + private void insert() { |
| 67 | + execute(new ExecStatement(AllowlistBounceTable.INSERT_STATEMENT) { |
| 68 | + @Override |
| 69 | + public void prepare(PreparedStatement statement) throws SQLException { |
| 70 | + statement.setString(1, playerUUID.toString()); |
| 71 | + statement.setString(2, playerName); |
| 72 | + statement.setString(3, serverUUID.toString()); |
| 73 | + statement.setInt(4, 1); |
| 74 | + statement.setLong(5, time); |
| 75 | + } |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + private boolean update() { |
| 80 | + return execute(new ExecStatement(AllowlistBounceTable.INCREMENT_TIMES_STATEMENT) { |
52 | 81 | @Override |
53 | 82 | public void prepare(PreparedStatement statement) throws SQLException { |
54 | 83 | statement.setLong(1, time); |
55 | 84 | statement.setString(2, playerUUID.toString()); |
56 | 85 | statement.setString(3, serverUUID.toString()); |
57 | 86 | } |
58 | 87 | }); |
59 | | - if (!updated) { |
60 | | - execute(new ExecStatement(AllowlistBounceTable.INSERT_STATEMENT) { |
61 | | - @Override |
62 | | - public void prepare(PreparedStatement statement) throws SQLException { |
63 | | - statement.setString(1, playerUUID.toString()); |
64 | | - statement.setString(2, playerName); |
65 | | - statement.setString(3, serverUUID.toString()); |
66 | | - statement.setInt(4, 1); |
67 | | - statement.setLong(5, time); |
68 | | - } |
69 | | - }); |
70 | | - } |
71 | 88 | } |
72 | 89 | } |
0 commit comments