Replaced concatenation with a better system

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2020-10-28 16:17:12 +01:00
parent 9c48d932d6
commit 6228fc9248
6 changed files with 62 additions and 58 deletions

View File

@ -65,21 +65,22 @@ public final class DBManager {
private static void initializeSubtitle(Connection connection) throws SQLException { private static void initializeSubtitle(Connection connection) throws SQLException {
logger.debug("Creating subtitle table."); logger.debug("Creating subtitle table.");
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
String query = "CREATE TABLE IF NOT EXISTS subtitles\n" + String query = """
"(\n" + CREATE TABLE IF NOT EXISTS subtitles
" id int GENERATED ALWAYS AS IDENTITY,\n" + (
" film_id int NOT NULL,\n" + id int GENERATED ALWAYS AS IDENTITY,
" language_id int NOT NULL,\n" + film_id int NOT NULL,
" importer varchar(37),\n" + language_id int NOT NULL,
" importer_guild_id text,\n" + importer varchar(37),
" imported_date timestamptz NOT NULL DEFAULT now(),\n" + importer_guild_id text,
" UNIQUE (film_id, language_id),\n" + imported_date timestamptz NOT NULL DEFAULT now(),
" PRIMARY KEY (id),\n" + UNIQUE (film_id, language_id),
" FOREIGN KEY (film_id)\n" + PRIMARY KEY (id),
" REFERENCES films (id),\n" + FOREIGN KEY (film_id)
" FOREIGN KEY (language_id)\n" + REFERENCES films (id),
" REFERENCES languages (id)\n" + FOREIGN KEY (language_id)
");"; REFERENCES languages (id)
);""";
stmt.executeUpdate(query); stmt.executeUpdate(query);
} }
} }

View File

@ -20,19 +20,20 @@ public final class FilmManager {
static void initializeFilm(Connection connection) throws SQLException { static void initializeFilm(Connection connection) throws SQLException {
logger.debug("Creating film table."); logger.debug("Creating film table.");
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
String query = "CREATE TABLE IF NOT EXISTS films\n" + String query = """
"(\n" + CREATE TABLE IF NOT EXISTS films
" id int GENERATED ALWAYS AS IDENTITY,\n" + (
" imdb_id varchar(10) NOT NULL,\n" + id int GENERATED ALWAYS AS IDENTITY,
" title text NOT NULL,\n" + imdb_id varchar(10) NOT NULL,
" year int,\n" + title text NOT NULL,
" film_type text NOT NULL,\n" + year int,
" season int,\n" + film_type text NOT NULL,
" episode int,\n" + season int,
" poster_link text,\n" + episode int,
" PRIMARY KEY (id),\n" + poster_link text,
" UNIQUE (imdb_id)\n" + PRIMARY KEY (id),
");"; UNIQUE (imdb_id)
);""";
stmt.executeUpdate(query); stmt.executeUpdate(query);
} }
} }

View File

@ -141,17 +141,18 @@ public final class LanguageManager {
static void initializeLanguages(Connection connection) throws SQLException { static void initializeLanguages(Connection connection) throws SQLException {
logger.debug("Creating language table."); logger.debug("Creating language table.");
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
String query = "CREATE TABLE IF NOT EXISTS languages\n" + String query = """
"(\n" + CREATE TABLE IF NOT EXISTS languages
" id int GENERATED ALWAYS AS IDENTITY,\n" + (
" alpha3_b char(3) NOT NULL,\n" + id int GENERATED ALWAYS AS IDENTITY,
" alpha3_t char(3),\n" + alpha3_b char(3) NOT NULL,
" alpha2 char(2),\n" + alpha3_t char(3),
" english text NOT NULL,\n" + alpha2 char(2),
" french text NOT NULL,\n" + english text NOT NULL,
" PRIMARY KEY (id),\n" + french text NOT NULL,
" UNIQUE (alpha3_b)\n" + PRIMARY KEY (id),
");"; UNIQUE (alpha3_b)
);""";
stmt.executeUpdate(query); stmt.executeUpdate(query);
} }
} }

View File

@ -54,14 +54,15 @@ public final class PropertyManager {
static void initializeProperties(Connection connection) throws SQLException { static void initializeProperties(Connection connection) throws SQLException {
logger.debug("Creating properties table."); logger.debug("Creating properties table.");
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
String query = "CREATE TABLE IF NOT EXISTS properties\n" + String query = """
"(\n" + CREATE TABLE IF NOT EXISTS properties
" id int GENERATED ALWAYS AS IDENTITY,\n" + (
" app_key text NOT NULL,\n" + id int GENERATED ALWAYS AS IDENTITY,
" app_value text NOT NULL,\n" + app_key text NOT NULL,
" PRIMARY KEY (id),\n" + app_value text NOT NULL,
" UNIQUE (app_key)\n" + PRIMARY KEY (id),
");"; UNIQUE (app_key)
);""";
stmt.executeUpdate(query); stmt.executeUpdate(query);
} }
} }

View File

@ -17,16 +17,17 @@ public final class SubtitleLineManager {
static void initializeSubtitleLine(Connection connection) throws SQLException { static void initializeSubtitleLine(Connection connection) throws SQLException {
logger.debug("Creating subtitle_line table."); logger.debug("Creating subtitle_line table.");
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
String query = "CREATE TABLE IF NOT EXISTS subtitle_lines\n" + String query = """
"(\n" + CREATE TABLE IF NOT EXISTS subtitle_lines
" id int GENERATED ALWAYS AS IDENTITY,\n" + (
" subtitle_id int NOT NULL,\n" + id int GENERATED ALWAYS AS IDENTITY,
" dialog_line text NOT NULL,\n" + subtitle_id int NOT NULL,
" time_code text NOT NULL,\n" + dialog_line text NOT NULL,
" PRIMARY KEY (id),\n" + time_code text NOT NULL,
" FOREIGN KEY (subtitle_id)\n" + PRIMARY KEY (id),
" REFERENCES subtitles (id)\n" + FOREIGN KEY (subtitle_id)
");"; REFERENCES subtitles (id)
);""";
stmt.executeUpdate(query); stmt.executeUpdate(query);
} }
} }

View File

@ -17,7 +17,6 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;