From: Felix Dörre Date: Fri, 25 Aug 2017 17:00:44 +0000 (+0200) Subject: add: support for resetting DB from stdin X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=cd52b411056e1a73d9c65dfe9f6fbb82b8512bc9 add: support for resetting DB from stdin Change-Id: I9f408922ea7eb60f2919594ca84fdf8540c2611a --- diff --git a/tests/club/wpia/gigi/testUtils/ConfiguredTest.java b/tests/club/wpia/gigi/testUtils/ConfiguredTest.java index 4dd091ed..c4fa2279 100644 --- a/tests/club/wpia/gigi/testUtils/ConfiguredTest.java +++ b/tests/club/wpia/gigi/testUtils/ConfiguredTest.java @@ -265,7 +265,7 @@ public abstract class ConfiguredTest { try { DatabaseManager.run(new String[] { testProps.getProperty("sql.driver"), testProps.getProperty("sql.url"), testProps.getProperty("sql.user"), testProps.getProperty("sql.password") - }, ImportType.TRUNCATE); + }, ImportType.TRUNCATE, false); } catch (ClassNotFoundException e) { e.printStackTrace(); } diff --git a/util/club/wpia/gigi/util/DatabaseManager.java b/util/club/wpia/gigi/util/DatabaseManager.java index 54797224..a6dc2f71 100644 --- a/util/club/wpia/gigi/util/DatabaseManager.java +++ b/util/club/wpia/gigi/util/DatabaseManager.java @@ -20,12 +20,19 @@ public class DatabaseManager { public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException { boolean test = false; + boolean stdin = false; if (args.length >= 1 && args[0].equals("--test")) { test = true; String[] ne = new String[args.length - 1]; System.arraycopy(args, 1, ne, 0, ne.length); args = ne; } + if (args.length >= 1 && args[0].equals("--stdin")) { + stdin = true; + String[] ne = new String[args.length - 1]; + System.arraycopy(args, 1, ne, 0, ne.length); + args = ne; + } if (args.length == 0) { Properties p = new Properties(); try (Reader reader = new InputStreamReader(new FileInputStream("config/gigi.properties"), "UTF-8")) { @@ -39,17 +46,17 @@ public class DatabaseManager { System.err.println("Usage: org.postgresql.Driver jdbc:postgresql://localhost/gigi user password"); return; } - run(args, test ? ImportType.TEST : ImportType.PRODUCTION); + run(args, test ? ImportType.TEST : ImportType.PRODUCTION, stdin); } - public static void run(String[] args, ImportType truncate) throws ClassNotFoundException, SQLException, IOException { + public static void run(String[] args, ImportType truncate, boolean stdin) throws ClassNotFoundException, SQLException, IOException { Class.forName(args[0]); final Connection conn = DriverManager.getConnection(args[1], args[2], args[3]); try { conn.setAutoCommit(false); Statement stmt = conn.createStatement(); try { - try (InputStream structure = DatabaseConnection.class.getResourceAsStream("tableStructure.sql")) { + try (InputStream structure = stdin ? System.in : DatabaseConnection.class.getResourceAsStream("tableStructure.sql")) { SQLFileManager.addFile(stmt, structure, truncate); } File localData = new File("doc/sampleData.sql");