You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2014/06/19 19:41:36 UTC

svn commit: r1603973 - in /db/derby/code/trunk/java/client/org/apache/derby: client/am/LogWriter.java jdbc/BasicClientDataSource40.java

Author: rhillegas
Date: Thu Jun 19 17:41:36 2014
New Revision: 1603973

URL: http://svn.apache.org/r1603973
Log:
DERBY-6621: Make client-side getLogWriter() method private; tests passed cleanly on derby-6621-02-aa-move-getPrintWriter.diff.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogWriter.java
    db/derby/code/trunk/java/client/org/apache/derby/jdbc/BasicClientDataSource40.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogWriter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogWriter.java?rev=1603973&r1=1603972&r2=1603973&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogWriter.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogWriter.java Thu Jun 19 17:41:36 2014
@@ -21,14 +21,8 @@
 
 package org.apache.derby.client.am;
 
-import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.PrintWriter;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
 import java.sql.SQLException;
 import java.util.Iterator;
 import java.util.Map;
@@ -675,42 +669,6 @@ public class LogWriter {
         Version.writeDriverConfiguration(printWriter_);
     }
 
-    public static PrintWriter getPrintWriter(
-            final String fileName,
-            final boolean fileAppend) throws SqlException {
-
-        PrintWriter printWriter = null;
-        //Using an anonymous class to deal with the PrintWriter because the  
-        //method java.security.AccessController.doPrivileged requires an 
-        //instance of a class(which implements 
-        //java.security.PrivilegedExceptionAction). Since getPrintWriter method
-        //is static, we can't simply pass "this" to doPrivileged method and 
-        //have LogWriter implement PrivilegedExceptionAction.
-        //To get around the static nature of method getPrintWriter, have an
-        //anonymous class implement PrivilegedExceptionAction. That class will 
-        //do the work related to PrintWriter in it's run method and return 
-        //PrintWriter object.
-        try {
-            printWriter = AccessController.doPrivileged(
-                new PrivilegedExceptionAction<PrintWriter>(){
-                    public PrintWriter run() throws IOException {
-                        String fileCanonicalPath =
-                            new File(fileName).getCanonicalPath();
-                        return new PrintWriter(
-                                new BufferedOutputStream(
-                                        new FileOutputStream(
-                                                fileCanonicalPath, fileAppend), 4096), true);
-                        }
-                    });
-        } catch (PrivilegedActionException pae) {
-            throw new SqlException(null, 
-                new ClientMessageId(SQLState.UNABLE_TO_OPEN_FILE),
-                new Object[] { fileName, pae.getMessage() },
-                pae);
-        }
-        return printWriter;
-    }
-    
     /**
      * Obtain a set of Properties for the client data source.
      */

Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/BasicClientDataSource40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/jdbc/BasicClientDataSource40.java?rev=1603973&r1=1603972&r2=1603973&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/jdbc/BasicClientDataSource40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/BasicClientDataSource40.java Thu Jun 19 17:41:36 2014
@@ -21,13 +21,18 @@
 
 package org.apache.derby.jdbc;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.security.PrivilegedAction;
 import java.sql.Connection;
 import java.sql.SQLException;
@@ -812,15 +817,51 @@ public class BasicClientDataSource40 
                         traceFile + logWriterInUseSuffix + "_" +
                         traceFileSuffixIndex;
                 }
-                return LogWriter.getPrintWriter(
+                return getPrintWriter(
                     fileName, true); // no file append and not enable caching.
             } else if (traceFile != null) {
-                return LogWriter.getPrintWriter(traceFile, traceFileAppend);
+                return getPrintWriter(traceFile, traceFileAppend);
             }
         }
         return null;
     }
 
+    private static PrintWriter getPrintWriter(
+            final String fileName,
+            final boolean fileAppend) throws SqlException {
+
+        PrintWriter printWriter = null;
+        //Using an anonymous class to deal with the PrintWriter because the  
+        //method java.security.AccessController.doPrivileged requires an 
+        //instance of a class(which implements 
+        //java.security.PrivilegedExceptionAction). Since getPrintWriter method
+        //is static, we can't simply pass "this" to doPrivileged method and 
+        //have LogWriter implement PrivilegedExceptionAction.
+        //To get around the static nature of method getPrintWriter, have an
+        //anonymous class implement PrivilegedExceptionAction. That class will 
+        //do the work related to PrintWriter in it's run method and return 
+        //PrintWriter object.
+        try {
+            printWriter = AccessController.doPrivileged(
+                new PrivilegedExceptionAction<PrintWriter>(){
+                    public PrintWriter run() throws IOException {
+                        String fileCanonicalPath =
+                            new File(fileName).getCanonicalPath();
+                        return new PrintWriter(
+                                new BufferedOutputStream(
+                                        new FileOutputStream(
+                                                fileCanonicalPath, fileAppend), 4096), true);
+                        }
+                    });
+        } catch (PrivilegedActionException pae) {
+            throw new SqlException(null, 
+                new ClientMessageId(SQLState.UNABLE_TO_OPEN_FILE),
+                new Object[] { fileName, pae.getMessage() },
+                pae);
+        }
+        return printWriter;
+    }
+    
     private static boolean parseBoolean(
         String boolString, boolean defaultBool) {