Database Manager: add optional "user data" sqlscript on creation.
authorFelix Dörre <felix@dogcraft.de>
Sat, 28 Jun 2014 01:16:11 +0000 (03:16 +0200)
committerFelix Dörre <felix@dogcraft.de>
Sat, 28 Jun 2014 16:16:39 +0000 (18:16 +0200)
doc/.gitignore [new file with mode: 0644]
util/org/cacert/gigi/util/DatabaseManager.java

diff --git a/doc/.gitignore b/doc/.gitignore
new file mode 100644 (file)
index 0000000..4696a08
--- /dev/null
@@ -0,0 +1 @@
+sampleData.sql\r
index e43eeb36203ed71c550d4ce7ce08cdd24267a9a4..da0c054cce5343170bd8393969d2afae15aabdd0 100644 (file)
@@ -27,14 +27,22 @@ public class DatabaseManager {
                Connection conn = DriverManager
                                .getConnection(args[1], args[2], args[3]);
                Statement stmt = conn.createStatement();
-               String sql = readFile(new File("doc/tableStructure.sql"));
+               addFile(stmt, new File("doc/tableStructure.sql"));
+               File localData = new File("doc/sampleData.sql");
+               if (localData.exists()) {
+                       addFile(stmt, localData);
+               }
+               stmt.executeBatch();
+               stmt.close();
+       }
+       private static void addFile(Statement stmt, File f) throws IOException,
+                       SQLException {
+               String sql = readFile(f);
                String[] stmts = sql.split(";");
                for (String string : stmts) {
                        if (!string.trim().equals("")) {
                                stmt.addBatch(string);
                        }
                }
-               stmt.executeBatch();
-               stmt.close();
        }
 }