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 2013/04/23 16:40:29 UTC

svn commit: r1470982 - in /db/derby/code/trunk/java/tools/org/apache/derby: iapi/tools/ impl/tools/ impl/tools/ij/

Author: rhillegas
Date: Tue Apr 23 14:40:29 2013
New Revision: 1470982

URL: http://svn.apache.org/r1470982
Log:
DERBY-6195: Cleanup encapsulation problems in ij.

Added:
    db/derby/code/trunk/java/tools/org/apache/derby/iapi/tools/ToolUtils.java   (with props)
Modified:
    db/derby/code/trunk/java/tools/org/apache/derby/iapi/tools/build.xml
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/build.xml
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ParseException.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/URLCheck.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijResultSetResult.java

Added: db/derby/code/trunk/java/tools/org/apache/derby/iapi/tools/ToolUtils.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/iapi/tools/ToolUtils.java?rev=1470982&view=auto
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/iapi/tools/ToolUtils.java (added)
+++ db/derby/code/trunk/java/tools/org/apache/derby/iapi/tools/ToolUtils.java Tue Apr 23 14:40:29 2013
@@ -0,0 +1,80 @@
+/*
+
+   Derby - Class org.apache.derby.iapi.tools.ToolUtils
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.iapi.tools;
+
+public  abstract    class   ToolUtils
+{
+	///////////////////////////////////////////////////////////////////
+	//
+	// Methods to copy arrays. We'd like to use java.util.copyOf(), but
+    // we have to run on Java 5. The same methods also appear in
+    // org.apache.derby.iapi.services.io.ArrayUtil. They are repeated here
+    // in order to avoid sealing issues.
+	//
+	///////////////////////////////////////////////////////////////////
+
+    /** Copy an array of objects; the original array could be null */
+    public  static  Object[]    copy( Object[] original )
+    {
+        return (original == null) ? null : (Object[]) original.clone();
+    }
+
+    /** Copy a (possibly null) array of strings */
+    public  static  String[]    copy( String[] original )
+    {
+        return (original == null) ? null : (String[]) original.clone();
+    }
+
+    /** Copy a (possibly null) array of booleans */
+    public  static  boolean[]   copy( boolean[] original )
+    {
+        return (original == null) ? null : (boolean[]) original.clone();
+    }
+
+    /** Copy a (possibly null) array of bytes */
+    public  static  byte[]   copy( byte[] original )
+    {
+        return (original == null) ? null : (byte[]) original.clone();
+    }
+
+    /** Copy a (possibly null) array of ints */
+    public  static  int[]   copy( int[] original )
+    {
+        return (original == null) ? null : (int[]) original.clone();
+    }
+
+    /** Copy a (possibly null) 2-dimensional array of ints */
+    public  static  int[][]   copy2( int[][] original )
+    {
+        if ( original == null ) { return null; }
+
+        int[][] result = new int[ original.length ][];
+        for ( int i = 0; i < original.length; i++ )
+        {
+            result[ i ] = copy( original[ i ] );
+        }
+        
+        return result;
+    }
+
+
+}

