Added a Log for JDBC code; info -> debug for HSQL liaison.

This commit is contained in:
Michael Bayne
2013-05-24 10:43:37 -07:00
parent 58736e2e8b
commit 3442a51457
13 changed files with 51 additions and 33 deletions
@@ -14,8 +14,6 @@ import java.util.List;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import static com.samskivert.Log.log;
/** /**
* A superclass to help with the shrinking subset of SQL our supported dialects can agree on, * A superclass to help with the shrinking subset of SQL our supported dialects can agree on,
* or when there is disagreement, implement the most standard-compliant version and let the * or when there is disagreement, implement the most standard-compliant version and let the
@@ -106,7 +104,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
update.append(")"); update.append(")");
executeQuery(conn, update.toString()); executeQuery(conn, update.toString());
log.info("Database index '" + ixName + "' added to table '" + table + "'"); log("Database index '" + ixName + "' added to table '" + table + "'");
return true; return true;
} }
@@ -120,7 +118,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
String update = "ALTER TABLE " + tableSQL(table) + " ADD PRIMARY KEY " + fields.toString(); String update = "ALTER TABLE " + tableSQL(table) + " ADD PRIMARY KEY " + fields.toString();
executeQuery(conn, update); executeQuery(conn, update);
log.info("Primary key " + fields + " added to table '" + table + "'"); log("Primary key " + fields + " added to table '" + table + "'");
} }
// from DatabaseLiaison // from DatabaseLiaison
@@ -146,7 +144,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " ADD COLUMN " + executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " ADD COLUMN " +
columnSQL(column) + " " + definition); columnSQL(column) + " " + definition);
log.info("Database column '" + column + "' added to table '" + table + "'."); log("Database column '" + column + "' added to table '" + table + "'.");
return true; return true;
} }
@@ -161,7 +159,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " ADD COLUMN " + executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " ADD COLUMN " +
columnSQL(column) + " " + expandDefinition(newColumnDef)); columnSQL(column) + " " + expandDefinition(newColumnDef));
log.info("Database column '" + column + "' added to table '" + table + "'."); log("Database column '" + column + "' added to table '" + table + "'.");
return true; return true;
} }
@@ -175,8 +173,8 @@ public abstract class BaseLiaison implements DatabaseLiaison
executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " CHANGE " + executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " CHANGE " +
columnSQL(column) + " " + columnSQL(column) + " " + defStr); columnSQL(column) + " " + columnSQL(column) + " " + defStr);
log.info("Database column '" + column + "' of table '" + table + "' modified to have " + log("Database column '" + column + "' of table '" + table + "' modified to have " +
"definition '" + defStr + "'."); "definition '" + defStr + "'.");
return true; return true;
} }
@@ -186,7 +184,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
{ {
executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " RENAME COLUMN " + executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " RENAME COLUMN " +
columnSQL(from) + " TO " + columnSQL(to)); columnSQL(from) + " TO " + columnSQL(to));
log.info("Renamed column '" + from + "' on table '" + table + "' to '" + to + "'"); log("Renamed column '" + from + "' on table '" + table + "' to '" + to + "'");
return true; return true;
} }
@@ -206,7 +204,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
return false; return false;
} }
executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " DROP COLUMN " + columnSQL(column)); executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " DROP COLUMN " + columnSQL(column));
log.info("Database column '" + column + "' removed from table '" + table + "'."); log("Database column '" + column + "' removed from table '" + table + "'.");
return true; return true;
} }
@@ -261,7 +259,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
builder.append(")"); builder.append(")");
executeQuery(conn, builder.toString()); executeQuery(conn, builder.toString());
log.info("Database table '" + table + "' created."); log("Database table '" + table + "' created.");
return true; return true;
} }
@@ -272,7 +270,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
return false; return false;
} }
executeQuery(conn, "DROP TABLE " + tableSQL(name)); executeQuery(conn, "DROP TABLE " + tableSQL(name));
log.info("Table '" + name + "' dropped."); log("Table '" + name + "' dropped.");
return true; return true;
} }
@@ -332,4 +330,8 @@ public abstract class BaseLiaison implements DatabaseLiaison
buf.append(columnSQL(column)); buf.append(columnSQL(column));
} }
} }
protected void log (String message) {
Log.log.info(message);
}
} }
@@ -11,7 +11,7 @@ import javax.sql.DataSource;
import com.samskivert.io.PersistenceException; import com.samskivert.io.PersistenceException;
import static com.samskivert.Log.log; import static com.samskivert.jdbc.Log.log;
/** /**
* Provides connections using a pair of {@link DataSource} instances (one for read-only operations * Provides connections using a pair of {@link DataSource} instances (one for read-only operations
@@ -16,8 +16,6 @@ import java.sql.ResultSet;
import java.sql.Statement; import java.sql.Statement;
import java.sql.SQLException; import java.sql.SQLException;
import static com.samskivert.Log.log;
/** /**
* Handles liaison for HSQLDB. * Handles liaison for HSQLDB.
*/ */
@@ -64,7 +62,7 @@ public class HsqldbLiaison extends BaseLiaison
} finally { } finally {
JDBCUtil.close(stmt); JDBCUtil.close(stmt);
} }
log.info("Initial value of " + tableName + ":" + columnName + " set to " + initValue + "."); log("Initial value of " + tableName + ":" + columnName + " set to " + initValue + ".");
} }
@Override // from DatabaseLiaison @Override // from DatabaseLiaison
@@ -191,4 +189,11 @@ public class HsqldbLiaison extends BaseLiaison
return builder.toString(); return builder.toString();
} }
@Override
protected void log (String message) {
// HSQL is generally used as a test database, so we don't generally want to hear a bunch of
// spam about table creation, etc. every time we start up/run tests
Log.log.debug(message);
}
} }
@@ -23,7 +23,7 @@ import java.sql.Statement;
import com.samskivert.io.PersistenceException; import com.samskivert.io.PersistenceException;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import static com.samskivert.Log.log; import static com.samskivert.jdbc.Log.log;
/** /**
* A repository for JDBC related utility functions. * A repository for JDBC related utility functions.
@@ -11,7 +11,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static com.samskivert.Log.log; import static com.samskivert.jdbc.Log.log;
/** /**
* The liaison registry provides access to the appropriate database liaison implementation for a * The liaison registry provides access to the appropriate database liaison implementation for a
@@ -0,0 +1,15 @@
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001-2012 Michael Bayne, et al.
// http://github.com/samskivert/samskivert/blob/master/COPYING
package com.samskivert.jdbc;
import com.samskivert.util.Logger;
/** A log instance for the JDBC code. */
public class Log {
/** We dispatch our log messages through this logger. */
public static final Logger log = Logger.getLogger("com.samskivert.jdbc");
}
@@ -8,8 +8,6 @@ package com.samskivert.jdbc;
import java.sql.*; import java.sql.*;
import java.util.List; import java.util.List;
import static com.samskivert.Log.log;
/** /**
* A database liaison for the MySQL database. * A database liaison for the MySQL database.
*/ */
@@ -86,7 +84,7 @@ public class MySQLLiaison extends BaseLiaison
update.append(")"); update.append(")");
executeQuery(conn, update.toString()); executeQuery(conn, update.toString());
log.info("Database index '" + ixName + "' added to table '" + table + "'"); log("Database index '" + ixName + "' added to table '" + table + "'");
return true; return true;
} }
@@ -112,8 +110,8 @@ public class MySQLLiaison extends BaseLiaison
} }
executeQuery(conn, "ALTER TABLE " + table + " CHANGE " + oldColumnName + " " + executeQuery(conn, "ALTER TABLE " + table + " CHANGE " + oldColumnName + " " +
newColumnName + " " + expandDefinition(newColumnDef)); newColumnName + " " + expandDefinition(newColumnDef));
log.info("Renamed column '" + oldColumnName + "' on table '" + table + "' to '" + log("Renamed column '" + oldColumnName + "' on table '" + table + "' to '" +
newColumnName + "'"); newColumnName + "'");
return true; return true;
} }
@@ -7,8 +7,6 @@ package com.samskivert.jdbc;
import java.sql.*; import java.sql.*;
import static com.samskivert.Log.log;
/** /**
* A database liaison for the MySQL database. * A database liaison for the MySQL database.
*/ */
@@ -68,7 +66,7 @@ public class PostgreSQLLiaison extends BaseLiaison
} finally { } finally {
JDBCUtil.close(stmt); JDBCUtil.close(stmt);
} }
log.info("Initial value of " + seqname + " set to " + initValue + "."); log("Initial value of " + seqname + " set to " + initValue + ".");
} }
// from DatabaseLiaison // from DatabaseLiaison
@@ -115,8 +113,8 @@ public class PostgreSQLLiaison extends BaseLiaison
} }
lbuf.append("defaultValue=").append(defaultValue); lbuf.append("defaultValue=").append(defaultValue);
} }
log.info("Database column '" + column + "' of table '" + table + "' modified to have " + log("Database column '" + column + "' of table '" + table + "' modified to have " +
"definition [" + lbuf + "]."); "definition [" + lbuf + "].");
return true; return true;
} }
@@ -10,7 +10,7 @@ import java.sql.*;
import com.samskivert.io.PersistenceException; import com.samskivert.io.PersistenceException;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import static com.samskivert.Log.log; import static com.samskivert.jdbc.Log.log;
/** /**
* The simple repository should be used for a repository that only needs access to a single JDBC * The simple repository should be used for a repository that only needs access to a single JDBC
@@ -14,7 +14,7 @@ import com.samskivert.util.ConfigUtil;
import com.samskivert.util.PropertiesUtil; import com.samskivert.util.PropertiesUtil;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import static com.samskivert.Log.log; import static com.samskivert.jdbc.Log.log;
/** /**
* The static connection provider generates JDBC connections based on configuration information * The static connection provider generates JDBC connections based on configuration information
@@ -16,7 +16,7 @@ import java.util.List;
import com.samskivert.io.PersistenceException; import com.samskivert.io.PersistenceException;
import static com.samskivert.Log.log; import static com.samskivert.jdbc.Log.log;
/** /**
* Used to note that transitionary code has been run to migrate persistent data. This is especially * Used to note that transitionary code has been run to migrate persistent data. This is especially
@@ -7,7 +7,7 @@ package com.samskivert.jdbc;
import com.samskivert.util.Invoker; import com.samskivert.util.Invoker;
import static com.samskivert.Log.log; import static com.samskivert.jdbc.Log.log;
/** /**
* Extends {@link com.samskivert.util.Invoker.Unit} and specializes it for writing to a database * Extends {@link com.samskivert.util.Invoker.Unit} and specializes it for writing to a database
@@ -8,7 +8,7 @@ package com.samskivert.jdbc.jora;
import java.util.*; import java.util.*;
import java.sql.*; import java.sql.*;
import static com.samskivert.Log.log; import static com.samskivert.jdbc.Log.log;
/** /**
* Cursor is used for successive access to records fetched by SELECT statement. * Cursor is used for successive access to records fetched by SELECT statement.