From 6228fc9248c72df01ffa0828cc4feb163369e748 Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Wed, 28 Oct 2020 16:17:12 +0100 Subject: [PATCH] Replaced concatenation with a better system Signed-off-by: Louis Vallat --- .../xyz/vallat/louis/database/DBManager.java | 31 ++++++++++--------- .../vallat/louis/database/FilmManager.java | 27 ++++++++-------- .../louis/database/LanguageManager.java | 23 +++++++------- .../louis/database/PropertyManager.java | 17 +++++----- .../louis/database/SubtitleLineManager.java | 21 +++++++------ .../xyz/vallat/louis/omdb/OMDBClient.java | 1 - 6 files changed, 62 insertions(+), 58 deletions(-) diff --git a/src/main/java/xyz/vallat/louis/database/DBManager.java b/src/main/java/xyz/vallat/louis/database/DBManager.java index 0bdc2f5..60e63b9 100644 --- a/src/main/java/xyz/vallat/louis/database/DBManager.java +++ b/src/main/java/xyz/vallat/louis/database/DBManager.java @@ -65,21 +65,22 @@ public final class DBManager { private static void initializeSubtitle(Connection connection) throws SQLException { logger.debug("Creating subtitle table."); try (Statement stmt = connection.createStatement()) { - String query = "CREATE TABLE IF NOT EXISTS subtitles\n" + - "(\n" + - " id int GENERATED ALWAYS AS IDENTITY,\n" + - " film_id int NOT NULL,\n" + - " language_id int NOT NULL,\n" + - " importer varchar(37),\n" + - " importer_guild_id text,\n" + - " imported_date timestamptz NOT NULL DEFAULT now(),\n" + - " UNIQUE (film_id, language_id),\n" + - " PRIMARY KEY (id),\n" + - " FOREIGN KEY (film_id)\n" + - " REFERENCES films (id),\n" + - " FOREIGN KEY (language_id)\n" + - " REFERENCES languages (id)\n" + - ");"; + String query = """ + CREATE TABLE IF NOT EXISTS subtitles + ( + id int GENERATED ALWAYS AS IDENTITY, + film_id int NOT NULL, + language_id int NOT NULL, + importer varchar(37), + importer_guild_id text, + imported_date timestamptz NOT NULL DEFAULT now(), + UNIQUE (film_id, language_id), + PRIMARY KEY (id), + FOREIGN KEY (film_id) + REFERENCES films (id), + FOREIGN KEY (language_id) + REFERENCES languages (id) + );"""; stmt.executeUpdate(query); } } diff --git a/src/main/java/xyz/vallat/louis/database/FilmManager.java b/src/main/java/xyz/vallat/louis/database/FilmManager.java index 487beb3..1fe1b89 100644 --- a/src/main/java/xyz/vallat/louis/database/FilmManager.java +++ b/src/main/java/xyz/vallat/louis/database/FilmManager.java @@ -20,19 +20,20 @@ public final class FilmManager { static void initializeFilm(Connection connection) throws SQLException { logger.debug("Creating film table."); try (Statement stmt = connection.createStatement()) { - String query = "CREATE TABLE IF NOT EXISTS films\n" + - "(\n" + - " id int GENERATED ALWAYS AS IDENTITY,\n" + - " imdb_id varchar(10) NOT NULL,\n" + - " title text NOT NULL,\n" + - " year int,\n" + - " film_type text NOT NULL,\n" + - " season int,\n" + - " episode int,\n" + - " poster_link text,\n" + - " PRIMARY KEY (id),\n" + - " UNIQUE (imdb_id)\n" + - ");"; + String query = """ + CREATE TABLE IF NOT EXISTS films + ( + id int GENERATED ALWAYS AS IDENTITY, + imdb_id varchar(10) NOT NULL, + title text NOT NULL, + year int, + film_type text NOT NULL, + season int, + episode int, + poster_link text, + PRIMARY KEY (id), + UNIQUE (imdb_id) + );"""; stmt.executeUpdate(query); } } diff --git a/src/main/java/xyz/vallat/louis/database/LanguageManager.java b/src/main/java/xyz/vallat/louis/database/LanguageManager.java index 6797542..37afc32 100644 --- a/src/main/java/xyz/vallat/louis/database/LanguageManager.java +++ b/src/main/java/xyz/vallat/louis/database/LanguageManager.java @@ -141,17 +141,18 @@ public final class LanguageManager { static void initializeLanguages(Connection connection) throws SQLException { logger.debug("Creating language table."); try (Statement stmt = connection.createStatement()) { - String query = "CREATE TABLE IF NOT EXISTS languages\n" + - "(\n" + - " id int GENERATED ALWAYS AS IDENTITY,\n" + - " alpha3_b char(3) NOT NULL,\n" + - " alpha3_t char(3),\n" + - " alpha2 char(2),\n" + - " english text NOT NULL,\n" + - " french text NOT NULL,\n" + - " PRIMARY KEY (id),\n" + - " UNIQUE (alpha3_b)\n" + - ");"; + String query = """ + CREATE TABLE IF NOT EXISTS languages + ( + id int GENERATED ALWAYS AS IDENTITY, + alpha3_b char(3) NOT NULL, + alpha3_t char(3), + alpha2 char(2), + english text NOT NULL, + french text NOT NULL, + PRIMARY KEY (id), + UNIQUE (alpha3_b) + );"""; stmt.executeUpdate(query); } } diff --git a/src/main/java/xyz/vallat/louis/database/PropertyManager.java b/src/main/java/xyz/vallat/louis/database/PropertyManager.java index e2139f2..a2f1e87 100644 --- a/src/main/java/xyz/vallat/louis/database/PropertyManager.java +++ b/src/main/java/xyz/vallat/louis/database/PropertyManager.java @@ -54,14 +54,15 @@ public final class PropertyManager { static void initializeProperties(Connection connection) throws SQLException { logger.debug("Creating properties table."); try (Statement stmt = connection.createStatement()) { - String query = "CREATE TABLE IF NOT EXISTS properties\n" + - "(\n" + - " id int GENERATED ALWAYS AS IDENTITY,\n" + - " app_key text NOT NULL,\n" + - " app_value text NOT NULL,\n" + - " PRIMARY KEY (id),\n" + - " UNIQUE (app_key)\n" + - ");"; + String query = """ + CREATE TABLE IF NOT EXISTS properties + ( + id int GENERATED ALWAYS AS IDENTITY, + app_key text NOT NULL, + app_value text NOT NULL, + PRIMARY KEY (id), + UNIQUE (app_key) + );"""; stmt.executeUpdate(query); } } diff --git a/src/main/java/xyz/vallat/louis/database/SubtitleLineManager.java b/src/main/java/xyz/vallat/louis/database/SubtitleLineManager.java index deeb54b..4afb9b2 100644 --- a/src/main/java/xyz/vallat/louis/database/SubtitleLineManager.java +++ b/src/main/java/xyz/vallat/louis/database/SubtitleLineManager.java @@ -17,16 +17,17 @@ public final class SubtitleLineManager { static void initializeSubtitleLine(Connection connection) throws SQLException { logger.debug("Creating subtitle_line table."); try (Statement stmt = connection.createStatement()) { - String query = "CREATE TABLE IF NOT EXISTS subtitle_lines\n" + - "(\n" + - " id int GENERATED ALWAYS AS IDENTITY,\n" + - " subtitle_id int NOT NULL,\n" + - " dialog_line text NOT NULL,\n" + - " time_code text NOT NULL,\n" + - " PRIMARY KEY (id),\n" + - " FOREIGN KEY (subtitle_id)\n" + - " REFERENCES subtitles (id)\n" + - ");"; + String query = """ + CREATE TABLE IF NOT EXISTS subtitle_lines + ( + id int GENERATED ALWAYS AS IDENTITY, + subtitle_id int NOT NULL, + dialog_line text NOT NULL, + time_code text NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (subtitle_id) + REFERENCES subtitles (id) + );"""; stmt.executeUpdate(query); } } diff --git a/src/main/java/xyz/vallat/louis/omdb/OMDBClient.java b/src/main/java/xyz/vallat/louis/omdb/OMDBClient.java index a8058eb..304b785 100644 --- a/src/main/java/xyz/vallat/louis/omdb/OMDBClient.java +++ b/src/main/java/xyz/vallat/louis/omdb/OMDBClient.java @@ -17,7 +17,6 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; -import java.text.ParseException; import java.util.ArrayList; import java.util.List;