]> WPIA git - gigi.git/blobdiff - util/org/cacert/gigi/util/DatabaseManager.java
Format code according do BenBE's formatter.
[gigi.git] / util / org / cacert / gigi / util / DatabaseManager.java
index 471083953b8d2b2f1362f8d440eca5016c7789de..9fe3f5fb3ec774416152fe2a5433193b667350a6 100644 (file)
@@ -11,44 +11,46 @@ import java.sql.Statement;
 import java.util.Properties;
 
 public class DatabaseManager {
-       public static String readFile(File f) throws IOException {
-               return new String(Files.readAllBytes(f.toPath()));
-       }
 
-       public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException {
-               if (args.length == 0) {
-                       Properties p = new Properties();
-                       p.load(new FileReader("config/gigi.properties"));
-                       args = new String[] { p.getProperty("sql.driver"), p.getProperty("sql.url"), p.getProperty("sql.user"),
-                                       p.getProperty("sql.password") };
-               }
-               if (args.length < 4) {
-                       System.err.println("Usage: com.mysql.jdbc.Driver jdbc:mysql://localhost/cacert user password");
-                       return;
-               }
-               run(args);
-       }
+    public static String readFile(File f) throws IOException {
+        return new String(Files.readAllBytes(f.toPath()));
+    }
 
-       public static void run(String[] args) throws ClassNotFoundException, SQLException, IOException {
-               Class.forName(args[0]);
-               Connection conn = DriverManager.getConnection(args[1], args[2], args[3]);
-               Statement stmt = conn.createStatement();
-               addFile(stmt, new File("doc/tableStructure.sql"));
-               File localData = new File("doc/sampleData.sql");
-               if (localData.exists()) {
-                       addFile(stmt, localData);
-               }
-               stmt.executeBatch();
-               stmt.close();
-       }
+    public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException {
+        if (args.length == 0) {
+            Properties p = new Properties();
+            p.load(new FileReader("config/gigi.properties"));
+            args = new String[] {
+                    p.getProperty("sql.driver"), p.getProperty("sql.url"), p.getProperty("sql.user"), p.getProperty("sql.password")
+            };
+        }
+        if (args.length < 4) {
+            System.err.println("Usage: com.mysql.jdbc.Driver jdbc:mysql://localhost/cacert user password");
+            return;
+        }
+        run(args);
+    }
 
-       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);
-                       }
-               }
-       }
+    public static void run(String[] args) throws ClassNotFoundException, SQLException, IOException {
+        Class.forName(args[0]);
+        Connection conn = DriverManager.getConnection(args[1], args[2], args[3]);
+        Statement stmt = conn.createStatement();
+        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);
+            }
+        }
+    }
 }