db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1456579 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/db/OptimizerTrace.java tools/org/apache/derby/impl/tools/optional/OptimizerTracer.java
Date Thu, 14 Mar 2013 18:06:16 GMT
Author: rhillegas
Date: Thu Mar 14 18:06:15 2013
New Revision: 1456579

URL: http://svn.apache.org/r1456579
Log:
DERBY-6022: Add filename argument to the optional tool which turns off optimizer tracing,
so that the trace can be dumped to a file.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/db/OptimizerTrace.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/optional/OptimizerTracer.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/db/OptimizerTrace.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/db/OptimizerTrace.java?rev=1456579&r1=1456578&r2=1456579&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/db/OptimizerTrace.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/db/OptimizerTrace.java Thu Mar 14
18:06:15 2013
@@ -21,6 +21,8 @@
 
 package org.apache.derby.iapi.db;
 
+import java.sql.SQLException;
+
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 import org.apache.derby.iapi.sql.conn.ConnectionUtil;
 
@@ -58,6 +60,14 @@ public class OptimizerTrace
 		return retCode;
 	}
 
+    /**
+     * Null out the optimizer trace.
+     */
+    public  static  void    nullifyTrace()  throws SQLException
+    {
+        ConnectionUtil.getCurrentLCC().setOptimizerTraceOutput( null );
+    }
+
 	/**
 	 * Control whether or not optimizer trace is generated in html.
 	 *

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/optional/OptimizerTracer.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/optional/OptimizerTracer.java?rev=1456579&r1=1456578&r2=1456579&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/optional/OptimizerTracer.java
(original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/optional/OptimizerTracer.java
Thu Mar 14 18:06:15 2013
@@ -21,6 +21,7 @@
 
 package org.apache.derby.impl.tools.optional;
 
+import java.io.FileWriter;
 import java.sql.SQLException;
 
 import org.apache.derby.iapi.db.OptimizerTrace;
@@ -74,16 +75,52 @@ public	class   OptimizerTracer  implemen
 
     /**
      * <p>
-     * Dump the optimizer trace and turn off tracing.
+     * Dump the optimizer trace and turn off tracing. Takes optional parameters:
      * </p>
+     *
+     * <ul>
+     * <li><b>fileName</b> - Where to write the optimizer trace. If omitted,
the trace is written to System.out.</li>
+     * </ul>
      */
     public  void    unloadTool( String... configurationParameters )
         throws SQLException
     {
-        System.out.println( OptimizerTrace.getOptimizerTraceOutput() );
+        String  trace = OptimizerTrace.getOptimizerTraceOutput();
+        if ( trace == null ) { trace = ""; }
+
+        OptimizerTrace.nullifyTrace();
+        
+        if (
+            (configurationParameters != null) &&
+            (configurationParameters.length > 0)
+            )
+        {
+            try {
+                FileWriter    writer = new FileWriter( configurationParameters[ 0 ] );
+
+                writer.write( trace );
+                writer.flush();
+                writer.close();
+            } catch (Exception e) { throw wrap( e ); }
+        }
+        else
+        {
+            System.out.println( trace );
+        }
 
         OptimizerTrace.setOptimizerTrace( false );
     }
 
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	MINIONS
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    /** Wrap an exception in a SQLException */
+    private SQLException    wrap( Throwable t )
+    {
+        return new SQLException( t.getMessage(), t );
+    }
 }
 



Mime
View raw message