cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amania...@apache.org
Subject svn commit: r668221 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: access/jdbc/ conf/ conn/ remote/hessian/ remote/service/
Date Mon, 16 Jun 2008 16:25:28 GMT
Author: amaniatis
Date: Mon Jun 16 09:25:28 2008
New Revision: 668221

URL: http://svn.apache.org/viewvc?rev=668221&view=rev
Log:
Remove several places where output is sent directly to the console rather than the apache
commons logger. This will reduce the noise in places where the user wishes to catch the exception
and not show it to the end user.

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/DriverDataSourceFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java?rev=668221&r1=668220&r2=668221&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
Mon Jun 16 09:25:28 2008
@@ -19,9 +19,6 @@
 
 package org.apache.cayenne.access.jdbc;
 
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -38,6 +35,8 @@
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.util.Util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * A ResultIterator over the underlying JDBC ResultSet.
@@ -47,7 +46,8 @@
  */
 // Replaces DefaultResultIterator
 public class JDBCResultIterator implements ResultIterator {
-
+    private static Log logger = LogFactory.getLog(JDBCResultIterator.class);
+    
     // Connection information
     protected Connection connection;
     protected Statement statement;
@@ -216,18 +216,15 @@
      */
     public void close() throws CayenneException {
         if (!closed) {
-
             nextRow = false;
 
-            StringWriter errors = new StringWriter();
-            PrintWriter out = new PrintWriter(errors);
+            StringBuffer errors = new StringBuffer();
 
             try {
                 resultSet.close();
             }
             catch (SQLException e1) {
-                out.println("Error closing ResultSet");
-                e1.printStackTrace(out);
+                errors.append("Error closing ResultSet.");
             }
 
             if (statement != null) {
@@ -235,8 +232,7 @@
                     statement.close();
                 }
                 catch (SQLException e2) {
-                    out.println("Error closing PreparedStatement");
-                    e2.printStackTrace(out);
+                    errors.append("Error closing PreparedStatement.");
                 }
             }
 
@@ -251,23 +247,12 @@
                     connection.close();
                 }
                 catch (SQLException e3) {
-                    out.println("Error closing Connection");
-                    e3.printStackTrace(out);
+                    errors.append("Error closing Connection.");
                 }
             }
 
-            try {
-                out.close();
-                errors.close();
-            }
-            catch (IOException ioex) {
-                // ignore - this is never going to happen, after all we are writing to
-                // StringBuffer in memory
-            }
-
-            StringBuffer buf = errors.getBuffer();
-            if (buf.length() > 0) {
-                throw new CayenneException("Error closing ResultIterator: " + buf);
+            if (errors.length() > 0) {
+                throw new CayenneException("Error closing ResultIterator: " + errors.toString());
             }
 
             closed = true;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/DriverDataSourceFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/DriverDataSourceFactory.java?rev=668221&r1=668220&r2=668221&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/DriverDataSourceFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/DriverDataSourceFactory.java
Mon Jun 16 09:25:28 2008
@@ -237,7 +237,6 @@
     }
 
     private class LoginHandler extends AbstractHandler {
-
         /**
          * Constructor which just delegates to the superconstructor.
          * 
@@ -259,7 +258,7 @@
                 password = bufferedReader.readLine();
             }
             catch (IOException exception) {
-                exception.printStackTrace();
+                logger.warn(exception);
             }
             finally {
                 try {
@@ -299,7 +298,7 @@
             catch (IOException exception) {
                 // Log the error while trying to open the stream. A null
                 // password will be returned as a result.
-                exception.printStackTrace();
+                logger.warn(exception);
             }
 
             return password;
@@ -347,7 +346,7 @@
                         password = passwordFromURL(new URL(passwordSource));
                     }
                     catch (MalformedURLException exception) {
-                        exception.printStackTrace();
+                        logger.warn(exception);
                     }
                 }
                 else if (passwordLocation
@@ -359,10 +358,10 @@
                             process.waitFor();
                         }
                         catch (IOException exception) {
-                            exception.printStackTrace();
+                            logger.warn(exception);
                         }
                         catch (InterruptedException exception) {
-                            exception.printStackTrace();
+                            logger.warn(exception);
                         }
                     }
                 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java?rev=668221&r1=668220&r2=668221&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java
Mon Jun 16 09:25:28 2008
@@ -24,6 +24,8 @@
 import org.apache.cayenne.conf.PasswordEncoding;
 import org.apache.cayenne.conf.PlainTextPasswordEncoder;
 import org.apache.cayenne.util.Util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Helper JavaBean class that holds DataSource login information.
@@ -35,7 +37,8 @@
  * @author Andrus Adamchik
  */
 public class DataSourceInfo implements Cloneable, Serializable {
-
+    private static Log logger = LogFactory.getLog(DataSourceInfo.class);
+    
     protected String userName;
     protected String password;
     protected String jdbcDriver;
@@ -212,17 +215,8 @@
             // encoder = (PasswordEncoding)
             // Class.forName(getPasswordEncoderClass()).newInstance();
         }
-        catch (InstantiationException exception) {
-            // TODO Auto-generated catch block
-            exception.printStackTrace();
-        }
-        catch (IllegalAccessException exception) {
-            // TODO Auto-generated catch block
-            exception.printStackTrace();
-        }
-        catch (ClassNotFoundException exception) {
-            // TODO Auto-generated catch block
-            exception.printStackTrace();
+        catch (Exception exception) {
+            logger.warn(exception);
         }
 
         return encoder;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java?rev=668221&r1=668220&r2=668221&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
Mon Jun 16 09:25:28 2008
@@ -26,6 +26,8 @@
 import org.apache.cayenne.remote.RemoteService;
 import org.apache.cayenne.remote.RemoteSession;
 import org.apache.cayenne.util.Util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import com.caucho.hessian.client.HessianRuntimeException;
 import com.caucho.hessian.io.HessianProtocolException;
@@ -42,6 +44,8 @@
  */
 public class HessianConnection extends BaseConnection {
 
+    private static Log logger = LogFactory.getLog(HessianConnection.class);
+    
     public static final String[] CLIENT_SERIALIZER_FACTORIES = new String[] {
             ClientSerializerFactory.class.getName(), EnumSerializerProxy.class.getName()
     };
@@ -216,10 +220,10 @@
         }
         catch (Throwable th) {
             th = unwindThrowable(th);
-            th.printStackTrace();
             String message = buildExceptionMessage(
                     "Error establishing remote session",
                     th);
+            logger.info(message, th);
             throw new CayenneRuntimeException(message, th);
         }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java?rev=668221&r1=668220&r2=668221&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java
Mon Jun 16 09:25:28 2008
@@ -158,18 +158,7 @@
 
             // This exception will probably be propagated to the client.
             // Recast the exception to a serializable form.
-            ByteArrayOutputStream causeMessageStream = new ByteArrayOutputStream();
-            PrintWriter causeMessage = new PrintWriter(causeMessageStream);
-            
-            String exceptionText = th.getLocalizedMessage();
-            if (exceptionText != null) {
-                causeMessage.print(exceptionText);
-                causeMessage.print(System.getProperty("line.separator"));
-            }
-
-            th.printStackTrace(causeMessage);
-            causeMessage.flush();
-            Exception cause = new Exception(causeMessageStream.toString());
+            Exception cause = new Exception(th.getLocalizedMessage());
 
             StringBuilder wrapperMessage = new StringBuilder();
             wrapperMessage.append("Exception processing message ")



Mime
View raw message