Bring things to a state where the basic DB schema gets auto-created if it doesn't...
[cfb.git] / prod / net / jaekl / cfb / CFB.java
index d864b6dc8681b9ae3de5d32b6603329385cc83ca..4d30011284f4d33e02a57a950c6e30cb74ebbcea 100644 (file)
@@ -3,6 +3,12 @@ package net.jaekl.cfb;
 import java.io.PrintWriter;
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.text.MessageFormat;
+import java.util.Locale;
+
+import net.jaekl.cfb.db.CfbSchema;
+import net.jaekl.cfb.db.driver.DbDriver;
+import net.jaekl.cfb.db.driver.PostgresqlDriver;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.GnuParser;
@@ -10,13 +16,11 @@ import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 
-import net.jaekl.cfb.db.CfbSchema;
-import net.jaekl.cfb.db.driver.DbDriver;
-import net.jaekl.cfb.db.driver.PostgresqlDriver;
-
 public class CFB {
        DbDriver m_driver;
        CfbSchema m_schema;
+       CfbBundle m_bundle;     
+       Locale m_locale;
        
        // Command-line parameters
        String m_dbName; // db name
@@ -25,9 +29,11 @@ public class CFB {
        String m_user;  // db user
        String m_pass;  // db password
        
-       CFB() {
+       CFB(Locale locale) {
                m_driver = new PostgresqlDriver();
                m_schema = new CfbSchema(m_driver);
+               m_locale = locale;
+               m_bundle = CfbBundle.getInst(m_locale);
                
                m_dbName = "CFB";
                m_host = "localhost";
@@ -82,6 +88,10 @@ public class CFB {
                help.printHelp(pw, 80, getClass().getName(), "", opt, 0, 0, "", true);
        }
        
+       String trans(String key) {
+               return m_bundle.get(key);
+       }
+       
        void doMain(PrintWriter pw, String[] args) throws SQLException {
                if ( ! parseArgs(pw, args) ) {
                        return;
@@ -89,8 +99,9 @@ public class CFB {
                
                try (Connection con = m_driver.connect(m_host, m_port, m_dbName, m_user, m_pass)) {
                        if (null == con) {
-                               // TODO:  string table
-                               pw.println("FATAL:  Cannot connect to db.");
+                               String cannotConnectFormat = trans(CfbBundle.CANNOT_CONNECT);
+                               String cannotConnect = MessageFormat.format(cannotConnectFormat, m_host, m_port, m_dbName, m_user);
+                               pw.println(cannotConnect);
                                return;
                        }
                        m_schema.ensureDbInitialized(con);                      
@@ -98,7 +109,7 @@ public class CFB {
        }
        
        public static void main(String[] args) {
-               CFB cfb = new CFB();
+               CFB cfb = new CFB(Locale.getDefault());
                
                try (PrintWriter pw = new PrintWriter(System.out)){
                        cfb.doMain(pw, args);