Add some unit testing of the CfbSchema.
[cfb.git] / prod / net / jaekl / cfb / CFB.java
index 924d33182d28c4824207b6fde0712d4362d6d6b7..81c30ea7a39ac86aaa9ee90838775953ecc74189 100644 (file)
@@ -20,6 +20,7 @@ import net.jaekl.cfb.analyze.Analysis;
 import net.jaekl.cfb.analyze.Analyzer;
 import net.jaekl.cfb.analyze.MessageMap;
 import net.jaekl.cfb.db.CfbSchema;
+import net.jaekl.cfb.db.TypeMismatchException;
 import net.jaekl.cfb.db.driver.DbDriver;
 import net.jaekl.cfb.db.driver.PostgresqlDriver;
 import net.jaekl.cfb.store.DbStore;
@@ -151,7 +152,7 @@ public class CFB {
                }
        } 
        
-       void doMain(PrintWriter pw, String[] args) throws SQLException, IOException, XmlParseException, SAXException {
+       void doMain(PrintWriter pw, String[] args) throws SQLException, IOException, XmlParseException, SAXException, TypeMismatchException {
                initArgs();     // read environment and system properties
                if ( ! parseArgs(pw, args) ) {
                        return;
@@ -169,7 +170,8 @@ public class CFB {
                                m_schema.purge(con);
                                return;
                        }
-                       m_schema.ensureDbInitialized(con);      
+                       m_schema.ensureDbInitialized(con);
+                       messageMap.loadIds(con, m_driver);
                }
                catch (SQLException exc) {
                        reportUnableToConnect(pw, exc);
@@ -184,7 +186,7 @@ public class CFB {
                }
                
                try (Connection con = m_driver.connect(m_host, m_port, m_dbName, m_user, m_pass)) {
-                       DbStore store = new DbStore(con);
+                       DbStore store = new DbStore(con, m_driver, messageMap.getColl());
                        
                        store.put(analysis);
                }
@@ -198,6 +200,11 @@ public class CFB {
                String cannotConnectFormat = trans(CfbBundle.CANNOT_CONNECT);
                String cannotConnect = MessageFormat.format(cannotConnectFormat, m_host, ""+m_port, m_dbName, m_user);
                exc.printStackTrace(pw);
+               SQLException next = exc.getNextException();
+               while (null != next) {
+                       next.printStackTrace(pw);
+                       next = next.getNextException();
+               }
                pw.println(cannotConnect);
        }
        
@@ -207,7 +214,7 @@ public class CFB {
                try (PrintWriter pw = new PrintWriter(System.out)){
                        cfb.doMain(pw, args);
                        pw.flush();
-               } catch (SQLException | IOException | XmlParseException | SAXException exc) {
+               } catch (SQLException | IOException | XmlParseException | SAXException | TypeMismatchException exc) {
                        exc.printStackTrace();
                }
        }