Propchange: db/derby/code/trunk/java/tools/org/apache/derby/iapi/tools/ToolUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/tools/org/apache/derby/iapi/tools/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/iapi/tools/build.xml?rev=1470982&r1=1470981&r2=1470982&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/iapi/tools/build.xml (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/iapi/tools/build.xml Tue Apr 23 14:40:29 2013
@@ -51,7 +51,7 @@
       <classpath>
         <pathelement path="${compile.classpath}"/>
       </classpath>
-      <include name="${derby.dir}/iapi/tools/i18n/**"/>
+      <include name="${derby.dir}/iapi/tools/**"/>
       <exclude name="${derby.dir}/iapi/tools/run.java"/>
     </javac>
   </target>

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/build.xml?rev=1470982&r1=1470981&r2=1470982&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/build.xml (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/build.xml Tue Apr 23 14:40:29 2013
@@ -31,6 +31,8 @@
   <!-- Compile-time classpath properties files -->
   <property file="${properties.dir}/extrapath.properties"/>
   <property file="${properties.dir}/compilepath.properties"/>
+  <property name="ijConstants.src" value="${generated.src.dir}/${derby.dir}/impl/tools/ij/ijConstants.java"/>
+  <property name="ijTokenManager.src" value="${generated.src.dir}/${derby.dir}/impl/tools/ij/ijTokenManager.java"/>
 
 <!-- Targets -->
   <target name="compile" depends="compile_tools_impl,optional"/>
@@ -83,6 +85,10 @@
       </fileset>
     </delete>
 
+    <!-- reduce the visibility of these files from public to package protection -->
+    <replaceregexp file="${ijConstants.src}" match="public interface" replace="interface"/>
+    <replaceregexp file="${ijTokenManager.src}" match="public class" replace="class"/>
+
   </target>
 
   <target name="compile_tools_impl" depends="parser">

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ParseException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ParseException.java?rev=1470982&r1=1470981&r2=1470982&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ParseException.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ParseException.java Tue Apr 23 14:40:29 2013
@@ -21,6 +21,8 @@
  */
 package org.apache.derby.impl.tools.ij;
 
+import org.apache.derby.iapi.tools.ToolUtils;
+
 /**
  * This exception is thrown when parse errors are encountered.
  * You can explicitly create objects of this exception type by
@@ -51,8 +53,8 @@ public class ParseException extends Exce
     super("");
     specialConstructor = true;
     currentToken = currentTokenVal;
-    expectedTokenSequences = expectedTokenSequencesVal;
-    tokenImage = tokenImageVal;
+    expectedTokenSequences = ToolUtils.copy2( expectedTokenSequencesVal );
+    tokenImage = ToolUtils.copy( tokenImageVal );
   }
 
   /**
@@ -80,28 +82,28 @@ public class ParseException extends Exce
    * this object and thereby affects the semantics of the
    * "getMessage" method (see below).
    */
-  protected boolean specialConstructor;
+  private boolean specialConstructor;
 
   /**
    * This is the last token that has been consumed successfully.  If
    * this object has been created due to a parse error, the token
    * followng this token will (therefore) be the first error token.
    */
-  public Token currentToken;
+  private Token currentToken;
 
   /**
    * Each entry in this array is an array of integers.  Each array
    * of integers represents a sequence of tokens (by their ordinal
    * values) that is expected at this point of the parse.
    */
-  public int[][] expectedTokenSequences;
+  private int[][] expectedTokenSequences;
 
   /**
    * This is a reference to the "tokenImage" array of the generated
    * parser within which the parse error occurred.  This array is
    * defined in the generated ...Constants interface.
    */
-  public String[] tokenImage;
+  private String[] tokenImage;
 
   /**
    * This method has the standard behavior when this object has been
@@ -160,14 +162,14 @@ public class ParseException extends Exce
   /**
    * The end of line string for this machine.
    */
-  protected String eol = System.getProperty("line.separator", "\n");
+  private String eol = System.getProperty("line.separator", "\n");
 
   /**
    * Used to convert raw characters to their escaped version
    * when these raw version cannot be used as part of an ASCII
    * string literal.
    */
-  protected String add_escapes(String str) {
+  private String add_escapes(String str) {
       StringBuffer retval = new StringBuffer();
       char ch;
       for (int i = 0; i < str.length(); i++) {

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/URLCheck.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/URLCheck.java?rev=1470982&r1=1470981&r2=1470982&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/URLCheck.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/URLCheck.java Tue Apr 23 14:40:29 2013
@@ -42,11 +42,11 @@ import java.sql.SQLException;
 
 public class URLCheck {
 
-  public Vector attributes;
-  public static Vector booleanAttributes;
+  private   Vector attributes;
+  private   static Vector booleanAttributes;
   //Need so that AppUI class does not get garbage collected
-  LocalizedResource langUtil = LocalizedResource.getInstance();
-  Vector validProps;
+  private   LocalizedResource langUtil = LocalizedResource.getInstance();
+  private   Vector validProps;
 
   public URLCheck(String anURL) {
 

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java?rev=1470982&r1=1470981&r2=1470982&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java Tue Apr 23 14:40:29 2013
@@ -31,16 +31,18 @@ import java.sql.SQLWarning;
 import java.util.List;
 import java.util.ArrayList;
 
+import org.apache.derby.iapi.tools.ToolUtils;
+
 /**
  * This impl is intended to be used with multiple resultsets, where
  * the execution of the statement is already complete.
  */
 public class ijMultipleResultSetResult extends ijResultImpl {
 
-    List resultSets = null;
+    private ArrayList resultSets = null;
 
-    int[] displayColumns = null;
-    int[] columnWidths = null;
+    private int[] displayColumns = null;
+    private int[] columnWidths = null;
 
     /**
      * Create a ijResultImpl that represents multiple result sets, only
@@ -57,8 +59,8 @@ public class ijMultipleResultSetResult e
         this.resultSets = new ArrayList();
         this.resultSets.addAll(resultSets);
 
-        displayColumns = display;
-        columnWidths   = widths;
+        displayColumns = ToolUtils.copy( display );
+        columnWidths   = ToolUtils.copy( widths );
     }
 
 
@@ -71,7 +73,7 @@ public class ijMultipleResultSetResult e
     }
 
     public List getMultipleResultSets() {
-        return resultSets;
+        return (List) resultSets.clone();
     }
 
     public void closeStatement() throws SQLException {
@@ -85,8 +87,8 @@ public class ijMultipleResultSetResult e
         }
     }
 
-    public int[] getColumnDisplayList() { return displayColumns; }
-    public int[] getColumnWidthList() { return columnWidths; }
+    public int[] getColumnDisplayList() { return ToolUtils.copy( displayColumns ); }
+    public int[] getColumnWidthList() { return ToolUtils.copy( columnWidths ); }
 
     /**
      * @return the warnings from all resultsets as one SQLWarning chain

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijResultSetResult.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijResultSetResult.java?rev=1470982&r1=1470981&r2=1470982&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijResultSetResult.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijResultSetResult.java Tue Apr 23 14:40:29 2013
@@ -28,17 +28,19 @@ import java.sql.Statement;
 import java.sql.SQLException;
 import java.sql.SQLWarning;
 
+import org.apache.derby.iapi.tools.ToolUtils;
+
 /**
  * This impl is intended to be used with a resultset,
  * where the execution of the statement is already complete.
  */
 public class ijResultSetResult extends ijResultImpl {
 
-	ResultSet resultSet;
-	Statement statement;
+	private ResultSet resultSet;
+	private Statement statement;
 
-	int[]     displayColumns = null;
-	int[]     columnWidths = null;
+	private int[]     displayColumns = null;
+	private int[]     columnWidths = null;
 
 	/**
 	 * Create a ijResultImpl that represents a result set.
@@ -63,8 +65,8 @@ public class ijResultSetResult extends i
 		resultSet = r;
 		statement = resultSet.getStatement();
 
-		displayColumns = display;
-		columnWidths   = widths;
+		displayColumns = ToolUtils.copy( display );
+		columnWidths   = ToolUtils.copy( widths );
 	}
 
 	public boolean isResultSet() throws SQLException { return statement==null || statement.getUpdateCount() == -1; }
@@ -73,8 +75,8 @@ public class ijResultSetResult extends i
 
 	public void closeStatement() throws SQLException { if(statement!=null) statement.close(); else resultSet.close(); }
 
-	public int[] getColumnDisplayList() { return displayColumns; }
-	public int[] getColumnWidthList() { return columnWidths; }
+	public int[] getColumnDisplayList() { return ToolUtils.copy( displayColumns ); }
+	public int[] getColumnWidthList() { return ToolUtils.copy( columnWidths ); }
 
 	public SQLWarning getSQLWarnings() throws SQLException { return resultSet.getWarnings(); }
 	public void clearSQLWarnings() throws SQLException { resultSet.clearWarnings(); }