Pass -Dcom.samskivert.jdbc.depot.debug=true to have Depot log queries before

they are executed.
This commit is contained in:
Michael Bayne
2008-04-23 23:29:07 +00:00
parent 513ce9aa60
commit 4eb7d9ecd3
3 changed files with 21 additions and 0 deletions
@@ -89,6 +89,10 @@ public abstract class FindAllQuery<T extends PersistentRecord>
_builder.newQuery(new SelectClause<T>(_type, _marsh.getPrimaryKeyFields(), _clauses));
PreparedStatement stmt = _builder.prepare(conn);
try {
if (PersistenceContext.DEBUG) {
log.info("KEY QUERY: " + stmt);
}
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
Key<T> key = _marsh.makePrimaryKey(rs);
@@ -141,6 +145,10 @@ public abstract class FindAllQuery<T extends PersistentRecord>
// and execute it
try {
if (PersistenceContext.DEBUG) {
log.info("VALUE QUERY: " + stmt);
}
ResultSet rs = stmt.executeQuery();
int cnt = 0, dups = 0;
while (rs.next()) {
@@ -193,6 +201,10 @@ public abstract class FindAllQuery<T extends PersistentRecord>
List<T> result = new ArrayList<T>();
PreparedStatement stmt = _builder.prepare(conn);
try {
if (PersistenceContext.DEBUG) {
log.info("QUERY: " + stmt);
}
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
result.add(_marsh.createObject(rs));
@@ -32,6 +32,8 @@ import com.samskivert.jdbc.JDBCUtil;
import com.samskivert.jdbc.depot.clause.QueryClause;
import com.samskivert.jdbc.depot.clause.SelectClause;
import static com.samskivert.jdbc.depot.Log.log;
/**
* The implementation of {@link DepotRepository#find) functionality.
*/
@@ -66,6 +68,10 @@ public class FindOneQuery<T extends PersistentRecord>
{
PreparedStatement stmt = _builder.prepare(conn);
try {
if (PersistenceContext.DEBUG) {
log.info("KEY QUERY: " + stmt);
}
T result = null;
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
@@ -49,6 +49,9 @@ import static com.samskivert.jdbc.depot.Log.log;
*/
public class PersistenceContext
{
/** Allow toggling of query logging and other debug output via a system property. */
public static final boolean DEBUG = Boolean.getBoolean("com.samskivert.jdbc.depot.debug");
/** Map {@link TableGenerator} instances by name. */
public HashMap<String, TableGenerator> tableGenerators = new HashMap<String, TableGenerator>();