Skip to content

Commit e3ee486

Browse files
committed
Rewardの存在をチェックするメソッド追加
1 parent 3fc04dc commit e3ee486

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/main/java/dev/felnull/pointed/teams/manager/reward/RewardAdminService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public interface RewardAdminService {
2424
void moveCommand(int rewardId, int fromIdx, int toIdx) throws SQLException;
2525
void setCommandEnabled(int rewardId, int idx, boolean enabled) throws SQLException;
2626
void updateCommandText(int rewardId, int idx, String newText) throws SQLException;
27+
boolean rewardExists(long rewardId);
2728

2829
// ===== Reward =====
2930
/**

src/main/java/dev/felnull/pointed/teams/manager/reward/impl/RewardAdminServiceImpl.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,5 +752,35 @@ public void dispatchManual(UUID playerUuid, String playerName, int rewardId) thr
752752
}
753753
}
754754

755+
// ==== 存在確認(非トランザクション版)====
756+
public boolean rewardExists(long rewardId) {
757+
try (Connection con = ds.getConnection()) {
758+
return rewardExists(con, rewardId);
759+
} catch (SQLException e) {
760+
throw new RuntimeException(e);
761+
}
762+
}
763+
764+
// ==== 存在確認(トランザクション版・接続使い回し)====
765+
public boolean rewardExists(Connection con, long rewardId) throws SQLException {
766+
final String sql = "SELECT 1 FROM rewards WHERE id = ? LIMIT 1";
767+
try (PreparedStatement ps = con.prepareStatement(sql)) {
768+
ps.setLong(1, rewardId);
769+
try (ResultSet rs = ps.executeQuery()) {
770+
return rs.next(); // 1行でも返れば存在
771+
}
772+
}
773+
}
774+
775+
// もし名前で唯一ならこっちも(任意)
776+
public boolean rewardExistsByName(Connection con, String name) throws SQLException {
777+
final String sql = "SELECT 1 FROM rewards WHERE name = ? LIMIT 1";
778+
try (PreparedStatement ps = con.prepareStatement(sql)) {
779+
ps.setString(1, name);
780+
try (ResultSet rs = ps.executeQuery()) {
781+
return rs.next();
782+
}
783+
}
784+
}
755785

756786
}

0 commit comments

Comments
 (0)