cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r439600 - /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/QueryLogger.java
Date Sat, 02 Sep 2006 14:09:53 GMT
Author: aadamchik
Date: Sat Sep  2 07:09:53 2006
New Revision: 439600

URL: http://svn.apache.org/viewvc?rev=439600&view=rev
Log:
improving logger output for all the new "primitive" types added to Cayenne

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/QueryLogger.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/QueryLogger.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/QueryLogger.java?rev=439600&r1=439599&r2=439600&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/QueryLogger.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/QueryLogger.java
Sat Sep  2 07:09:53 2006
@@ -19,6 +19,7 @@
 
 package org.apache.cayenne.access;
 
+import java.lang.reflect.Array;
 import java.sql.SQLException;
 import java.util.List;
 
@@ -44,7 +45,7 @@
 
     private static final Log logObj = LogFactory.getLog(QueryLogger.class);
 
-    public static final int TRIM_VALUES_THRESHOLD = 300;
+    public static final int TRIM_VALUES_THRESHOLD = 30;
 
     /**
      * @since 1.2
@@ -52,26 +53,22 @@
     static ThreadLocal logLevel = new ThreadLocal();
 
     /**
-     * Utility method that appends SQL literal for the specified object to the buffer.
-     * <p>
-     * Note: this method is not intended to build SQL queries, rather this is used in
-     * logging routines only. In particular it will trim large values to avoid flooding
-     * the logs.
+     * Appends SQL literal for the specified object to the buffer. This is a utility
+     * method and is not intended to build SQL queries, rather this is used in logging
+     * routines. In particular it will trim large values to avoid flooding the logs.
      * </p>
      * 
-     * @param buf buffer to append value
-     * @param anObject object to be transformed to SQL literal.
+     * @param buffer buffer to append value
+     * @param object object to be transformed to SQL literal.
      */
-    public static void sqlLiteralForObject(StringBuffer buf, Object anObject) {
-        // 0. Null
-        if (anObject == null) {
-            buf.append("NULL");
-        }
-        // 1. String literal
-        else if (anObject instanceof String) {
-            buf.append('\'');
+    public static void sqlLiteralForObject(StringBuffer buffer, Object object) {
+        if (object == null) {
+            buffer.append("NULL");
+        }
+        else if (object instanceof String) {
+            buffer.append('\'');
             // lets escape quotes
-            String literal = (String) anObject;
+            String literal = (String) object;
             if (literal.length() > TRIM_VALUES_THRESHOLD) {
                 literal = literal.substring(0, TRIM_VALUES_THRESHOLD) + "...";
             }
@@ -80,72 +77,75 @@
             int endPos = 0;
 
             while ((endPos = literal.indexOf('\'', curPos)) >= 0) {
-                buf.append(literal.substring(curPos, endPos + 1)).append('\'');
+                buffer.append(literal.substring(curPos, endPos + 1)).append('\'');
                 curPos = endPos + 1;
             }
 
             if (curPos < literal.length())
-                buf.append(literal.substring(curPos));
+                buffer.append(literal.substring(curPos));
 
-            buf.append('\'');
+            buffer.append('\'');
+        }
+        // handle byte pretty formatting
+        else if (object instanceof Byte) {
+            IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue());
         }
-        // 2. Numeric literal
-        else if (anObject instanceof Number) {
+        else if (object instanceof Number) {
             // process numeric value (do something smart in the future)
-            buf.append(anObject);
+            buffer.append(object);
+        }
+        else if (object instanceof java.sql.Date) {
+            buffer.append('\'').append(object).append('\'');
+        }
+        else if (object instanceof java.sql.Time) {
+            buffer.append('\'').append(object).append('\'');
+        }
+        else if (object instanceof java.util.Date) {
+            long time = ((java.util.Date) object).getTime();
+            buffer.append('\'').append(new java.sql.Timestamp(time)).append('\'');
+        }
+        else if (object instanceof java.util.Calendar) {
+            long time = ((java.util.Calendar) object).getTimeInMillis();
+            buffer.append(object.getClass().getName()).append('(').append(
+                    new java.sql.Timestamp(time)).append(')');
         }
-        // 3. Date
-        else if (anObject instanceof java.sql.Date) {
-            buf.append('\'').append(anObject).append('\'');
-        }
-        // 4. Date
-        else if (anObject instanceof java.sql.Time) {
-            buf.append('\'').append(anObject).append('\'');
-        }
-        // 5 Date
-        else if (anObject instanceof java.util.Date) {
-            long time = ((java.util.Date) anObject).getTime();
-            buf.append('\'').append(new java.sql.Timestamp(time)).append('\'');
-        }
-        else if (anObject instanceof java.util.Calendar) {
-            long time = ((java.util.Calendar) anObject).getTimeInMillis();
-            buf.append("calendar<").append(new java.sql.Timestamp(time)).append('>');
-        }
-        // 6. byte[]
-        else if (anObject instanceof byte[]) {
-            buf.append("< ");
-            byte[] b = (byte[]) anObject;
 
-            int len = b.length;
+        else if (object instanceof Boolean) {
+            buffer.append('\'').append(object).append('\'');
+        }
+        else if (object instanceof ParameterBinding) {
+            sqlLiteralForObject(buffer, ((ParameterBinding) object).getValue());
+        }
+        else if (object.getClass().isArray()) {
+            buffer.append("< ");
+
+            int len = Array.getLength(object);
             boolean trimming = false;
             if (len > TRIM_VALUES_THRESHOLD) {
                 len = TRIM_VALUES_THRESHOLD;
                 trimming = true;
             }
-
+            
             for (int i = 0; i < len; i++) {
-                IDUtil.appendFormattedByte(buf, b[i]);
-                buf.append(' ');
+                if (i > 0) {
+                    buffer.append(",");
+                }
+                sqlLiteralForObject(buffer, Array.get(object, i));
             }
 
             if (trimming) {
-                buf.append("...");
+                buffer.append("...");
             }
-            buf.append('>');
-        }
-        else if (anObject instanceof Boolean) {
-            buf.append('\'').append(anObject).append('\'');
 
-        }
-        else if (anObject instanceof ParameterBinding) {
-            sqlLiteralForObject(buf, ((ParameterBinding) anObject).getValue());
+            buffer.append('>');
         }
         else {
-            // unknown
-            buf.append("[").append(anObject.getClass().getName()).append(": ").append(
-                    anObject).append("]");
+            buffer.append(object.getClass().getName()).append("@").append(
+                    System.identityHashCode(object));
         }
     }
+    
+    
 
     /**
      * @since 1.2 logs an arbitrary message using logging level setup for QueryLogger.



Mime
View raw message