From 86bc530f148bcf3d6c4b7da024286494cbf19152 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Thu, 8 Dec 2022 19:09:35 +0800 Subject: [PATCH] fixed SekaiSong insert Song ignored its difficulties --- gradle.properties | 2 +- .../sekai_db/table/SekaiSongDifficulties.java | 21 +++++++++++++++++++ .../cc/sukazyo/sekai_db/table/SekaiSongs.java | 12 ++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 795f631..a1037e3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ ## Project Configurations # Proj Metadata -projVersion = 0.8 +projVersion = 0.8.1 # Dependencies diff --git a/sekai-database/src/main/java/cc/sukazyo/sekai_db/table/SekaiSongDifficulties.java b/sekai-database/src/main/java/cc/sukazyo/sekai_db/table/SekaiSongDifficulties.java index 6bd1feb..1ebfa15 100644 --- a/sekai-database/src/main/java/cc/sukazyo/sekai_db/table/SekaiSongDifficulties.java +++ b/sekai-database/src/main/java/cc/sukazyo/sekai_db/table/SekaiSongDifficulties.java @@ -2,6 +2,8 @@ package cc.sukazyo.sekai_db.table; import cc.sukazyo.sekai_db.PostgresSession; import cc.sukazyo.sekai_db.type.SekaiDifficulties; +import cc.sukazyo.sekai_scores.Difficulty; +import cc.sukazyo.sekai_scores.Song; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -63,5 +65,24 @@ public class SekaiSongDifficulties { else insert.setInt(7, data.plvlp); return insert.executeUpdate(); } + + public int insertFromSong (Difficulty difficulty, Song parent) throws SQLException { + final PreparedStatement insert = session.session.prepareStatement(""" + insert into sekai_song_difficulties + (song_id, difficulty, level, notes, "lvl+", "flvl+", "plvl+") + values (?, cast(? as sekai_difficulties), ?, ?, ?, ?, ?) + """); + insert.setInt(1, parent.id()); + insert.setString(2, difficulty.id()); + insert.setInt(3, difficulty.level()); + insert.setInt(4, difficulty.noteCount()); + if (difficulty.levelPlus() == Difficulty.NULL) insert.setNull(5, Types.SMALLINT); + insert.setInt(5, difficulty.levelPlus()); + if (difficulty.levelPlus_f() == Difficulty.NULL) insert.setNull(6, Types.SMALLINT); + insert.setInt(6, difficulty.levelPlus_f()); + if (difficulty.levelPlus_p() == Difficulty.NULL) insert.setNull(7, Types.SMALLINT); + insert.setInt(7, difficulty.levelPlus_p()); + return insert.executeUpdate(); + } } diff --git a/sekai-database/src/main/java/cc/sukazyo/sekai_db/table/SekaiSongs.java b/sekai-database/src/main/java/cc/sukazyo/sekai_db/table/SekaiSongs.java index 828ef73..3fc83bf 100644 --- a/sekai-database/src/main/java/cc/sukazyo/sekai_db/table/SekaiSongs.java +++ b/sekai-database/src/main/java/cc/sukazyo/sekai_db/table/SekaiSongs.java @@ -1,6 +1,7 @@ package cc.sukazyo.sekai_db.table; import cc.sukazyo.sekai_db.PostgresSession; +import cc.sukazyo.sekai_scores.Difficulty; import cc.sukazyo.sekai_scores.Song; import java.sql.PreparedStatement; @@ -30,6 +31,9 @@ public class SekaiSongs { } public int insert (Song song) throws SQLException { + + int updated = 0; + final PreparedStatement statement = session.session.prepareStatement(""" insert into sekai_songs (id, unit_seq, name, producer, arranger, composer, lyricist, bpm, duration, release_date, name_alias) @@ -49,7 +53,13 @@ public class SekaiSongs { if (song.releaseDate() == null) statement.setNull(10, Types.TIMESTAMP_WITH_TIMEZONE); else statement.setTimestamp(10, Timestamp.from(song.releaseDate().toInstant())); statement.setArray(11, session.session.createArrayOf("text", song.nameAlias())); - return statement.executeUpdate(); + updated += statement.executeUpdate(); + + for (Difficulty difficulty : song.difficulties().getAll()) + updated += SekaiSongDifficulties.as(session).insertFromSong(difficulty, song); + + return updated; + } }