cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mgen...@apache.org
Subject svn commit: r612201 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: access/QueryLogger.java access/jdbc/BatchAction.java dba/oracle/OracleLOBBatchAction.java
Date Tue, 15 Jan 2008 20:23:51 GMT
Author: mgentry
Date: Tue Jan 15 12:23:50 2008
New Revision: 612201

URL: http://svn.apache.org/viewvc?rev=612201&view=rev
Log:
Changes for CAY-960.

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryLogger.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchAction.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryLogger.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryLogger.java?rev=612201&r1=612200&r2=612201&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryLogger.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryLogger.java
Tue Jan 15 12:23:50 2008
@@ -21,6 +21,7 @@
 
 import java.lang.reflect.Array;
 import java.sql.SQLException;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.cayenne.access.jdbc.ParameterBinding;
@@ -51,6 +52,7 @@
     /**
      * @since 1.2
      */
+    @SuppressWarnings("unchecked")
     static ThreadLocal logLevel = new ThreadLocal();
 
     /**
@@ -242,43 +244,70 @@
                                  String            prefix,
                                  String            postfix,
                                  List<DbAttribute> attributes,
-                                 List<Object>      parameters)
+                                 List<?>           parameters,
+                                 boolean           isInserting)
     {
         if (parameters != null && parameters.size() > 0)
         {
-            DbAttribute attribute = null;
-            int         size      = parameters.size();
+            DbAttribute           attribute         = null;
+            Iterator<DbAttribute> attributeIterator = null;
+            int                   position          = 0;
 
-            for (int i = 0; i < size; i++)
+            if (attributes != null)
+                attributeIterator = attributes.iterator();
+
+            for (Object parameter : parameters)
             {
-                if (i == 0)
+                // If at the beginning, output the prefix, otherwise a separator.
+                if (position++ == 0)
                     buffer.append(prefix);
                 else
                     buffer.append(", ");
 
-                if (attributes != null && i < attributes.size())
-                    attribute = attributes.get(i);
-
-                buffer.append(i + 1);
-
-                if (attribute != null)
+                // Find the next attribute and SKIP generated attributes.  Only
+                // skip when logging inserts, though.  Should show previously
+                // generated keys on DELETE, UPDATE, or SELECT.
+                while (attributeIterator != null && attributeIterator.hasNext())
                 {
-                    buffer.append("->");
-                    buffer.append(attribute.getName());
+                    attribute = attributeIterator.next();
+
+                    if (isInserting == false || attribute.isGenerated() == false)
+                        break;
                 }
 
-                buffer.append(":");
-                sqlLiteralForObject(buffer, parameters.get(i));
+                buffer.append(position);
+
+              if (attribute != null)
+              {
+                  buffer.append("->");
+                  buffer.append(attribute.getName());
+              }
+
+              buffer.append(":");
+              sqlLiteralForObject(buffer, parameter);
             }
 
             buffer.append(postfix);
         }
     }
 
+    private static boolean isInserting(String query)
+    {
+        if (query == null || query.length() == 0)
+            return false;
+
+        char firstCharacter = query.charAt(0);
+        
+        if (firstCharacter == 'I' || firstCharacter == 'i')
+            return true;
+        else
+            return false;
+    }
+
     /**
      * @since 1.2
      */
-    public static void logQuery(String queryStr, List params) {
+    public static void logQuery(String queryStr, List<?> params) {
         logQuery(queryStr, null, params, -1);
     }
 
@@ -291,10 +320,10 @@
      *            in prepared statement.
      * @since 1.2
      */
-    public static void logQuery(String queryStr, List<DbAttribute> attrs, List params,
long time) {
+    public static void logQuery(String queryStr, List<DbAttribute> attrs, List<?>
params, long time) {
         if (isLoggable()) {
             StringBuffer buf = new StringBuffer(queryStr);
-            buildLog(buf, " [bind: ", "]", attrs, params);
+            buildLog(buf, " [bind: ", "]", attrs, params, isInserting(queryStr));
 
             // log preparation time only if it is something significant
             if (time > 5) {
@@ -308,11 +337,14 @@
     /**
      * @since 1.2
      */
-    public static void logQueryParameters(String label, List<DbAttribute> attrs, List
parameters) {
+    public static void logQueryParameters(String           label,
+                                         List<DbAttribute> attrs,
+                                         List<Object>      parameters,
+                                         boolean           isInserting) {
         String prefix = "[" + label + ": ";
         if (isLoggable() && parameters.size() > 0) {
             StringBuffer buf = new StringBuffer();
-            buildLog(buf, prefix, "]", attrs, parameters);
+            buildLog(buf, prefix, "]", attrs, parameters, isInserting);
             logObj.info(buf.toString());
         }
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java?rev=612201&r1=612200&r2=612201&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
Tue Jan 15 12:23:50 2008
@@ -122,7 +122,8 @@
                     QueryLogger.logQueryParameters
                         ("batch bind",
                          query.getDbAttributes(), 
-                         queryBuilder.getParameterValues(query));
+                         queryBuilder.getParameterValues(query),
+                         query instanceof InsertBatchQuery);
                 }
 
                 queryBuilder.bindParameters(statement, query);
@@ -185,7 +186,7 @@
             while (query.next()) {
                 if (isLoggable) {
                     QueryLogger.logQueryParameters
-                        ("bind", query.getDbAttributes(), queryBuilder.getParameterValues(query));
+                        ("bind", query.getDbAttributes(), queryBuilder.getParameterValues(query),
query instanceof InsertBatchQuery);
                 }
 
                 queryBuilder.bindParameters(statement, query);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchAction.java?rev=612201&r1=612200&r2=612201&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchAction.java
Tue Jan 15 12:23:50 2008
@@ -108,7 +108,7 @@
 
                 if (isLoggable) {
                     List bindings = queryBuilder.getValuesForLOBUpdateParameters(query);
-                    QueryLogger.logQueryParameters("bind", null, bindings);
+                    QueryLogger.logQueryParameters("bind", null, bindings, query instanceof
InsertBatchQuery);
                 }
 
                 queryBuilder.bindParameters(statement, query);
@@ -156,7 +156,7 @@
 
         if (isLoggable) {
             QueryLogger.logQuery(selectStr, qualifierValues);
-            QueryLogger.logQueryParameters("write LOB", null, lobValues);
+            QueryLogger.logQueryParameters("write LOB", null, lobValues, false);
         }
 
         PreparedStatement selectStatement = con.prepareStatement(selectStr);



Mime
View raw message