From 31f210e4895b1259e00ddb43b12d03a86022a991 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 29 Oct 2023 14:49:07 +0200 Subject: [PATCH] Add block to turn on UUID plugin. --- .../repositories/blocks/TurnOnUUIDPlugin.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/space/kklochko/jdbc_hospital_example/db/repositories/blocks/TurnOnUUIDPlugin.java diff --git a/src/main/java/space/kklochko/jdbc_hospital_example/db/repositories/blocks/TurnOnUUIDPlugin.java b/src/main/java/space/kklochko/jdbc_hospital_example/db/repositories/blocks/TurnOnUUIDPlugin.java new file mode 100644 index 0000000..a7f96be --- /dev/null +++ b/src/main/java/space/kklochko/jdbc_hospital_example/db/repositories/blocks/TurnOnUUIDPlugin.java @@ -0,0 +1,19 @@ +package space.kklochko.jdbc_hospital_example.db.repositories.blocks; + +import space.kklochko.jdbc_hospital_example.db.factories.DataBaseConnection; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +public class TurnOnUUIDPlugin { + public boolean create(DataBaseConnection db) { + try (Connection connection = db.connect()) { + Statement statement = connection.createStatement(); + statement.execute("CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"); + return true; + } catch (SQLException e) { + throw new RuntimeException(e); + } + } +}