Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C94E610A4F for ; Tue, 23 Apr 2013 14:40:52 +0000 (UTC) Received: (qmail 98788 invoked by uid 500); 23 Apr 2013 14:40:52 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 98719 invoked by uid 500); 23 Apr 2013 14:40:52 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 98712 invoked by uid 99); 23 Apr 2013 14:40:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Apr 2013 14:40:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Apr 2013 14:40:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 47F4023888E7; Tue, 23 Apr 2013 14:40:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1470982 - in /db/derby/code/trunk/java/tools/org/apache/derby: iapi/tools/ impl/tools/ impl/tools/ij/ Date: Tue, 23 Apr 2013 14:40:29 -0000 To: derby-commits@db.apache.org From: rhillegas@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130423144030.47F4023888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ - + 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 @@ + + @@ -83,6 +85,10 @@ + + + + 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(); }