]> WPIA git - gigi.git/commitdiff
add: support for resetting DB from stdin
authorFelix Dörre <felix@dogcraft.de>
Fri, 25 Aug 2017 17:00:44 +0000 (19:00 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 31 Aug 2017 22:54:35 +0000 (00:54 +0200)
Change-Id: I9f408922ea7eb60f2919594ca84fdf8540c2611a

tests/club/wpia/gigi/testUtils/ConfiguredTest.java
util/club/wpia/gigi/util/DatabaseManager.java

index 4dd091edd1aeb881f766f01826ee219c91a6a500..c4fa2279e959e108e96db2b160790f21893a598e 100644 (file)
@@ -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();
         }
index 54797224f9d7d8e47eae01a7580628f706bd83ea..a6dc2f7153fb29abd258af12475fb89ee0a31747 100644 (file)
@@ -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");