--- /dev/null
+#!/bin/bash
+CFB_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+echo Compiling...
+find "${CFB_ROOT}/prod" -name "*.java" | xargs javac -classpath ${CFB_ROOT}/prod:${CLASSPATH} -Xlint:deprecation
+cp -r ${CFB_ROOT}/prod/* ${CFB_ROOT}/bin/
+find "${CFB_ROOT}/prod" -name '*.class' -exec rm {} \;
+echo Launching...
+java -Djsse.enableSNIExtension=false net.jaekl.cfb.CFB $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} ${12} ${13} ${14} ${15} ${16} ${17} ${18} ${19} ${20}
--- /dev/null
+cannot.connect.to.db=Unable to connect to database {2} on {0}:{1} as user {3}.
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;
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
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";
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;
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);
}
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);
--- /dev/null
+package net.jaekl.cfb;
+
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import java.util.concurrent.ConcurrentHashMap;
+
+import net.jaekl.qd.QDBundleFactory;
+
+public class CfbBundle {
+ public static final String CANNOT_CONNECT = "cannot.connect.to.db";
+
+ final static String BUNDLE_NAME = "cfb";
+
+ static ConcurrentHashMap<Locale, CfbBundle> m_bundleMap = new ConcurrentHashMap<Locale, CfbBundle>();
+
+ ResourceBundle m_bundle;
+
+ public static CfbBundle getInst(Locale locale) {
+ CfbBundle result = m_bundleMap.get(locale);
+ if (null == result) {
+ synchronized(CfbBundle.class) {
+ result = m_bundleMap.get(locale);
+ if (null == result) {
+ result = new CfbBundle(locale);
+ }
+ m_bundleMap.put(locale, result);
+ }
+ }
+ return result;
+ }
+
+ private CfbBundle(Locale locale) {
+ m_bundle = QDBundleFactory.getInst().getBundle(BUNDLE_NAME, locale);
+ }
+
+ public String get(String key) {
+ try {
+ if (null != m_bundle) {
+ return m_bundle.getString(key);
+ }
+ }
+ catch (MissingResourceException exc) {
+ // Make it clear that something has gone wrong.
+ exc.printStackTrace();
+ // Fall through to the fallback behaviour below
+ }
+ return "[" + key + "]";
+ }
+}
},
{
// Runs of FindBugs, normally one per build version
- { "RUNS " },
+ { "RUNS" },
{ "RUNID", INTEGER, -1, NOT_NULL },
{ "VERSION", VARCHAR, 32, NULL },
- { "START", TIMESTAMPTZ, -1, NOT_NULL },
- { "END", TIMESTAMPTZ, -1, NOT_NULL }
+ { "STARTTIME", TIMESTAMPTZ, -1, NOT_NULL },
+ { "ENDTIME", TIMESTAMPTZ, -1, NOT_NULL }
}
};
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Locale;
import net.jaekl.cfb.db.driver.DbDriver;
try (ResultSet rs = dbmd.getTables(null, null, null, new String[]{"TABLE"})) {
while (rs.next()) {
- extantTables.add(rs.getString(3));
+ extantTables.add(rs.getString(3).toUpperCase(Locale.CANADA));
}
}
for (Table table : m_tables) {
- if ( ! extantTables.contains(table.getName()) ) {
+ String name = table.getName().toUpperCase(Locale.CANADA);
+ if ( ! extantTables.contains(name) ) {
// One or more tables missing
return false;
}
try (PreparedStatement ps = con.prepareStatement(sql)) {
ps.executeUpdate();
}
+ catch (SQLException exc) {
+ throw new SQLException("Failed to executeUpdate: " + sql, exc);
+ }
return true;
}
--- /dev/null
+// Copyright (C) 2004, 2014 Christian Jaekl
+
+// Central spot from which to access ResourceBundles.
+// This made more sense with earlier versions of Java, where the specification did not
+// guarantee that ResourceBundles would be cached. Java 7 and later cache by default,
+// but it still seems prudent to centralize accesses to resources here so that we have
+// control in case we want to implement our own cache, or override certain behaviours.
+//
+// Note that we rely on the JVM's caching, to avoid unnecessary overhead.
+// See http://java2go.blogspot.ca/2010/03/dont-be-smart-never-implement-resource.html
+
+package net.jaekl.qd;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+public class QDBundleFactory {
+ static volatile QDBundleFactory m_inst; // singleton instance
+
+ private QDBundleFactory() {
+ // no-op
+ }
+
+ public static QDBundleFactory getInst() {
+ QDBundleFactory result = m_inst;
+ if (null == result) {
+ synchronized(QDBundleFactory.class) {
+ if (null == m_inst) {
+ m_inst = new QDBundleFactory();
+ }
+ result = m_inst;
+ }
+ }
+ return result;
+ }
+
+ public ResourceBundle getBundle(String baseName, Locale locale) {
+ return ResourceBundle.getBundle(baseName, locale);
+ }
+}
--- /dev/null
+#!/bin/bash
+
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+export CLASSPATH=${SCRIPT_DIR}/bin
+
+for x in ${SCRIPT_DIR}/lib/*.jar
+do
+ export CLASSPATH=${x}:${CLASSPATH}
+done
+
+export CLASSPATH=/usr/share/java/commons-cli.jar:${CLASSPATH}
+export CLASSPATH=/usr/share/java/junit4.jar:${CLASSPATH}
+export CLASSPATH=/usr/share/java/postgresql.jar:${CLASSPATH}
+#export CLASSPATH=${SCRIPT_DIR}/jcov/jcov.jar:${CLASSPATH}