Added a Log for JDBC code; info -> debug for HSQL liaison.
This commit is contained in:
@@ -14,8 +14,6 @@ import java.util.List;
|
||||
|
||||
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,
|
||||
* 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(")");
|
||||
|
||||
executeQuery(conn, update.toString());
|
||||
log.info("Database index '" + ixName + "' added to table '" + table + "'");
|
||||
log("Database index '" + ixName + "' added to table '" + table + "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -120,7 +118,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
String update = "ALTER TABLE " + tableSQL(table) + " ADD PRIMARY KEY " + fields.toString();
|
||||
|
||||
executeQuery(conn, update);
|
||||
log.info("Primary key " + fields + " added to table '" + table + "'");
|
||||
log("Primary key " + fields + " added to table '" + table + "'");
|
||||
}
|
||||
|
||||
// from DatabaseLiaison
|
||||
@@ -146,7 +144,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
|
||||
executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " ADD COLUMN " +
|
||||
columnSQL(column) + " " + definition);
|
||||
log.info("Database column '" + column + "' added to table '" + table + "'.");
|
||||
log("Database column '" + column + "' added to table '" + table + "'.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -161,7 +159,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
|
||||
executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " ADD COLUMN " +
|
||||
columnSQL(column) + " " + expandDefinition(newColumnDef));
|
||||
log.info("Database column '" + column + "' added to table '" + table + "'.");
|
||||
log("Database column '" + column + "' added to table '" + table + "'.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -175,8 +173,8 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
|
||||
executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " CHANGE " +
|
||||
columnSQL(column) + " " + columnSQL(column) + " " + defStr);
|
||||
log.info("Database column '" + column + "' of table '" + table + "' modified to have " +
|
||||
"definition '" + defStr + "'.");
|
||||
log("Database column '" + column + "' of table '" + table + "' modified to have " +
|
||||
"definition '" + defStr + "'.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -186,7 +184,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
{
|
||||
executeQuery(conn, "ALTER TABLE " + tableSQL(table) + " RENAME COLUMN " +
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -206,7 +204,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -261,7 +259,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
builder.append(")");
|
||||
|
||||
executeQuery(conn, builder.toString());
|
||||
log.info("Database table '" + table + "' created.");
|
||||
log("Database table '" + table + "' created.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -272,7 +270,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
return false;
|
||||
}
|
||||
executeQuery(conn, "DROP TABLE " + tableSQL(name));
|
||||
log.info("Table '" + name + "' dropped.");
|
||||
log("Table '" + name + "' dropped.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -332,4 +330,8 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
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 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
|
||||
|
||||
@@ -16,8 +16,6 @@ import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static com.samskivert.Log.log;
|
||||
|
||||
/**
|
||||
* Handles liaison for HSQLDB.
|
||||
*/
|
||||
@@ -64,7 +62,7 @@ public class HsqldbLiaison extends BaseLiaison
|
||||
} finally {
|
||||
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
|
||||
@@ -191,4 +189,11 @@ public class HsqldbLiaison extends BaseLiaison
|
||||
|
||||
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.util.StringUtil;
|
||||
import static com.samskivert.Log.log;
|
||||
import static com.samskivert.jdbc.Log.log;
|
||||
|
||||
/**
|
||||
* A repository for JDBC related utility functions.
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
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
|
||||
|
||||
@@ -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.util.List;
|
||||
|
||||
import static com.samskivert.Log.log;
|
||||
|
||||
/**
|
||||
* A database liaison for the MySQL database.
|
||||
*/
|
||||
@@ -86,7 +84,7 @@ public class MySQLLiaison extends BaseLiaison
|
||||
update.append(")");
|
||||
|
||||
executeQuery(conn, update.toString());
|
||||
log.info("Database index '" + ixName + "' added to table '" + table + "'");
|
||||
log("Database index '" + ixName + "' added to table '" + table + "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -112,8 +110,8 @@ public class MySQLLiaison extends BaseLiaison
|
||||
}
|
||||
executeQuery(conn, "ALTER TABLE " + table + " CHANGE " + oldColumnName + " " +
|
||||
newColumnName + " " + expandDefinition(newColumnDef));
|
||||
log.info("Renamed column '" + oldColumnName + "' on table '" + table + "' to '" +
|
||||
newColumnName + "'");
|
||||
log("Renamed column '" + oldColumnName + "' on table '" + table + "' to '" +
|
||||
newColumnName + "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ package com.samskivert.jdbc;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
import static com.samskivert.Log.log;
|
||||
|
||||
/**
|
||||
* A database liaison for the MySQL database.
|
||||
*/
|
||||
@@ -68,7 +66,7 @@ public class PostgreSQLLiaison extends BaseLiaison
|
||||
} finally {
|
||||
JDBCUtil.close(stmt);
|
||||
}
|
||||
log.info("Initial value of " + seqname + " set to " + initValue + ".");
|
||||
log("Initial value of " + seqname + " set to " + initValue + ".");
|
||||
}
|
||||
|
||||
// from DatabaseLiaison
|
||||
@@ -115,8 +113,8 @@ public class PostgreSQLLiaison extends BaseLiaison
|
||||
}
|
||||
lbuf.append("defaultValue=").append(defaultValue);
|
||||
}
|
||||
log.info("Database column '" + column + "' of table '" + table + "' modified to have " +
|
||||
"definition [" + lbuf + "].");
|
||||
log("Database column '" + column + "' of table '" + table + "' modified to have " +
|
||||
"definition [" + lbuf + "].");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.sql.*;
|
||||
import com.samskivert.io.PersistenceException;
|
||||
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
|
||||
|
||||
@@ -14,7 +14,7 @@ import com.samskivert.util.ConfigUtil;
|
||||
import com.samskivert.util.PropertiesUtil;
|
||||
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
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
|
||||
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
|
||||
|
||||
@@ -7,7 +7,7 @@ package com.samskivert.jdbc;
|
||||
|
||||
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
|
||||
|
||||
@@ -8,7 +8,7 @@ package com.samskivert.jdbc.jora;
|
||||
import java.util.*;
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user