openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r406215 [4/10] - in /incubator/openjpa/trunk/openjpa-lib: ./ java/ java/org/ java/org/apache/ java/org/apache/openjpa/ java/org/apache/openjpa/lib/ java/org/apache/openjpa/lib/conf/ java/org/apache/openjpa/lib/jdbc/ java/org/apache/openjpa/...
Date Sun, 14 May 2006 03:26:02 GMT
Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEvent.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEvent.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEvent.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEvent.java Sat May 13 20:25:56 2006
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.jdbc;
+
+
+import java.sql.*;
+import java.util.*;
+
+
+/** 
+ *  <p>A JDBC event.  The event source will be the connection.</p>
+ *  
+ *	@see	JDBCListener
+ *  @author  Marc Prud'hommeaux
+ *  @author  Abe White
+ */
+public class JDBCEvent
+	extends EventObject
+{
+	/** 
+	 *  Type code indicating that a {@link Statement} is being prepared.
+	 */
+	public static final short BEFORE_PREPARE_STATEMENT = 1;
+
+	/** 
+	 *  Type code indicating that a {@link Statement} is being prepared.
+	 */
+	public static final short AFTER_PREPARE_STATEMENT = 2;
+
+	/** 
+	 *  Type code indicating that a {@link Statement} is being created.
+	 */
+	public static final short BEFORE_CREATE_STATEMENT = 3;
+
+	/** 
+	 *  Type code indicating that a {@link Statement} is being created.
+	 */
+	public static final short AFTER_CREATE_STATEMENT = 4;
+
+	/** 
+	 *  Type code indicating that a {@link Statement} is about to be executed.
+	 */
+	public static final short BEFORE_EXECUTE_STATEMENT = 5;
+
+	/** 
+	 *  Type code indicating that a {@link Statement} completed execution.
+	 */
+	public static final short AFTER_EXECUTE_STATEMENT = 6;
+
+	/** 
+	 *  Type code indicating that a {@link Connection} is about to be committed.
+	 */
+	public static final short BEFORE_COMMIT = 7;
+
+	/** 
+	 *  Type code indicating that a {@link Connection} was just committed.
+	 */
+	public static final short AFTER_COMMIT = 8;
+
+	/** 
+	 *  Type code indicating that a rollback is about to occur.
+	 */
+	public static final short BEFORE_ROLLBACK = 9;
+
+	/** 
+	 *  Type code indicating that a rollback just occured.
+	 */
+	public static final short AFTER_ROLLBACK = 10;
+
+	/**
+	 *	Type code indicating that a connection was obtained.  This does
+	 *	not necessarily mean that the connection is new if pooling is enabled.
+	 */
+	public static final short AFTER_CONNECT = 11;
+
+	/**
+	 *	Type code indicating that a connection was closed.  This does
+	 *	not necessarily mean that the underlying database connection was 
+	 *	severed if pooling is enabled.
+	 */
+	public static final short BEFORE_CLOSE = 12;
+
+	private final short					type;
+	private final long 					time;
+	private final String				sql;
+	private final JDBCEvent 			associatedEvent;
+	private final transient Statement 	statement;
+
+
+	/**
+	 *	Constructor.
+	 */
+	public JDBCEvent (Connection source, short type, JDBCEvent associatedEvent, 
+		Statement statement, String sql)
+	{
+		super (source);
+		this.type = type;
+		this.time = System.currentTimeMillis ();
+		this.associatedEvent = associatedEvent;
+		this.sql = sql;
+		this.statement = statement;
+	}
+
+
+	/**
+	 *	Return the event's type code.
+	 */
+	public final short getType ()
+	{
+		return type;
+	}
+
+
+	/** 
+	 *  Return the Connection for this event.
+	 */
+	public final Connection getConnection ()
+	{
+		return (Connection) getSource ();
+	}
+
+
+	/**
+	 *	Return the time the event was constructed.
+	 */
+	public final long getTime ()
+	{
+		return time;
+	}
+
+
+	/** 
+	 *  Return the associated {@link JDBCEvent} for this event.
+	 * 	For AFTER_XXX events, this will typically be the JDBCEvent 
+	 *	that was created in the	BEFORE_XXX stage. This may be null when
+	 * 	an association is not appropriate for the event.
+	 */
+	public final JDBCEvent getAssociatedEvent ()
+	{
+		return associatedEvent;
+	}
+
+
+	/**
+	 *	Return the SQL associated with this event; may be null.
+	 */
+	public final String getSQL ()
+	{
+		return sql;
+	}
+
+
+	/** 
+	 *  Return the Statement for this event, may be null for events
+	 * 	unrelated to Statement execution.
+	 */
+	public final Statement getStatement ()
+	{
+		return statement;
+	}
+}
+

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEvent.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEventConnectionDecorator.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEventConnectionDecorator.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEventConnectionDecorator.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEventConnectionDecorator.java Sat May 13 20:25:56 2006
@@ -0,0 +1,381 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.jdbc;
+
+
+import java.sql.*;
+import javax.sql.*;
+import java.util.*;
+
+import org.apache.openjpa.lib.util.*;
+
+
+/**
+ *	<p>Manages the firing of {@link JDBCEvent}s.</p>
+ *
+ *	@author		Abe White
+ *	@nojavadoc
+ */
+public class JDBCEventConnectionDecorator
+	extends AbstractEventManager
+	implements ConnectionDecorator
+{
+	public Connection decorate (Connection conn)
+	{
+		if (!hasListeners ())
+			return conn;
+		return new EventConnection (conn); 
+	}
+
+
+	/**
+	 *	Fire the given event to all listeners.  Prevents creation of an
+	 *	event object when there are no listeners.
+	 */
+	private JDBCEvent fireEvent (Connection source, short type, 
+		JDBCEvent associatedEvent, Statement stmnt, String sql)
+	{
+		if (!hasListeners ())
+			return null;
+
+		JDBCEvent event = new JDBCEvent (source, type, associatedEvent,
+			stmnt, sql);
+		fireEvent (event);
+		return event;
+	}
+
+
+	/**
+	 *	Fire the given event to all listeners.
+	 */
+	protected void fireEvent (Object event, Object listener)
+	{
+		JDBCListener listen = (JDBCListener) listener;
+		JDBCEvent ev = (JDBCEvent) event;
+		switch (ev.getType ())
+		{
+		case JDBCEvent.BEFORE_PREPARE_STATEMENT:
+			listen.beforePrepareStatement (ev);
+			break;
+		case JDBCEvent.AFTER_PREPARE_STATEMENT:
+			listen.afterPrepareStatement (ev);
+			break;
+		case JDBCEvent.BEFORE_CREATE_STATEMENT:
+			listen.beforeCreateStatement (ev);
+			break;
+		case JDBCEvent.AFTER_CREATE_STATEMENT:
+			listen.afterCreateStatement (ev);
+			break;
+		case JDBCEvent.BEFORE_EXECUTE_STATEMENT:
+			listen.beforeExecuteStatement (ev);
+			break;
+		case JDBCEvent.AFTER_EXECUTE_STATEMENT:
+			listen.afterExecuteStatement (ev);
+			break;
+		case JDBCEvent.BEFORE_COMMIT:
+			listen.beforeCommit (ev);
+			break;
+		case JDBCEvent.AFTER_COMMIT:
+			listen.afterCommit (ev);
+			break;
+		case JDBCEvent.BEFORE_ROLLBACK:
+			listen.beforeRollback (ev);
+			break;
+		case JDBCEvent.AFTER_ROLLBACK:
+			listen.afterRollback (ev);
+			break;
+		case JDBCEvent.AFTER_CONNECT:
+			listen.afterConnect (ev);
+			break;
+		case JDBCEvent.BEFORE_CLOSE:
+			listen.beforeClose (ev);
+			break;
+		}
+	}
+
+	
+	/**
+	 *	Fires events as appropriate.
+	 */
+	private class EventConnection
+		extends DelegatingConnection
+	{
+		public EventConnection (Connection conn)
+		{
+			super (conn);
+			fireEvent (getDelegate (), JDBCEvent.AFTER_CONNECT, 
+				null, null, null);
+		}
+
+
+		public void commit ()
+			throws SQLException
+		{
+			JDBCEvent before = fireEvent (getDelegate (), 
+				JDBCEvent.BEFORE_COMMIT, null, null, null);
+			try
+			{ 
+				super.commit ();
+			}
+			finally
+			{
+				fireEvent (getDelegate (), JDBCEvent.AFTER_COMMIT, before,
+					null, null);	
+			}
+		}
+
+
+		public void rollback ()
+			throws SQLException
+		{
+			JDBCEvent before = fireEvent (getDelegate (), 
+				JDBCEvent.BEFORE_ROLLBACK, null, null, null);
+			try
+			{ 
+				super.rollback ();
+			}
+			finally
+			{
+				fireEvent (getDelegate (), JDBCEvent.AFTER_ROLLBACK, before, 
+					null, null);	
+			}
+		}
+
+
+		protected Statement createStatement (boolean wrap)
+			throws SQLException
+		{
+			JDBCEvent before = fireEvent (getDelegate (), 
+				JDBCEvent.BEFORE_CREATE_STATEMENT, null, null, null);
+			Statement stmnt = null;
+			try
+			{ 
+				stmnt = new EventStatement (super.createStatement (false),
+					EventConnection.this);
+			}
+			finally
+			{
+				fireEvent (getDelegate (), JDBCEvent.AFTER_CREATE_STATEMENT, 
+					before, stmnt, null);	
+			}
+			return stmnt;
+		}
+
+
+		protected Statement createStatement (int rsType, int rsConcur, 
+			boolean wrap)
+			throws SQLException
+		{
+			JDBCEvent before = fireEvent (getDelegate (), 
+				JDBCEvent.BEFORE_CREATE_STATEMENT, null, null, null);
+			Statement stmnt = null;
+			try
+			{ 
+				stmnt = new EventStatement (super.createStatement 
+					(rsType, rsConcur, false), EventConnection.this);
+			}
+			finally
+			{
+				fireEvent (getDelegate (), JDBCEvent.AFTER_CREATE_STATEMENT, 
+					before, stmnt, null);	
+			}
+			return stmnt;
+		}
+
+
+		protected PreparedStatement prepareStatement (String sql, boolean wrap)
+			throws SQLException
+		{
+			JDBCEvent before = fireEvent (getDelegate (), 
+				JDBCEvent.BEFORE_PREPARE_STATEMENT, null, null, sql);
+			PreparedStatement stmnt = null;
+			try
+			{ 
+				stmnt = new EventPreparedStatement (super.prepareStatement 
+					(sql, false), EventConnection.this, sql); 
+			}
+			finally
+			{
+				fireEvent (getDelegate (), JDBCEvent.AFTER_PREPARE_STATEMENT, 
+					before, stmnt, sql);	
+			}
+			return stmnt;
+		}
+
+
+		protected PreparedStatement prepareStatement (String sql, int rsType,
+			int rsConcur, boolean wrap)
+			throws SQLException
+		{
+			JDBCEvent before = fireEvent (getDelegate (), 
+				JDBCEvent.BEFORE_PREPARE_STATEMENT, null, null, sql);
+			PreparedStatement stmnt = null;
+			try
+			{ 
+				stmnt = new EventPreparedStatement (super.prepareStatement 
+					(sql, rsType, rsConcur, false), EventConnection.this, sql);
+			}
+			finally
+			{
+				fireEvent (getDelegate (), JDBCEvent.AFTER_PREPARE_STATEMENT, 
+					before, stmnt, sql);	
+			}
+			return stmnt;
+		}
+
+
+		public void close ()
+			throws SQLException
+		{
+			try
+			{
+				fireEvent (getDelegate (), JDBCEvent.BEFORE_CLOSE,
+					null, null, null);
+			}
+			finally
+			{
+				super.close ();
+			}
+		}
+	}
+
+
+	/**
+	 *	Fires events as appropriate.
+	 */
+	private class EventPreparedStatement
+		extends DelegatingPreparedStatement
+	{
+		private final EventConnection	_conn;
+		private final String 			_sql;
+
+
+		public EventPreparedStatement (PreparedStatement ps, 
+			EventConnection conn, String sql)
+		{
+			super (ps, conn);
+			_conn = conn;
+			_sql = sql;
+		}
+
+
+		public int executeUpdate ()
+			throws SQLException
+		{
+			JDBCEvent before = fireEvent (_conn.getDelegate (), 
+				JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate (), _sql);
+			try
+			{ 
+				return super.executeUpdate ();
+			}
+			finally
+			{
+				fireEvent (_conn.getDelegate (), 
+					JDBCEvent.AFTER_EXECUTE_STATEMENT, before, 
+					getDelegate (), _sql);
+			}
+		}
+
+
+		protected ResultSet executeQuery (boolean wrap)
+			throws SQLException
+		{
+			JDBCEvent before = fireEvent (_conn.getDelegate (), 
+				JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate (), _sql);
+			try
+			{ 
+				return super.executeQuery (wrap);
+			}
+			finally
+			{
+				fireEvent (_conn.getDelegate (), 
+					JDBCEvent.AFTER_EXECUTE_STATEMENT, before, 
+					getDelegate (), _sql);
+			}
+		}
+
+
+		public int[] executeBatch ()
+			throws SQLException
+		{
+			JDBCEvent before = fireEvent (_conn.getDelegate (), 
+				JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate (), _sql);
+			try
+			{ 
+				return super.executeBatch ();
+			}
+			finally
+			{
+				fireEvent (_conn.getDelegate (), 
+					JDBCEvent.AFTER_EXECUTE_STATEMENT, before, 
+					getDelegate (), _sql);
+			}
+		}
+	}
+
+
+	/**
+	 *	Fires events as appropriate.
+	 */
+	private class EventStatement
+		extends DelegatingStatement
+	{
+		private final EventConnection _conn;
+
+
+		public EventStatement (Statement stmnt, EventConnection conn)
+		{
+			super (stmnt, conn);
+			_conn = conn;
+		}
+
+
+		public int executeUpdate (String sql)
+			throws SQLException
+		{
+			JDBCEvent before = fireEvent (_conn.getDelegate (), 
+				JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate (), sql);
+			try
+			{ 
+				return super.executeUpdate (sql);
+			}
+			finally
+			{
+				fireEvent (_conn.getDelegate (), 
+					JDBCEvent.AFTER_EXECUTE_STATEMENT, before, 
+					getDelegate (), sql);
+			}
+		}
+
+
+		protected ResultSet executeQuery (String sql, boolean wrap)
+			throws SQLException
+		{
+			JDBCEvent before = fireEvent (_conn.getDelegate (), 
+				JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate (), sql);
+			try
+			{ 
+				return super.executeQuery (sql, wrap);
+			}
+			finally
+			{
+				fireEvent (_conn.getDelegate (), 
+					JDBCEvent.AFTER_EXECUTE_STATEMENT, before, 
+					getDelegate (), sql);
+			}
+		}
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEventConnectionDecorator.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCListener.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCListener.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCListener.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCListener.java Sat May 13 20:25:56 2006
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.jdbc;
+
+
+/** 
+ *	A listener for all {@link JDBCEvent}s that occur.
+ *
+ *	@see	AbstractJDBCListener
+ *  @author  Marc Prud'hommeaux
+ *	@author	Abe White
+ */
+public interface JDBCListener
+{
+	/**
+	 *	@see JDBCEvent#BEFORE_PREPARE_STATEMENT
+	 */
+	public void beforePrepareStatement (JDBCEvent event);
+
+
+	/**
+	 *	@see JDBCEvent#AFTER_PREPARE_STATEMENT
+	 */
+	public void afterPrepareStatement (JDBCEvent event);
+
+
+	/**
+	 *	@see JDBCEvent#BEFORE_CREATE_STATEMENT
+	 */
+	public void beforeCreateStatement (JDBCEvent event);
+
+
+	/**
+	 *	@see JDBCEvent#AFTER_CREATE_STATEMENT
+	 */
+	public void afterCreateStatement (JDBCEvent event);
+
+
+	/**
+	 *	@see JDBCEvent#BEFORE_EXECUTE_STATEMENT
+	 */
+	public void beforeExecuteStatement (JDBCEvent event);
+
+
+	/**
+	 *	@see JDBCEvent#AFTER_EXECUTE_STATEMENT
+	 */
+	public void afterExecuteStatement (JDBCEvent event);
+
+
+	/**
+	 *	@see JDBCEvent#BEFORE_COMMIT
+	 */
+	public void beforeCommit (JDBCEvent event);
+
+
+	/**
+	 *	@see JDBCEvent#AFTER_COMMIT
+	 */
+	public void afterCommit (JDBCEvent event);
+
+
+	/**
+	 *	@see JDBCEvent#BEFORE_ROLLBACK
+	 */
+	public void beforeRollback (JDBCEvent event);
+
+
+	/**
+	 *	@see JDBCEvent#AFTER_ROLLBACK
+	 */
+	public void afterRollback (JDBCEvent event);
+
+
+	/**
+	 *	@see JDBCEvent#AFTER_CONNECT
+	 */
+	public void afterConnect (JDBCEvent event);
+
+
+	/**
+	 *	@see JDBCEvent#BEFORE_CLOSE
+	 */
+	public void beforeClose (JDBCEvent event);
+}
+

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCListener.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/LoggingConnectionDecorator.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/LoggingConnectionDecorator.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/LoggingConnectionDecorator.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/LoggingConnectionDecorator.java Sat May 13 20:25:56 2006
@@ -0,0 +1,1775 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.jdbc;
+
+
+import java.io.*;
+import java.math.*;
+import java.sql.*;
+import java.sql.Date;
+import java.util.*;
+import javax.sql.*;
+
+import org.apache.openjpa.lib.log.*;
+
+
+/** 
+ *  A {@link ConnectionDecorator} that creates logging connections and
+ *	{@link ReportingSQLException}s.
+ *  
+ *  @author  Marc Prud'hommeaux
+ *	@nojavadoc
+ */
+public class LoggingConnectionDecorator
+	implements ConnectionDecorator
+{
+	private static final String SEP = System.getProperty ("line.separator");
+
+	private static final int WARN_IGNORE = 0;
+   	private static final int WARN_LOG_TRACE = 1;
+   	private static final int WARN_LOG_INFO = 2;
+   	private static final int WARN_LOG_WARN = 3;
+   	private static final int WARN_LOG_ERROR = 4;
+   	private static final int WARN_THROW = 5;
+   	private static final int WARN_HANDLE = 6;
+   	private static final String[] WARNING_ACTIONS = new String[7];
+	static
+   	{
+		WARNING_ACTIONS[WARN_IGNORE] = "ignore";
+		WARNING_ACTIONS[WARN_LOG_TRACE] = "trace";
+		WARNING_ACTIONS[WARN_LOG_INFO] = "info";
+		WARNING_ACTIONS[WARN_LOG_WARN] = "warn";
+		WARNING_ACTIONS[WARN_LOG_ERROR] = "error";
+		WARNING_ACTIONS[WARN_THROW] = "throw";
+		WARNING_ACTIONS[WARN_HANDLE] = "handle";
+	}
+
+	private final DataSourceLogs _logs = new DataSourceLogs ();
+	private SQLFormatter _formatter;
+	private boolean _prettyPrint;
+	private int _prettyPrintLineLength = 60;
+	private int _warningAction = WARN_IGNORE;
+   	private SQLWarningHandler _warningHandler;
+   	private boolean _trackParameters = true;
+
+
+	/**
+	 *	If set to <code>true</code>, pretty-print SQL by running it
+	 *	through {@link SQLFormatter#prettyPrint}. If
+	 *	<code>false</code>, don't pretty-print, and output SQL logs in
+	 *	a single line. Pretty-printed SQL can be easier for a human to
+	 *	read, but is harder to parse with tools like grep.
+	 */
+	public void setPrettyPrint (boolean prettyPrint)
+	{
+		_prettyPrint = prettyPrint;
+		if (_formatter == null && _prettyPrint)
+		{
+			_formatter = new SQLFormatter ();
+			_formatter.setLineLength (_prettyPrintLineLength);
+		}
+		else if (!_prettyPrint)
+			_formatter = null;
+	}
+
+
+	/**
+	 *	@see {@link #setPrettyPrint}
+	 */
+	public boolean getPrettyPrint ()
+	{
+		return _prettyPrint;
+	}
+
+
+	/**
+	 *	The number of characters to print per line when
+	 *	pretty-printing of SQL is enabled. Defaults to 60 to provide
+	 *	some space for any ant-related characters on the left of a
+	 *	standard 80-character display.
+	 */
+	public void setPrettyPrintLineLength (int length)
+	{
+		_prettyPrintLineLength = length;
+		if (_formatter != null)
+			_formatter.setLineLength (length);
+	}
+
+
+	/**
+	 *	@see {@link #setPrettyPrintLineLength}
+	 */
+	public int getPrettyPrintLineLength ()
+	{
+		return _prettyPrintLineLength;
+	}
+
+
+	/** 
+	 *  Whether to track parameters for the purposes of reporting exceptions. 
+	 */
+	public void setTrackParameters (boolean trackParameters)
+	{
+		_trackParameters = trackParameters;
+	}
+
+
+	/** 
+	 *  Whether to track parameters for the purposes of reporting exceptions. 
+	 */
+	public boolean getTrackParameters ()
+	{
+		return _trackParameters;
+	}
+
+
+	/**
+	 *	What to do with SQL warnings.
+	 */
+	public void setWarningAction (String warningAction)
+	{
+		int index = Arrays.asList (WARNING_ACTIONS).indexOf (warningAction);
+		if (index < 0)
+			index = WARN_IGNORE;
+		_warningAction = index;
+	}
+
+
+	/**
+	 *	What to do with SQL warnings.
+	 */
+	public String getWarningAction ()
+	{
+		return WARNING_ACTIONS[_warningAction];
+	}
+
+
+	/**
+	 *	What to do with SQL warnings.
+	 */
+	public void setWarningHandler (SQLWarningHandler warningHandler)
+	{
+		_warningHandler = warningHandler;
+	}
+
+
+	/**
+	 *	What to do with SQL warnings.
+	 */
+	public SQLWarningHandler getWarningHandler ()
+	{
+		return _warningHandler;
+	}
+
+
+	/**
+	 *	The log to write to.
+	 */
+	public DataSourceLogs getLogs ()
+	{
+		return _logs;
+	}
+
+
+	public Connection decorate (Connection conn)
+		throws SQLException
+	{
+		return new LoggingConnection (conn);
+	}
+
+
+	private SQLException wrap (SQLException sqle, Statement stmnt)
+	{
+		if (sqle instanceof ReportingSQLException)
+			return (ReportingSQLException)sqle;
+
+		return new ReportingSQLException (sqle, stmnt);
+	}
+
+
+	private SQLException wrap (SQLException sqle, String sql)
+	{
+		if (sqle instanceof ReportingSQLException)
+			return (ReportingSQLException)sqle;
+
+		return new ReportingSQLException (sqle, sql);
+	}
+
+
+	private static String getExceptionMessage (SQLException sqle,
+		Statement stmnt)
+	{
+		try
+		{
+			return sqle.getMessage () + " {" + stmnt + "} "
+				+ "[code=" + sqle.getErrorCode () + ", state="
+				+ sqle.getSQLState () + "]";
+		}
+		catch (Throwable t)
+		{
+			return sqle.getMessage ();
+		}
+	}
+
+
+	/** 
+	 *  Interface that allows customization of what to do when
+	 *  {@link SQLWarning}s occur.
+	 */
+	public static interface SQLWarningHandler
+	{
+		public void handleWarning (SQLWarning warning)
+			throws SQLException;
+	}
+
+
+	private class LoggingConnection
+		extends DelegatingConnection
+	{
+		public LoggingConnection (Connection conn)
+			throws SQLException
+		{
+			super (conn);
+		}
+	
+	
+    	protected PreparedStatement prepareStatement (String sql, boolean wrap) 
+			throws SQLException
+		{
+			try
+			{
+				PreparedStatement stmnt = super.prepareStatement (sql, false);
+				return new LoggingPreparedStatement (stmnt, sql);
+			}
+			catch (SQLException se)
+			{
+				throw wrap (se, sql);
+			}
+		}
+	
+	
+    	protected PreparedStatement prepareStatement (String sql, int rsType, 
+			int rsConcur, boolean wrap) 
+			throws SQLException
+		{
+			try
+			{
+				PreparedStatement stmnt = super.prepareStatement 
+					(sql, rsType, rsConcur, false);
+				return new LoggingPreparedStatement (stmnt, sql);
+			}
+			catch (SQLException se)
+			{
+				throw wrap (se, sql);
+			}
+		}
+	
+	
+		protected Statement createStatement (boolean wrap)
+			throws SQLException
+		{
+			Statement stmnt = super.createStatement (false);
+			return new LoggingStatement (stmnt);
+		}
+	
+	
+    	protected Statement createStatement (int type, int concurrency, 
+			boolean wrap) 
+			throws SQLException
+		{
+			Statement stmnt = super.createStatement (type, concurrency, false);
+			return new LoggingStatement (stmnt);
+		}
+	
+	
+		public void commit ()
+			throws SQLException
+		{
+			long start = System.currentTimeMillis ();
+
+			try
+			{
+				super.commit ();
+			}
+			finally
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("commit", start, this);
+				handleSQLWarning ();
+			}
+		}
+	
+	
+		public void rollback ()
+			throws SQLException
+		{
+			long start = System.currentTimeMillis ();
+
+			try
+			{
+				super.rollback ();
+			}
+			finally
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("rollback", start, this);
+				handleSQLWarning ();
+			}
+		}
+	
+	
+		public void close ()
+			throws SQLException
+		{
+			long start = System.currentTimeMillis ();
+
+			try
+			{
+				super.close ();
+			}
+			finally
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("close", start, this);
+			}
+		}
+	
+
+		public Savepoint setSavepoint ()
+			throws SQLException
+		{
+			long start = System.currentTimeMillis ();
+			try
+			{
+				return super.setSavepoint ();
+			}
+			finally
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("savepoint", start, this);
+				handleSQLWarning ();
+			}
+		}
+	
+
+		public Savepoint setSavepoint (String name)
+			throws SQLException
+		{
+			long start = System.currentTimeMillis ();
+			try
+			{
+				return super.setSavepoint (name);
+			}
+			finally
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("savepoint: " + name, start, this);
+				handleSQLWarning ();
+			}
+		}
+
+
+		public void rollback (Savepoint savepoint)
+			throws SQLException
+		{
+			long start = System.currentTimeMillis ();
+			try
+			{
+				super.rollback (savepoint);
+			}
+			finally
+			{
+				if (_logs.isJDBCEnabled ())
+				{
+					String name = null;
+					try
+					{
+						name = savepoint.getSavepointName ();
+					}
+					catch (SQLException sqe)
+					{
+						name = String.valueOf (savepoint.getSavepointId ());
+					}
+					_logs.logJDBC ("rollback: " + name, start, this);
+				}
+				handleSQLWarning ();
+			}
+		}
+
+
+		public void releaseSavepoint (Savepoint savepoint)
+			throws SQLException
+		{
+			long start = System.currentTimeMillis ();
+			try
+			{
+				super.releaseSavepoint (savepoint);
+			}
+			finally
+			{
+				if (_logs.isJDBCEnabled ())
+				{
+					String name = null;
+					try
+					{
+						name = savepoint.getSavepointName ();
+					}
+					catch (SQLException sqe)
+					{
+						name = String.valueOf (savepoint.getSavepointId ());
+					}
+					_logs.logJDBC ("release: " + name, start, this);
+				}
+				handleSQLWarning ();
+			}
+		}
+
+
+		protected Statement createStatement (int resultSetType,
+			int resultSetConcurrency, int resultSetHoldability, boolean wrap)
+			throws SQLException
+		{
+			Statement stmnt = super.createStatement (resultSetType, 
+				resultSetConcurrency, resultSetHoldability, false);
+			handleSQLWarning ();
+			return new LoggingStatement (stmnt);
+		}
+
+
+		protected PreparedStatement prepareStatement (String sql, 
+			int resultSetType, int resultSetConcurrency, 
+			int resultSetHoldability, boolean wrap)
+			throws SQLException
+		{
+			try
+			{
+				PreparedStatement stmnt = super.prepareStatement 
+					(sql, resultSetType, resultSetConcurrency, 
+					resultSetHoldability, false);
+				handleSQLWarning ();
+				return new LoggingPreparedStatement (stmnt, sql);
+			}
+			catch (SQLException se)
+			{
+				throw wrap (se, sql);
+			}
+		}
+
+
+		protected PreparedStatement prepareStatement (String sql, 
+			int autoGeneratedKeys, boolean wrap)
+			throws SQLException
+		{
+			try
+			{
+				PreparedStatement stmnt = super.prepareStatement 
+					(sql, autoGeneratedKeys, false);
+				handleSQLWarning ();
+				return new LoggingPreparedStatement (stmnt, sql);
+			}
+			catch (SQLException se)
+			{
+				throw wrap (se, sql);
+			}
+		}
+
+
+		protected PreparedStatement prepareStatement (String sql, 
+			int[] columnIndexes, boolean wrap)
+			throws SQLException
+		{
+			try
+			{
+				PreparedStatement stmnt = super.prepareStatement 
+					(sql, columnIndexes, false);
+				handleSQLWarning ();
+				return new LoggingPreparedStatement (stmnt, sql);
+			}
+			catch (SQLException se)
+			{
+				throw wrap (se, sql);
+			}
+		}
+
+
+		protected PreparedStatement prepareStatement (String sql, 
+			String[] columnNames, boolean wrap)
+			throws SQLException
+		{
+			try
+			{
+				PreparedStatement stmnt = super.prepareStatement 
+					(sql, columnNames, false);
+				handleSQLWarning ();
+				return new LoggingPreparedStatement (stmnt, sql);
+			}
+			catch (SQLException se)
+			{
+				throw wrap (se, sql);
+			}
+		}
+
+
+		protected DatabaseMetaData getMetaData (boolean wrap)
+			throws SQLException
+		{
+			return new LoggingDatabaseMetaData (super.getMetaData (false));
+		}
+
+
+		/** 
+		 *  Handle any {@link SQLWarning}s on the current {@link Connection}.
+		 *
+		 *  @see #handleSQLWarning(SQLWarning) 
+		 */
+		private void handleSQLWarning ()
+			throws SQLException
+		{
+			if (_warningAction == WARN_IGNORE)
+				return;
+
+			try
+			{
+				handleSQLWarning (getWarnings ());
+			}
+			finally
+			{
+				clearWarnings ();
+			}
+		}
+
+
+		/** 
+		 *  Handle any {@link SQLWarning}s on the specified {@link Statement}.
+		 *
+		 *  @see #handleSQLWarning(SQLWarning)
+		 */
+		private void handleSQLWarning (Statement stmnt)
+			throws SQLException
+		{
+			if (_warningAction == WARN_IGNORE)
+				return;
+
+			try
+			{
+				handleSQLWarning (stmnt.getWarnings ());
+			}
+			finally
+			{
+				stmnt.clearWarnings ();
+			}
+		}
+
+
+		/** 
+		 *  Handle any {@link SQLWarning}s on the specified {@link ResultSet}.
+		 *
+		 *  @see #handleSQLWarning(SQLWarning)
+		 */
+		private void handleSQLWarning (ResultSet rs)
+			throws SQLException
+		{
+			if (_warningAction == WARN_IGNORE)
+				return;
+
+			try
+			{
+				handleSQLWarning (rs.getWarnings ());
+			}
+			finally
+			{
+				rs.clearWarnings ();
+			}
+		}
+
+
+		/** 
+		 *  Handle the specified {@link SQLWarning} depending on the
+		 *  setting of the {@link #setWarningAction} attribute.
+		 *  
+		 *  @param  warning  the warning to handle
+		 */
+		void handleSQLWarning (SQLWarning warning)
+			throws SQLException
+		{
+			if (warning == null)
+				return;
+			if (_warningAction == WARN_IGNORE)
+				return;
+
+			Log log = _logs.getJDBCLog ();
+			for ( ; warning != null; warning = warning.getNextWarning ())
+			{
+				switch (_warningAction)
+				{
+				case WARN_LOG_TRACE:
+					if (log.isTraceEnabled ())
+						log.trace (warning);
+					break;
+				case WARN_LOG_INFO:
+					if (log.isInfoEnabled ())
+						log.info (warning);
+					break;
+				case WARN_LOG_WARN:
+					if (log.isWarnEnabled ())
+						log.warn (warning);
+					break;
+				case WARN_LOG_ERROR:
+					if (log.isErrorEnabled ())
+						log.error (warning);
+					break;
+				case WARN_THROW:
+					// just throw it as if it were a SQLException
+					throw warning;
+				case WARN_HANDLE:
+					if (_warningHandler != null)
+						_warningHandler.handleWarning (warning);
+					break;
+				default:
+					// ignore
+					break;
+				}
+			}
+		}
+
+
+		private class LoggingDatabaseMetaData
+			extends DelegatingDatabaseMetaData
+		{
+			public LoggingDatabaseMetaData (DatabaseMetaData meta)
+			{
+				super (meta, LoggingConnection.this);
+			}
+
+
+			public ResultSet getBestRowIdentifier (String catalog,
+				String schema, String table, int scope, boolean nullable)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getBestRowIdentifier: "
+						+ catalog + ", " + schema + ", " + table, 
+						LoggingConnection.this);
+				return super.getBestRowIdentifier (catalog, schema,
+					table, scope, nullable);
+			}
+		
+		
+			public ResultSet getCatalogs ()
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getCatalogs", 
+						LoggingConnection.this);
+				return super.getCatalogs ();
+			}
+		
+		
+			public ResultSet getColumnPrivileges (String catalog, String schema,
+				String table, String columnNamePattern)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getColumnPrivileges: " 
+						+ catalog + ", " + schema + ", " + table, 
+						LoggingConnection.this);
+				return super.getColumnPrivileges (catalog, schema,
+					table, columnNamePattern);
+			}
+		
+		
+			public ResultSet getColumns (String catalog, String schemaPattern,
+				String tableNamePattern, String columnNamePattern)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getColumns: "
+						+ catalog + ", " + schemaPattern + ", "
+						+ tableNamePattern + ", " + columnNamePattern, 
+						LoggingConnection.this);
+				return super.getColumns (catalog, schemaPattern,
+					tableNamePattern, columnNamePattern);
+			}
+		
+		
+			public ResultSet getCrossReference (String primaryCatalog,
+				String primarySchema, String primaryTable,
+				String foreignCatalog, String foreignSchema,
+				String foreignTable)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getCrossReference: "
+						+ primaryCatalog + ", " + primarySchema + ", "
+						+ primaryTable + ", " + foreignCatalog + ", "
+						+ foreignSchema + ", " + foreignSchema, 
+						LoggingConnection.this);
+				return super.getCrossReference (primaryCatalog, primarySchema,
+					primaryTable, foreignCatalog, foreignSchema, foreignTable);
+			}
+		
+		
+			public ResultSet getExportedKeys (String catalog, String schema,
+				String table)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getExportedKeys: "
+						+ catalog + ", " + schema + ", " + table, 
+						LoggingConnection.this);
+				return super.getExportedKeys (catalog, schema, table);
+			}
+		
+		
+			public ResultSet getImportedKeys (String catalog, String schema,
+				String table)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getImportedKeys: "
+						+ catalog + ", " + schema + ", " + table, 
+						LoggingConnection.this);
+				return super.getImportedKeys (catalog, schema, table);
+			}
+		
+		
+			public ResultSet getIndexInfo (String catalog, String schema,
+				String table, boolean unique, boolean approximate)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getIndexInfo: "
+						+ catalog + ", " + schema + ", " + table, 
+						LoggingConnection.this);
+				return super.getIndexInfo (catalog, schema, table, unique,
+					approximate);
+			}
+		
+		
+			public ResultSet getPrimaryKeys (String catalog, String schema,
+				String table)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getPrimaryKeys: "
+						+ catalog + ", " + schema + ", " + table, 
+						LoggingConnection.this);
+				return super.getPrimaryKeys (catalog, schema, table);
+			}
+		
+		
+			public ResultSet getProcedureColumns (String catalog,
+				String schemaPattern, String procedureNamePattern,
+				String columnNamePattern)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getProcedureColumns: "
+						+ catalog + ", " + schemaPattern + ", "
+						+ procedureNamePattern + ", " + columnNamePattern, 
+						LoggingConnection.this);
+				return super.getProcedureColumns (catalog, schemaPattern,
+					procedureNamePattern, columnNamePattern);
+			}
+		
+		
+			public ResultSet getProcedures (String catalog,
+				String schemaPattern, String procedureNamePattern)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getProcedures: "
+						+ catalog + ", " + schemaPattern + ", "
+						+ procedureNamePattern, 
+						LoggingConnection.this);
+				return super.getProcedures (catalog, schemaPattern,
+					procedureNamePattern);
+			}
+		
+		
+			public ResultSet getSchemas ()
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getSchemas", 
+						LoggingConnection.this);
+				return super.getSchemas ();
+			}
+		
+		
+			public ResultSet getTablePrivileges (String catalog,
+				String schemaPattern, String tableNamePattern)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getTablePrivileges", 
+						LoggingConnection.this);
+				return super.getTablePrivileges (catalog, schemaPattern,
+					tableNamePattern);
+			}
+		
+				
+			public ResultSet getTables (String catalog, String schemaPattern,
+				String tableNamePattern, String[] types)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getTables: "
+						+ catalog + ", " + schemaPattern + ", "
+						+ tableNamePattern, 
+						LoggingConnection.this);
+				return super.getTables (catalog, schemaPattern,
+					tableNamePattern, types);
+			}
+		
+		
+			public ResultSet getTableTypes ()
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getTableTypes", 
+						LoggingConnection.this);
+				return super.getTableTypes ();
+			}
+		
+		
+			public ResultSet getTypeInfo ()
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getTypeInfo", 
+						LoggingConnection.this);
+				return super.getTypeInfo ();
+			}
+		
+		
+			public ResultSet getUDTs (String catalog, String schemaPattern,
+				String typeNamePattern, int[] types)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getUDTs", 
+						LoggingConnection.this);
+				return super.getUDTs (catalog, schemaPattern,
+					typeNamePattern, types);
+			}
+		
+		
+			public ResultSet getVersionColumns (String catalog,
+				String schema, String table)
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("getVersionColumns: "
+						+ catalog + ", " + schema + ", " + table, 
+						LoggingConnection.this);
+				return super.getVersionColumns (catalog, schema, table);
+			}
+		}
+	
+	
+		/**
+		 *	Statement wrapper that logs SQL to the parent data source and
+		 *	remembers the last piece of SQL to be executed on it.
+		 */
+		private class LoggingStatement
+			extends DelegatingStatement
+		{
+			private String _sql = null;
+		
+		
+			public LoggingStatement (Statement stmnt)
+				throws SQLException
+			{
+				super (stmnt, LoggingConnection.this);
+			}
+			
+			
+			public void appendInfo (StringBuffer buf)
+			{
+				if (_sql != null)
+				{
+					buf.append (" ");
+					if (_formatter != null)
+					{
+						buf.append (SEP);
+						buf.append (_formatter.prettyPrint (_sql));
+					}
+					else
+					{
+						buf.append (_sql);
+					}
+				}
+			}
+          
+                
+			protected ResultSet wrapResult (ResultSet rs, boolean wrap)
+			{   
+				if (!wrap || rs == null)
+					return super.wrapResult (rs, wrap);
+				return new LoggingResultSet (rs, this);
+			}
+
+
+	    	public void cancel ()
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("cancel " + this + ": " + _sql,
+						LoggingConnection.this);
+
+				super.cancel ();
+			}
+	
+	
+   		 	protected ResultSet executeQuery (String sql, boolean wrap) 
+				throws SQLException
+			{
+				long start = System.currentTimeMillis ();
+
+				_sql = sql;
+				try
+				{
+					return super.executeQuery (sql, wrap);
+				}
+				catch (SQLException se)
+				{
+					throw wrap (se, LoggingStatement.this);
+				}
+				finally
+				{
+					if (_logs.isSQLEnabled ())
+						_logs.logSQL ("executing " + this, start, 
+							LoggingConnection.this);
+					handleSQLWarning (LoggingStatement.this);
+				}
+			}
+		
+		
+	    	public int executeUpdate (String sql) 
+				throws SQLException
+			{
+				long start = System.currentTimeMillis ();
+
+				_sql = sql;
+				try
+				{
+					return super.executeUpdate (sql);
+				}
+				catch (SQLException se)
+				{
+					throw wrap (se, LoggingStatement.this);
+				}
+				finally
+				{
+					if (_logs.isSQLEnabled ())
+						_logs.logSQL ("executing " + this, start, 
+							LoggingConnection.this);
+					handleSQLWarning (LoggingStatement.this);
+				}
+			}
+		
+		
+	    	public boolean execute (String sql) 
+				throws SQLException
+			{
+				long start = System.currentTimeMillis ();
+
+				_sql = sql;
+				try
+				{
+					return super.execute (sql);
+				}
+				catch (SQLException se)
+				{
+					throw wrap (se, LoggingStatement.this);
+				}
+				finally
+				{
+					if (_logs.isSQLEnabled ())
+						_logs.logSQL ("executing " + this, start, 
+							LoggingConnection.this);
+					handleSQLWarning (LoggingStatement.this);
+				}
+			}
+		}
+	
+	
+		private class LoggingPreparedStatement
+			extends DelegatingPreparedStatement
+		{
+			private final String 	_sql;
+			private List			_params	= null;
+			private List			_paramBatch = null;
+	
+	
+			public LoggingPreparedStatement (PreparedStatement stmnt,
+				String sql)
+				throws SQLException
+			{
+				super (stmnt, LoggingConnection.this);
+				_sql = sql;
+			}
+
+
+			protected ResultSet wrapResult (ResultSet rs, boolean wrap)
+			{
+				if (!wrap || rs == null)
+					return super.wrapResult (rs, wrap);
+				return new LoggingResultSet (rs, this);
+			}
+		
+		
+	    	protected ResultSet executeQuery (String sql, boolean wrap) 
+				throws SQLException
+			{
+				long start = System.currentTimeMillis ();
+
+				try
+				{
+					return super.executeQuery (sql, wrap);
+				}
+				catch (SQLException se)
+				{
+					throw wrap (se, LoggingPreparedStatement.this);
+				}
+				finally
+				{
+					log ("executing", start);
+					clearLogParameters (true);
+					handleSQLWarning (LoggingPreparedStatement.this);
+				}
+			}
+		
+		
+	    	public int executeUpdate (String sql) 
+				throws SQLException
+			{
+				long start = System.currentTimeMillis ();
+
+				try
+				{
+					return super.executeUpdate (sql);
+				}
+				catch (SQLException se)
+				{
+					throw wrap (se, LoggingPreparedStatement.this);
+				}
+				finally
+				{
+					log ("executing", start);
+					clearLogParameters (true);
+					handleSQLWarning (LoggingPreparedStatement.this);
+				}
+			}
+		
+		
+	    	public boolean execute (String sql) 
+				throws SQLException
+			{
+				long start = System.currentTimeMillis ();
+
+				try
+				{
+					return super.execute (sql);
+				}
+				catch (SQLException se)
+				{
+					throw wrap (se, LoggingPreparedStatement.this);
+				}
+				finally
+				{
+					log ("executing", start);
+					clearLogParameters (true);
+					handleSQLWarning (LoggingPreparedStatement.this);
+				}
+			}
+	
+	
+			protected ResultSet executeQuery (boolean wrap) 
+				throws SQLException
+			{
+				long start = System.currentTimeMillis ();
+
+				try
+				{
+					return super.executeQuery (wrap);
+				}
+				catch (SQLException se)
+				{
+					throw wrap (se, LoggingPreparedStatement.this);
+				}
+				finally
+				{
+					log ("executing", start);
+					clearLogParameters (true);
+					handleSQLWarning (LoggingPreparedStatement.this);
+				}
+			}
+	
+	
+			public int executeUpdate  () 
+				throws SQLException
+			{
+				long start = System.currentTimeMillis ();
+
+				try
+				{
+					return super.executeUpdate ();
+				}
+				catch (SQLException se)
+				{
+					throw wrap (se, LoggingPreparedStatement.this);
+				}
+				finally
+				{
+					log ("executing", start);
+					clearLogParameters (true);
+					handleSQLWarning (LoggingPreparedStatement.this);
+				}
+			}
+	
+	
+			public int[] executeBatch ()
+				throws SQLException
+			{
+				long start = System.currentTimeMillis ();
+
+				try
+				{
+					return super.executeBatch ();
+				}
+				catch (SQLException se)
+				{
+					// if the exception is a BatchUpdateException, and
+					// we are tracking parameters, then set the current
+					// parameter set to be the index of the failed
+					// statement so that the ReportingSQLException will
+					// show the correct param
+					if (se instanceof BatchUpdateException 
+						&& _paramBatch != null && shouldTrackParameters ())
+					{
+						int[] count = ((BatchUpdateException)se).
+							getUpdateCounts ();
+						if (count != null && count.length <= _paramBatch.size())
+						{
+							int index = -1;
+							for (int i = 0; i < count.length; i++)
+							{
+								// -3 is Statement.STATEMENT_FAILED, but is
+								// only available in JDK 1.4+
+								if (count[i] == -3)
+								{
+									index = i;
+									break;
+								}
+							}
+
+							// no -3 element: it may be that the server stopped
+							// processing, so the size of the count will be
+							// the index
+							if (index == -1)
+								index = count.length + 1;
+
+							// set the current params to the saved values
+							if (index < _paramBatch.size ())
+								_params = (List)_paramBatch.get (index);
+						}
+					}
+					throw wrap (se, LoggingPreparedStatement.this);
+				}	
+				finally
+				{
+					log ("executing batch", start);
+					clearLogParameters (true);
+					handleSQLWarning (LoggingPreparedStatement.this);
+				}
+			}
+		
+		
+	    	public boolean execute () 
+				throws SQLException
+			{
+				long start = System.currentTimeMillis ();
+
+				try
+				{
+					return super.execute ();
+				}
+				catch (SQLException se)
+				{
+					throw wrap (se, LoggingPreparedStatement.this);
+				}
+				finally
+				{
+					log ("executing", start);
+					clearLogParameters (true);
+					handleSQLWarning (LoggingPreparedStatement.this);
+				}
+			}
+
+
+	    	public void cancel ()
+				throws SQLException
+			{
+				if (_logs.isJDBCEnabled ())
+					_logs.logJDBC ("cancel " + this + ": " + _sql,
+						LoggingConnection.this);
+
+				super.cancel ();
+			}
+	
+	
+			public void setNull (int i1, int i2) 
+				throws SQLException
+			{
+				setLogParameter (i1, "null", null);
+				super.setNull (i1, i2);
+			}
+	
+	
+			public void setBoolean (int i, boolean b) 
+				throws SQLException
+			{
+				setLogParameter (i, b);
+				super.setBoolean (i, b);
+			}
+		
+		
+			public void setByte (int i, byte b) 
+				throws SQLException
+			{
+				setLogParameter (i, b);
+				super.setByte (i,b);
+			}
+		
+		
+			public void setShort (int i, short s) 
+				throws SQLException
+			{
+				setLogParameter (i, s);
+				super.setShort (i, s);
+			}
+	
+	
+			public void setInt (int i1, int i2) 
+				throws SQLException
+			{
+				setLogParameter (i1, i2);
+				super.setInt (i1, i2);
+			}
+		
+		
+			public void setLong (int i, long l) 
+				throws SQLException
+			{
+				setLogParameter (i, l);
+				super.setLong (i, l);
+			}
+		
+		
+			public void setFloat (int i, float f) 
+				throws SQLException
+			{
+				setLogParameter (i, f);
+				super.setFloat (i, f);
+			}
+		
+		
+			public void setDouble (int i, double d) 
+				throws SQLException
+			{
+				setLogParameter (i, d);
+				super.setDouble (i, d);
+			}
+		
+		
+			public void setBigDecimal (int i, BigDecimal bd) 
+				throws SQLException
+			{
+				setLogParameter (i, "BigDecimal", bd);
+				super.setBigDecimal (i, bd);
+			}
+		
+		
+			public void setString (int i, String s) 
+				throws SQLException
+			{
+				setLogParameter (i, "String", s);
+				super.setString (i, s);
+			}
+		
+		
+			public void setBytes (int i, byte[] b) 
+				throws SQLException
+			{
+				setLogParameter (i, "byte[]", b);
+				super.setBytes (i, b);
+			}
+		
+		
+			public void setDate (int i, Date d) 
+				throws SQLException
+			{
+				setLogParameter (i, "Date", d);
+				super.setDate (i, d);
+			}
+		
+		
+			public void setTime (int i, Time t) 
+				throws SQLException
+			{
+				setLogParameter (i, "Time", t);
+				super.setTime (i, t);
+			}
+		
+		
+			public void setTimestamp (int i, Timestamp t) 
+				throws SQLException
+			{
+				setLogParameter (i, "Timestamp", t);
+				super.setTimestamp (i, t);
+			}
+		
+		
+			public void setAsciiStream (int i1, InputStream is, int i2) 
+				throws SQLException
+			{
+				setLogParameter (i1, "InputStream", is);
+				super.setAsciiStream (i1, is, i2);
+			}
+		
+		
+			public void setUnicodeStream (int i1, InputStream is, int i2) 
+				throws SQLException
+			{
+				setLogParameter (i1, "InputStream", is);
+				super.setUnicodeStream (i2, is, i2);
+			}
+		
+		
+			public void setBinaryStream (int i1, InputStream is, int i2) 
+				throws SQLException
+			{
+				setLogParameter (i1, "InputStream", is);
+				super.setBinaryStream (i1, is, i2);
+			}
+		
+		
+	    	public void clearParameters () 
+				throws SQLException
+			{
+				clearLogParameters (false);
+				super.clearParameters ();
+			}
+		
+		
+			public void setObject (int i1, Object o, int i2, int i3) 
+				throws SQLException
+			{
+				setLogParameter (i1, "Object", o);
+				super.setObject (i1, o, i2, i3);
+			}
+		
+		
+			public void setObject (int i1, Object o, int i2)
+				throws SQLException
+			{
+				setLogParameter (i1, "Object", o);
+				super.setObject (i1, o, i2);
+			}
+		
+		
+			public void setObject (int i, Object o) 
+				throws SQLException
+			{
+				setLogParameter (i, "Object", o);
+				super.setObject (i, o);
+			}
+		
+		
+	    	public void addBatch () 
+				throws SQLException
+			{
+				long start = System.currentTimeMillis ();
+
+				try
+				{
+					super.addBatch ();
+					if (shouldTrackParameters ())
+					{
+						// make sure our list is initialized
+						if (_paramBatch == null) 
+							_paramBatch = new ArrayList ();
+                        // copy parameters since they will be re-used
+						if (_params != null)
+							_paramBatch.add (new ArrayList (_params));
+						else
+							_paramBatch.add (null);
+                    }
+				}
+				finally
+				{
+					log ("batching", start);
+				}
+			}
+		
+		
+			public void setCharacterStream (int i1, Reader r, int i2)
+				throws SQLException
+			{
+				setLogParameter (i1, "Reader", r);
+				super.setCharacterStream (i1, r, i2);
+			}
+		
+		
+			public void setRef (int i, Ref r) 
+				throws SQLException
+			{
+				setLogParameter (i, "Ref", r);
+				super.setRef (i, r);
+			}
+		
+		
+			public void setBlob (int i, Blob b) 
+				throws SQLException
+			{
+				setLogParameter (i, "Blob", b);
+				super.setBlob (i, b);
+			}
+		
+		
+			public void setClob (int i, Clob c) 
+				throws SQLException
+			{
+				setLogParameter (i, "Clob", c);
+				super.setClob (i, c);
+			}
+		
+		
+			public void setArray (int i, Array a) 
+				throws SQLException
+			{
+				setLogParameter (i, "Array", a);
+				super.setArray (i, a);
+			}
+		
+		
+	    	public ResultSetMetaData getMetaData () 
+				throws SQLException
+			{
+				return super.getMetaData ();
+			}
+		
+		
+			public void setDate (int i, Date d, Calendar c) 
+				throws SQLException
+			{
+				setLogParameter (i, "Date", d);
+				super.setDate (i, d, c);
+			}
+		
+		
+			public void setTime (int i, Time t, Calendar c) 
+				throws SQLException
+			{
+				setLogParameter (i, "Time", t);
+				super.setTime (i, t, c);
+			}
+		
+		
+			public void setTimestamp (int i, Timestamp t, Calendar c) 
+				throws SQLException
+			{
+				setLogParameter (i, "Timestamp", t);
+				super.setTimestamp (i, t, c);
+			}
+		
+		
+			public void setNull (int i1, int i2, String s) 
+				throws SQLException
+			{
+				setLogParameter (i1, "null", null);
+				super.setNull (i1, i2, s);
+			}
+	
+	
+			protected void appendInfo (StringBuffer buf)
+			{
+				buf.append (" ");
+				if (_formatter != null)
+				{
+					buf.append (SEP);
+					buf.append (_formatter.prettyPrint (_sql));
+					buf.append (SEP);
+				}
+				else
+				{
+					buf.append (_sql);
+				}
+	
+				StringBuffer paramBuf = null;
+				if (_params != null && !_params.isEmpty ())
+				{
+					paramBuf = new StringBuffer ();
+					for (Iterator itr = _params.iterator (); itr.hasNext ();)
+					{
+						paramBuf.append (itr.next ());
+						if (itr.hasNext ())
+							paramBuf.append (", ");
+					}
+				}
+	
+				if (paramBuf != null)
+				{
+					if (!_prettyPrint)
+						buf.append (" ");
+					buf.append ("[params=").
+						append (paramBuf.toString ()).append ("]");
+				}
+				super.appendInfo (buf);
+			}
+	
+	
+			private void log (String msg, long startTime)
+				throws SQLException
+			{
+				if (_logs.isSQLEnabled ())
+					_logs.logSQL (msg + " " + this, startTime,
+						LoggingConnection.this);
+			}
+	
+	
+			private void clearLogParameters (boolean batch)
+			{
+				if (_params != null)
+					_params.clear ();
+				if (batch && _paramBatch != null)
+					_paramBatch.clear ();
+			}
+
+
+			private boolean shouldTrackParameters ()
+			{
+				return _trackParameters || _logs.isSQLEnabled ();
+			}
+	
+	
+			private void setLogParameter (int index, boolean val)
+			{
+				if (shouldTrackParameters ())
+					setLogParameter (index, "(boolean) " + val);
+			}
+	
+	
+			private void setLogParameter (int index, byte val)
+			{
+				if (shouldTrackParameters ())
+					setLogParameter (index, "(byte) " + val);
+			}
+	
+	
+			private void setLogParameter (int index, double val)
+			{
+				if (shouldTrackParameters ())
+					setLogParameter (index, "(double) " + val);
+			}
+	
+	
+			private void setLogParameter (int index, float val)
+			{
+				if (shouldTrackParameters ())
+					setLogParameter (index, "(float) " + val);
+			}
+	
+	
+			private void setLogParameter (int index, int val)
+			{
+				if (shouldTrackParameters ())
+					setLogParameter (index, "(int) " + val);
+			}
+	
+	
+			private void setLogParameter (int index, long val)
+			{
+				if (shouldTrackParameters ())
+					setLogParameter (index, "(long) " + val);
+			}
+	
+	
+			private void setLogParameter (int index, short val)
+			{
+				if (shouldTrackParameters ())
+					setLogParameter (index, "(short) " + val);
+			}
+	
+	
+			private void setLogParameter (int index, String type, Object val)
+			{
+				if (shouldTrackParameters ())
+					setLogParameter (index, "(" + type + ") " + val);
+			}
+	
+	
+			private void setLogParameter (int index, String val)
+			{
+				if (_params == null)
+					_params = new ArrayList ();
+				while (_params.size () < index)
+					_params.add (null);
+				if (val.length () > 80)
+					val = val.substring (0, 77) + "...";
+				_params.set (index - 1, val);
+			}
+		}
+
+
+		private class LoggingResultSet
+			extends DelegatingResultSet
+		{
+			public LoggingResultSet (ResultSet rs, Statement stmnt)
+			{
+				super (rs, stmnt);
+			}
+
+
+			public boolean next ()
+				throws SQLException
+			{
+				try
+				{
+					return super.next ();
+				}
+				finally
+				{
+					handleSQLWarning (LoggingResultSet.this);
+				}
+			}
+
+
+			public void close ()
+				throws SQLException
+			{
+				try
+				{
+					super.close ();
+				}
+				finally
+				{
+					handleSQLWarning (LoggingResultSet.this);
+				}
+			}
+
+
+			public void beforeFirst ()
+				throws SQLException
+			{
+				try
+				{
+					super.beforeFirst ();
+				}
+				finally
+				{
+					handleSQLWarning (LoggingResultSet.this);
+				}
+			}
+
+
+			public void afterLast ()
+				throws SQLException
+			{
+				try
+				{
+					super.afterLast ();
+				}
+				finally
+				{
+					handleSQLWarning (LoggingResultSet.this);
+				}
+			}
+
+
+			public boolean first ()
+				throws SQLException
+			{
+				try
+				{
+					return super.first ();
+				}
+				finally
+				{
+					handleSQLWarning (LoggingResultSet.this);
+				}
+			}
+
+
+			public boolean last ()
+				throws SQLException
+			{
+				try
+				{
+					return super.last ();
+				}
+				finally
+				{
+					handleSQLWarning (LoggingResultSet.this);
+				}
+			}
+
+
+			public boolean absolute (int a)
+				throws SQLException
+			{
+				try
+				{
+					return super.absolute (a);
+				}
+				finally
+				{
+					handleSQLWarning (LoggingResultSet.this);
+				}
+			}
+
+
+			public boolean relative (int a)
+				throws SQLException
+			{
+				try
+				{
+					return super.relative (a);
+				}
+				finally
+				{
+					handleSQLWarning (LoggingResultSet.this);
+				}
+			}
+
+
+			public boolean previous ()
+				throws SQLException
+			{
+				try
+				{
+					return super.previous ();
+				}
+				finally
+				{
+					handleSQLWarning (LoggingResultSet.this);
+				}
+			}
+		}
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/LoggingConnectionDecorator.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/ReportingSQLException.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/ReportingSQLException.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/ReportingSQLException.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/ReportingSQLException.java Sat May 13 20:25:56 2006
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.jdbc;
+
+
+import java.sql.*;
+
+
+/** 
+ *  <p>A {@link SQLException} that contains information about
+ *  the {@link Statement} SQL that caused the exception.</p>
+ *  
+ *  @author  Marc Prud'hommeaux
+ *	@nojavadoc
+ */
+public class ReportingSQLException
+	extends SQLException
+{
+	private final transient Statement	_stmnt;
+	private final SQLException			_sqle;
+
+	public ReportingSQLException (SQLException sqle,
+		Statement stmnt, String sql)
+	{
+		super (getExceptionMessage (sqle, stmnt, sql));
+		this._sqle = sqle;
+		this._stmnt = stmnt;
+		setNextException (sqle);
+	}
+
+
+	public ReportingSQLException (SQLException sqle, String sql)
+	{
+		this (sqle, null, sql);
+	}
+
+
+	public ReportingSQLException (SQLException sqle, Statement stmnt)
+	{
+		this (sqle, stmnt, null);
+	}
+
+
+	/** 
+	 *  Returns the SQL state of the underlying {@link SQLException}.
+	 */
+	public String getSQLState ()
+	{
+		return _sqle.getSQLState ();
+	}
+
+
+	/** 
+	 *  Returns the error code of the underlying {@link SQLException}.
+	 */
+	public int getErrorCode ()
+	{
+		return _sqle.getErrorCode ();
+	}
+
+
+	/** 
+	 *  Returns the {@link Statement} that caused the exception.
+	 */
+	public Statement getStatement ()
+	{
+		return _stmnt;
+	}
+
+
+	private static String getExceptionMessage (SQLException sqle,
+		Statement stmnt, String sql)
+	{
+		try
+		{
+			if (stmnt != null)
+				return sqle.getMessage () + " {" + stmnt + "} "
+					+ "[code=" + sqle.getErrorCode () + ", state="
+					+ sqle.getSQLState () + "]";
+			else if (sql != null)
+				return sqle.getMessage () + " {" + sql + "} "
+					+ "[code=" + sqle.getErrorCode () + ", state="
+					+ sqle.getSQLState () + "]";
+			else
+				return sqle.getMessage () + " "
+					+ "[code=" + sqle.getErrorCode () + ", state="
+					+ sqle.getSQLState () + "]";
+		}
+		catch (Throwable t)
+		{
+			return sqle.getMessage ();
+		}
+	}
+}
+
+

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/ReportingSQLException.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/SQLFormatter.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/SQLFormatter.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/SQLFormatter.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/SQLFormatter.java Sat May 13 20:25:56 2006
@@ -0,0 +1,331 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.jdbc;
+
+
+import java.util.*;
+
+
+/*
+ *	Lots of this could be abstracted out into a word-wrapping class.
+ */
+
+/**
+ *	<p>Converts single-line SQL strings into nicely-formatted
+ *	multi-line, indented statements.</p>
+ *
+	<p>Example:
+ 	<code>SELECT * from PERSON t0, COMPANY t1 WHERE t0.ID = 10 AND \
+t0.COMPANY_ID = t1.ID AND t1.NAME = 'OpenJPA'</code>
+ 	becomes 
+ 	<code>SELECT * 
+    FROM PERSON t0, COMPANY t1 
+    WHERE t0.ID = 10 AND t0.COMPANY_ID = t1.ID AND t1.NAME = 'OpenJPA'\
+</code>
+	and
+ 	<code>INSERT INTO PERSON VALUES ('Patrick', 'Linskey', 'OpenJPA', \
+'202 595 2064 x1111')</code>
+ 	becomes 
+ 	<code>INSERT INTO PERSON VALUES ('Patrick', 'Linskey', 'OpenJPA', '202 
+        595 2064 x1111')</code>
+	etc.</p>
+ *
+ *	@author	Patrick Linskey
+ */
+public class SQLFormatter
+{
+	private boolean 	multiLine = false;
+	private boolean 	doubleSpace = true;
+	private String 		newline = System.getProperty ("line.separator");
+	private int			lineLength = 72;
+	private String		wrapIndent = "        ";
+	private String		clauseIndent = "    ";
+
+
+	private static final String[] selectSeparators = new String[] {
+			"FROM ",
+			"WHERE ",
+			"ORDER BY ", // ### is this order correct?
+			"GROUP BY ",
+			"HAVING ",
+		};
+
+	private static final String[] insertSeparators = new String[] {
+			"VALUES ",
+		};
+
+	private static final String[] updateSeparators = new String[] {
+			"SET ",
+			"WHERE ",
+		};
+
+	private static final String[] deleteSeparators = new String[] {
+			"WHERE ",
+		};
+
+	private static final String[] createTableSeparators = new String[] {
+			"( ",
+		};
+
+	private static final String[] createIndexSeparators = new String[] {
+			"ON ",
+			"( ",
+		};
+
+
+	public void setNewline (String val)
+	{
+		newline = val;
+	}
+
+
+	public String getNewline ()
+	{
+		return newline;
+	}
+
+
+	public void setLineLength (int val)
+	{
+		lineLength = val;
+	}
+
+
+	public int getLineLength ()
+	{
+		return lineLength;
+	}
+
+
+	public void setWrapIndent (String val)
+	{
+		wrapIndent = val;
+	}
+
+
+	public String getWrapIndent ()
+	{
+		return wrapIndent;
+	}
+
+
+	public void setClauseIndent (String val)
+	{
+		clauseIndent = val;
+	}
+
+
+	public String getClauseIndent ()
+	{
+		return clauseIndent;
+	}
+
+
+	/** 
+	 *  If true, then try to parse multi-line SQL statements.
+	 */
+	public void setMultiLine (boolean multiLine)
+	{
+		this.multiLine = multiLine;
+	}
+
+
+	/** 
+	 *  If true, then try to parse multi-line SQL statements.
+	 */
+	public boolean getMultiLine ()
+	{
+		return this.multiLine;
+	}
+
+
+
+	/** 
+	 *  If true, then output two lines after multi-line statements.
+	 */
+	public void setDoubleSpace (boolean doubleSpace)
+	{
+		this.doubleSpace = doubleSpace;
+	}
+
+
+	/** 
+	 *  If true, then output two lines after multi-line statements.
+	 */
+	public boolean getDoubleSpace ()
+	{
+		return this.doubleSpace;
+	}
+
+
+
+	public Object prettyPrint (Object sqlObject)
+	{
+		if (!multiLine)
+		{
+			return prettyPrintLine (sqlObject);
+		}
+		else
+		{
+			StringBuffer sql = new StringBuffer (sqlObject.toString ());
+			StringBuffer buf = new StringBuffer (sql.length ());
+
+			while (sql.length () > 0)
+			{
+				String line = null;
+
+				int index = Math.max (sql.toString ().indexOf (";\n"),
+					sql.toString ().indexOf (";\r"));
+				if (index == -1)
+					line = sql.toString ();
+				else
+					line = sql.substring (0, index + 2);
+
+				// remove the current line from the sql buffer
+				sql.delete (0, line.length ());
+
+				buf.append (prettyPrintLine (line));
+				for (int i = 0; i < 1 + (getDoubleSpace () ? 1 : 0); i++)
+					buf.append (System.getProperty ("line.separator"));
+			}
+
+			return buf.toString ();
+		}
+	}
+
+
+	private Object prettyPrintLine (Object sqlObject)
+	{
+		String sql = sqlObject.toString ().trim ();
+		String lowerCaseSql = sql.toLowerCase ();
+
+		String[] separators;
+		if (lowerCaseSql.startsWith ("select"))
+			separators = selectSeparators;
+		else if (lowerCaseSql.startsWith ("insert"))
+			separators = insertSeparators;
+		else if (lowerCaseSql.startsWith ("update"))
+			separators = updateSeparators;
+		else if (lowerCaseSql.startsWith ("delete"))
+			separators = deleteSeparators;
+		else if (lowerCaseSql.startsWith ("create table"))
+			separators = createTableSeparators;
+		else if (lowerCaseSql.startsWith ("create index"))
+			separators = createIndexSeparators;
+		else
+			separators = new String[0];
+
+		int start = 0;
+		int end = -1;
+		StringBuffer clause;
+		List clauses = new ArrayList ();
+		clauses.add (new StringBuffer ());
+		for (int i = 0; i < separators.length; i++)
+		{
+			end = lowerCaseSql.indexOf (" " + separators[i].toLowerCase (), 
+				start);
+			if (end == -1)
+				break;
+
+			clause = (StringBuffer) clauses.get (clauses.size () - 1);
+			clause.append (sql.substring (start, end));
+
+			clause = new StringBuffer ();
+			clauses.add (clause);
+			clause.append (clauseIndent);
+			clause.append (separators[i]);
+
+			start = end + 1 + separators[i].length ();
+		}
+
+		clause = (StringBuffer) clauses.get (clauses.size () - 1);
+		clause.append (sql.substring (start));
+
+
+		StringBuffer pp = new StringBuffer (sql.length ());
+		for (Iterator iter = clauses.iterator (); iter.hasNext (); )
+		{
+			pp.append (wrapLine (((StringBuffer) iter.next ()).toString ()));
+			if (iter.hasNext ())
+				pp.append (newline);
+		}
+
+		return pp.toString ();
+	}
+
+
+	private String wrapLine (String line)
+	{
+		StringBuffer lines = new StringBuffer (line.length ());
+
+		// ensure that any leading whitespace is preserved.
+		for (int i = 0; i < line.length () && 
+				 (line.charAt (i) == ' ' || line.charAt (i) == '\t'); i++)
+		{
+			lines.append (line.charAt (i));
+		}
+
+		StringTokenizer tok = new StringTokenizer (line);
+		int length = 0;
+		String elem;
+		while (tok.hasMoreTokens ())
+		{
+			elem = tok.nextToken ();
+			length += elem.length ();
+
+			// if we would have exceeded the max, write out a newline
+			// before writing the elem.
+			if (length >= lineLength)
+			{
+				lines.append (newline);
+				lines.append (wrapIndent);
+				lines.append (elem);
+				lines.append (' ');
+				length = wrapIndent.length () + elem.length () + 1;
+				continue;
+			}
+
+			// if the current length is greater than the max, then the
+			// last word alone was too long, so just write out a
+			// newline and move on.
+			if (elem.length () >= lineLength)
+			{
+				lines.append (elem);
+				if (tok.hasMoreTokens ())
+					lines.append (newline);
+				lines.append (wrapIndent);
+				length = wrapIndent.length ();
+				continue;
+			}
+			
+			lines.append (elem);
+			lines.append (' ');
+			length++;
+		}
+
+		return lines.toString ();
+	}
+
+
+	public static void main (String [] args) 
+	{
+		SQLFormatter formatter = new SQLFormatter ();
+		for (int i = 0; i < args.length; i++)
+		{
+			System.out.println (formatter.prettyPrint (args[i]));
+		}
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/SQLFormatter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/package.html
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/package.html?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/package.html (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/package.html Sat May 13 20:25:56 2006
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+<html>
+<body>
+	<p><strong>Database Connectivity</strong></p>
+	<p>
+		Includes an implementation of the {@link javax.sql.DataSource} APIs 
+		around a normal JDBC 1.x driver.  Implements connection pooling and
+		prepared statement caching.  Also includes a framework for firing and
+	 	consuming JDBC-related events.
+	</p>
+</body>
+</html>

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/package.html
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/AbstractLog.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/AbstractLog.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/AbstractLog.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/AbstractLog.java Sat May 13 20:25:56 2006
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.log;
+
+
+import java.io.*;
+
+
+/** 
+ *  A simple implementation of the {@link Log} interface. Writes
+ *  output to stdout.
+ *
+ *	@author	Patrick Linskey
+ */
+public abstract class AbstractLog
+	implements Log
+{
+	/** 
+	 *  Check to see if the specified logging level is enabled.
+	 */
+	protected abstract boolean isEnabled (short level);
+
+
+	/** 
+	 *  Send the specified log message to the handler.
+	 *  
+	 *  @param  level	the level of the log message
+	 *  @param  message	the message to send
+	 *  @param  t		the Throwable, or null if this is not an error
+	 */
+	protected abstract void log (short level, String message, Throwable t);
+
+
+	public boolean isTraceEnabled ()
+	{
+		return isEnabled (TRACE);
+	}
+
+
+	public boolean isDebugEnabled ()
+	{
+		return isEnabled (DEBUG);
+	}
+
+
+	public boolean isInfoEnabled ()
+	{
+		return isEnabled (INFO);
+	}
+
+
+	public boolean isWarnEnabled ()
+	{
+		return isEnabled (WARN);
+	}
+
+
+	public boolean isErrorEnabled ()
+	{
+		return isEnabled (ERROR);
+	}
+
+
+	public boolean isFatalEnabled ()
+	{
+		return isEnabled (FATAL);
+	}
+
+
+	public void trace (Object message)
+	{
+		trace (message, throwableParam (message, null));
+	}
+
+
+	public void trace (Object message, Throwable t)
+	{
+		if (isTraceEnabled ())
+			log (TRACE, toString (message), throwableParam (message, t));
+	}
+
+
+	public void debug (Object message)
+	{
+		debug (message, throwableParam (message, null));
+	}
+
+
+	public void debug (Object message, Throwable t)
+	{
+		if (isDebugEnabled ())
+			log (DEBUG, toString (message), throwableParam (message, t));
+	}
+
+
+	public void info (Object message)
+	{
+		info (message, throwableParam (message, null));
+	}
+
+
+	public void info (Object message, Throwable t)
+	{
+		if (isInfoEnabled ())
+			log (INFO, toString (message), throwableParam (message, t));
+	}
+
+
+	public void warn (Object message)
+	{
+		warn (message, throwableParam (message, null));
+	}
+
+
+	public void warn (Object message, Throwable t)
+	{
+		if (isWarnEnabled ())
+			log (WARN, toString (message), throwableParam (message, t));
+	}
+
+
+	public void error (Object message)
+	{
+		error (message, throwableParam (message, null));
+	}
+
+
+	public void error (Object message, Throwable t)
+	{
+		if (isErrorEnabled ())
+			log (ERROR, toString (message), throwableParam (message, t));
+	}
+
+
+	public void fatal (Object message)
+	{
+		fatal (message, throwableParam (message, null));
+	}
+
+
+	public void fatal (Object message, Throwable t)
+	{
+		if (isFatalEnabled ())
+			log (FATAL, toString (message), throwableParam (message, t));
+	}
+
+
+	/** 
+	 *  Utility method to obtain a stack trace as a String.
+	 */
+	protected static String getStackTrace (Throwable t)
+	{
+		StringWriter sw = new StringWriter ();
+		PrintWriter pw = new PrintWriter (sw, true);
+		t.printStackTrace (pw);
+		pw.close ();
+		return sw.toString ();
+	}
+
+
+	/**
+	 *	If either given instance is a throwable, return it.
+	 */
+	private static Throwable throwableParam (Object message, Throwable t)
+	{
+		if (t != null)
+			return t;
+		if (message instanceof Throwable)
+			return (Throwable)message;
+
+		return null;
+	}
+
+
+	/**
+	 *	Efficiently turn the given object into a string.
+ 	 */
+	private static String toString (Object o)
+	{
+		return (o == null) ? "null" : o.toString ();
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/AbstractLog.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/CommonsLogFactory.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/CommonsLogFactory.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/CommonsLogFactory.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/CommonsLogFactory.java Sat May 13 20:25:56 2006
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.log;
+
+
+import java.util.*;
+
+
+/**
+ *	{@link LogFactory} implementation that delegates to the commons logging
+ *	framework.
+ *
+ *	@author	Patrick Linskey
+ */
+public class CommonsLogFactory
+	extends LogFactoryAdapter
+{
+	private org.apache.commons.logging.LogFactory _factory;
+
+
+	public CommonsLogFactory ()
+	{
+		_factory = org.apache.commons.logging.LogFactory.getFactory ();
+	}
+
+
+	protected org.apache.openjpa.lib.log.Log newLogAdapter (String channel)
+	{
+		return new LogAdapter (_factory.getInstance (channel));
+	}
+
+
+	/**
+	 *	Adapts a commons logging log to the {@link org.apache.openjpa.lib.log.Log} 
+	 *	interface.
+	 */
+	public static class LogAdapter
+		implements org.apache.openjpa.lib.log.Log
+	{
+		private org.apache.commons.logging.Log _log;
+
+
+		private LogAdapter (org.apache.commons.logging.Log wrapee)
+		{
+			_log = wrapee;
+		}
+
+
+		public org.apache.commons.logging.Log getDelegate ()
+		{
+			return _log;
+		}
+
+
+		public boolean isDebugEnabled ()
+		{
+			return _log.isDebugEnabled ();
+		}
+
+
+		public boolean isErrorEnabled ()
+		{
+			return _log.isErrorEnabled ();
+		}
+
+
+		public boolean isFatalEnabled ()
+		{
+			return _log.isFatalEnabled ();
+		}
+
+
+		public boolean isInfoEnabled ()
+		{
+			return _log.isInfoEnabled ();
+		}
+
+
+		public boolean isTraceEnabled ()
+		{
+			return _log.isTraceEnabled ();
+		}
+
+
+		public boolean isWarnEnabled ()
+		{
+			return _log.isWarnEnabled ();
+		}
+
+
+		public void trace (Object o)
+		{
+			_log.trace (o);
+		}
+
+
+		public void trace (Object o, Throwable t)
+		{
+			_log.trace (o, t);
+		}
+
+
+		public void debug (Object o)
+		{
+			_log.debug (o);
+		}
+
+
+		public void debug (Object o, Throwable t)
+		{
+			_log.debug (o, t);
+		}
+
+
+		public void info (Object o)
+		{
+			_log.info (o);
+		}
+
+
+		public void info (Object o, Throwable t)
+		{
+			_log.info (o, t);
+		}
+
+
+		public void warn (Object o)
+		{
+			_log.warn (o);
+		}
+
+
+		public void warn (Object o, Throwable t)
+		{
+			_log.warn (o, t);
+		}
+
+
+		public void error (Object o)
+		{
+			_log.error (o);
+		}
+
+
+		public void error (Object o, Throwable t)
+		{
+			_log.error (o, t);
+		}
+
+
+		public void fatal (Object o)
+		{
+			_log.fatal (o);
+		}
+
+
+		public void fatal (Object o, Throwable t)
+		{
+			_log.fatal (o, t);
+		}
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/CommonsLogFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log.java Sat May 13 20:25:56 2006
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.log;
+
+
+/**
+ *	Logging interface that is independent of other logging frameworks. 
+ *
+ *	@author Patrick Linskey
+ *	@author	Abe White
+ */
+public interface Log
+{
+	public static final short TRACE	= 1;
+	public static final short DEBUG	= 2;
+	public static final short INFO	= 3;
+	public static final short WARN	= 4;
+	public static final short ERROR	= 5;
+	public static final short FATAL	= 6;
+
+
+	/**
+	 *	Returns if the {@link #TRACE} log level is enabled.
+	 */
+    public boolean isTraceEnabled ();
+
+
+	/**
+	 *	Returns if the {@link #DEBUG} log level is enabled.
+	 */
+    public boolean isDebugEnabled ();
+
+
+	/**
+	 *	Returns if the {@link #INFO} log level is enabled.
+	 */
+    public boolean isInfoEnabled ();
+
+
+	/**
+	 *	Returns if the {@link #WARN} log level is enabled.
+	 */
+    public boolean isWarnEnabled ();
+
+
+	/**
+	 *	Returns if the {@link #ERROR} log level is enabled.
+	 */
+    public boolean isErrorEnabled ();
+
+
+	/**
+	 *	Returns if the {@link #FATAL} log level is enabled.
+	 */
+    public boolean isFatalEnabled ();
+
+
+	/**
+	 *	Write out a log message at the {@link #TRACE}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message.
+	 */
+    public void trace (Object o);
+
+
+	/**
+	 *	Write out a log message at the {@link #TRACE}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message, also outputting <code>t</code> to the log.
+	 */
+    public void trace (Object o, Throwable t);
+
+
+	/**
+	 *	Write out a log message at the {@link #DEBUG}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message, also outputting <code>t</code> to the log.
+	 */
+    public void debug (Object o);
+
+
+	/**
+	 *	Write out a log message at the {@link #DEBUG}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message, also outputting <code>t</code> to the log.
+	 */
+    public void debug (Object o, Throwable t);
+
+
+	/**
+	 *	Write out a log message at the {@link #INFO}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message, also outputting <code>t</code> to the log.
+	 */
+    public void info (Object o);
+
+
+	/**
+	 *	Write out a log message at the {@link #INFO}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message, also outputting <code>t</code> to the log.
+	 */
+    public void info (Object o, Throwable t);
+
+
+	/**
+	 *	Write out a log message at the {@link #WARN}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message, also outputting <code>t</code> to the log.
+	 */
+    public void warn (Object o);
+
+
+	/**
+	 *	Write out a log message at the {@link #WARN}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message, also outputting <code>t</code> to the log.
+	 */
+    public void warn (Object o, Throwable t);
+
+
+	/**
+	 *	Write out a log message at the {@link #ERROR}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message, also outputting <code>t</code> to the log.
+	 */
+    public void error (Object o);
+
+
+	/**
+	 *	Write out a log message at the {@link #ERROR}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message, also outputting <code>t</code> to the log.
+	 */
+    public void error (Object o, Throwable t);
+
+
+	/**
+	 *	Write out a log message at the {@link #FATAL}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message, also outputting <code>t</code> to the log.
+	 */
+    public void fatal (Object o);
+
+
+	/**
+	 *	Write out a log message at the {@link #FATAL}
+	 *	level with the stringification of <code>o</code> as the body
+	 *	of the message, also outputting <code>t</code> to the log.
+	 */
+    public void fatal (Object o, Throwable t);
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log4JLogFactory.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log4JLogFactory.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log4JLogFactory.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log4JLogFactory.java Sat May 13 20:25:56 2006
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.log;
+
+
+import java.util.*;
+
+import org.apache.log4j.*;
+
+
+/**
+ *	{@link LogFactory} implementation that delegates to the Log4J framework.
+ *
+ *	@author	Patrick Linskey
+ */
+public class Log4JLogFactory
+	extends LogFactoryAdapter
+{
+	protected Log newLogAdapter (String channel)
+	{
+		return new LogAdapter ((Logger) LogManager.getLogger (channel));
+	}
+
+
+	/**
+	 *	Adapts a Log4J logger to the {@link org.apache.openjpa.lib.log.Log} interface.
+	 */
+	public static class LogAdapter
+		implements Log
+	{
+		private Logger _log;
+
+
+		private LogAdapter (Logger wrapee)
+		{
+			_log = wrapee;
+		}
+
+
+		public Logger getDelegate ()
+		{
+			return _log;
+		}
+
+
+		public boolean isTraceEnabled ()
+		{
+			return isDebugEnabled ();
+		}
+
+
+		public boolean isDebugEnabled ()
+		{
+			return _log.getEffectiveLevel ().toInt () >= Level.DEBUG_INT;
+		}
+
+
+		public boolean isInfoEnabled ()
+		{
+			return _log.getEffectiveLevel ().toInt () >= Level.INFO_INT;
+		}
+
+
+		public boolean isWarnEnabled ()
+		{
+			return _log.getEffectiveLevel ().toInt () >= Level.WARN_INT;
+		}
+
+
+		public boolean isErrorEnabled ()
+		{
+			return _log.getEffectiveLevel ().toInt () >= Level.ERROR_INT;
+		}
+
+
+		public boolean isFatalEnabled ()
+		{
+			return _log.getEffectiveLevel ().toInt () >= Level.FATAL_INT;
+		}
+
+
+		public void trace (Object o)
+		{
+			_log.debug (o);
+		}
+
+
+		public void trace (Object o, Throwable t)
+		{
+			_log.debug (o, t);
+		}
+
+
+		public void debug (Object o)
+		{
+			_log.debug (o);
+		}
+
+
+		public void debug (Object o, Throwable t)
+		{
+			_log.debug (o, t);
+		}
+
+
+		public void info (Object o)
+		{
+			_log.info (o);
+		}
+
+
+		public void info (Object o, Throwable t)
+		{
+			_log.info (o, t);
+		}
+
+
+		public void warn (Object o)
+		{
+			_log.warn (o);
+		}
+
+
+		public void warn (Object o, Throwable t)
+		{
+			_log.warn (o, t);
+		}
+
+
+		public void error (Object o)
+		{
+			_log.error (o);
+		}
+
+
+		public void error (Object o, Throwable t)
+		{
+			_log.error (o, t);
+		}
+
+
+		public void fatal (Object o)
+		{
+			_log.fatal (o);
+		}
+
+
+		public void fatal (Object o, Throwable t)
+		{
+			_log.fatal (o, t);
+		}
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log4JLogFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/LogFactory.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/LogFactory.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/LogFactory.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/LogFactory.java Sat May 13 20:25:56 2006
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.log;
+
+
+/**
+ *	<p>Factory for log instances.</p>
+ *
+ *	@author	Abe White
+ */
+public interface LogFactory
+{
+	/**
+	 *	Return a log for the given channel name.
+	 */
+	public Log getLog (String channel);
+}



Mime
View raw message