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 2006/08/25 19:49:05 UTC

svn commit: r436875 - in /db/derby/code/branches/10.2/java: engine/org/apache/derby/iapi/sql/dictionary/ engine/org/apache/derby/impl/sql/catalog/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/org/apache/derbyTesting/functionTests/t...

Author: rhillegas
Date: Fri Aug 25 10:49:03 2006
New Revision: 436875

URL: http://svn.apache.org/viewvc?rev=436875&view=rev
Log:
DERBY-1725: Merged patches from trunk to the 10.2 branch: DERBY-1739 (433446), DERBY-744 (433445, 433443), DERBY-1734 (433434, 433349, ), DERBY-1609 (433331, 433274, 433273).

Added:
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IJRunScriptTest.java
      - copied unchanged from r433447, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IJRunScriptTest.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
      - copied unchanged from r433447, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
Modified:
    db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/sql/dictionary/SystemColumn.java
    db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/IndexInfoImpl.java
    db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java
    db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/SystemColumnImpl.java
    db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/TabInfoImpl.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
    db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/Main.java
    db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ij.jj
    db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/mtTestCase.java
    db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/utilMain.java
    db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/JDBCDisplayUtil.java
    db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/ij.java

Modified: db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/sql/dictionary/SystemColumn.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/sql/dictionary/SystemColumn.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/sql/dictionary/SystemColumn.java (original)
+++ db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/sql/dictionary/SystemColumn.java Fri Aug 25 10:49:03 2006
@@ -40,13 +40,6 @@
 	 * @return	The column name.
 	 */
 	public String	getName();
-
-	/**
-	 * Gets the id of this column.
-	 *
-	 * @return	The column id.
-	 */
-	public int	getID();
     
     /**
      * Return the type of this column.

Modified: db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java (original)
+++ db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java Fri Aug 25 10:49:03 2006
@@ -6505,7 +6505,7 @@
 		TableDescriptor td = getTableDescriptor(rowFactory.getCatalogName(), sd);
 
 		theColumn = columns[columnNumber - 1];	// from 1 to 0 based
-		ColumnDescriptor cd = makeColumnDescriptor(theColumn, td );
+		ColumnDescriptor cd = makeColumnDescriptor(theColumn, columnNumber, td );
 		columnName = cd.getColumnName();
 		cd.getType().setNullability(nullability);
 		int[] columnNameColArray = new int[1];
@@ -6583,7 +6583,7 @@
 			columnID = newColumnIDs[ix];
 			currentColumn = columns[ columnID - 1 ];	// from 1 to 0 based
 
-			cdArray[ix] = makeColumnDescriptor( currentColumn, td );
+			cdArray[ix] = makeColumnDescriptor( currentColumn, ix + 1, td );
 		}
 		addDescriptorArray(cdArray, td, SYSCOLUMNS_CATALOG_NUM, false, tc);
 
@@ -7215,7 +7215,8 @@
 					SanityManager.THROWASSERT("column "+columnNumber+" for table "+ti.getTableName()+" is null");
 				}
 			}
-			cdlArray[columnNumber] = makeColumnDescriptor( column, td );
+			cdlArray[columnNumber] = makeColumnDescriptor( column,
+                    columnNumber + 1, td );
 		}
 		addDescriptorArray(cdlArray, td, SYSCOLUMNS_CATALOG_NUM, false, tc);
 		
@@ -7229,6 +7230,7 @@
 	  *	Converts a SystemColumn to a ColumnDescriptor.
 	  *
 	  *	@param	column	a SystemColumn
+      * @param  columnPosition Position of the column in the table, one based.
 	  *	@param	td		descriptor for table that column lives in
 	  *
 	  *	@return	a ColumnDes*criptor
@@ -7236,12 +7238,13 @@
 	  *	@exception StandardException Standard Cloudscape error policy
 	  */
 	private	ColumnDescriptor	makeColumnDescriptor( SystemColumn		column,
+            int columnPosition,
 													  TableDescriptor	td )
 						throws StandardException
 	{
 		//RESOLVEAUTOINCREMENT
 		return new ColumnDescriptor
-			(column.getName(), column.getID(), column.getType(), null, null, td,
+			(column.getName(), columnPosition, column.getType(), null, null, td,
 			 (UUID) null, // No defaults yet for system columns
 			 0, 0
 			 );

Modified: db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/IndexInfoImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/IndexInfoImpl.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/IndexInfoImpl.java (original)
+++ db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/IndexInfoImpl.java Fri Aug 25 10:49:03 2006
@@ -35,15 +35,15 @@
 *
 * @author jerry
 */
-public class IndexInfoImpl
+class IndexInfoImpl
 {
-	boolean				isUnique;
-	String[]			columnNames;
-	int[]				columnPositions;
-	IndexRowGenerator	irg;
-	int					columnCount;
-	long				conglomerateNumber;
-	String				name;
+	private boolean				isUnique;
+	private String[]			columnNames;
+	private int[]				columnPositions;
+	private IndexRowGenerator	irg;
+	private int					columnCount;
+	private long				conglomerateNumber;
+	private String				name;
 
 	/**
 	 * Constructor
@@ -72,7 +72,7 @@
 	 *
 	 * @return long	The conglomerate number for the index.
 	 */
-	public long getConglomerateNumber()
+	long getConglomerateNumber()
 	{
 		return conglomerateNumber;
 	}
@@ -82,7 +82,7 @@
 	 *
 	 * @param conglomerateNumber	The conglomerateNumber for the index.
 	 */
-	public void setConglomerateNumber(long conglomerateNumber)
+	void setConglomerateNumber(long conglomerateNumber)
 	{
 		this.conglomerateNumber = conglomerateNumber;
 	}
@@ -92,7 +92,7 @@
 	 *
 	 * @return String	The index name for the index.
 	 */
-	public String getIndexName()
+	String getIndexName()
 	{
 		return name;
 	}
@@ -102,7 +102,7 @@
 	 *
 	 * @param indexName		The name for the index.
 	 */
-	public void setIndexName(String indexName)
+	void setIndexName(String indexName)
 	{
 		name = indexName;
 	}
@@ -112,7 +112,7 @@
 	 *
 	 * @return int	The column count for the index.
 	 */
-	public int getColumnCount()
+	int getColumnCount()
 	{
 		return columnCount;
 	}
@@ -122,7 +122,7 @@
 	 *
 	 * @return IndexRowGenerator	The IRG for this index.
 	 */
-	public IndexRowGenerator getIndexRowGenerator()
+	IndexRowGenerator getIndexRowGenerator()
 	{
 		return irg;
 	}
@@ -132,7 +132,7 @@
 	 *
 	 * @param irg			The IndexRowGenerator for this index.
 	 */
-	public void setIndexRowGenerator(IndexRowGenerator irg)
+	void setIndexRowGenerator(IndexRowGenerator irg)
 	{
 		this.irg = irg;
 	}
@@ -145,7 +145,7 @@
 	 *
 	 * @return int		The base column position for the column.
 	 */
-	public int getBaseColumnPosition(int colNumber)
+	int getBaseColumnPosition(int colNumber)
 	{
 		return columnPositions[colNumber];
 	}
@@ -157,7 +157,7 @@
 	 * @param colNumber		The column number within the index
 	 * @param baseColumnPosition	The base column position for the column.
 	 */
-	public void setBaseColumnPosition(int colNumber,
+	void setBaseColumnPosition(int colNumber,
 									 int baseColumnPosition)
 	{
 		columnPositions[colNumber] = baseColumnPosition;
@@ -168,7 +168,7 @@
 	 *
 	 * @return boolean		Whether or not this index is declared unique
 	 */
-	public boolean isIndexUnique()
+	boolean isIndexUnique()
 	{
 		return isUnique;
 	}

Modified: db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java (original)
+++ db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java Fri Aug 25 10:49:03 2006
@@ -22,6 +22,7 @@
 package org.apache.derby.impl.sql.catalog;
 
 import org.apache.derby.iapi.types.TypeId;
+import org.apache.derby.iapi.reference.JDBC30Translation;
 import org.apache.derby.iapi.sql.dictionary.SystemColumn;
 import org.apache.derby.catalog.TypeDescriptor;
 
@@ -423,115 +424,31 @@
 										aliasInfo, specificName);
 	}
 
-	/**
-	 * Builds a list of columns suitable for creating this Catalog.
-	 *
-	 *
-	 * @return array of SystemColumn suitable for making this catalog.
-	 */
-	public SystemColumn[]	buildColumnList()
-	{
-		SystemColumn[]			columnList = new SystemColumn[SYSALIASES_COLUMN_COUNT];
-
-		// describe columns
-
-		columnList[0] =
-					new SystemColumnImpl(
-							convertIdCase( "ALIASID"),			// column name
-							1,	// column number
-							0,					// precision
-							0,					// scale
-							false,				// nullability
-							"CHAR",				// dataType
-							true,				// built-in type
-							36					// maxLength
-			               );
-
-		columnList[1] =
-					new SystemColumnImpl(
-							convertIdCase( "ALIAS"),			// column name
-							2,	// column number
-							false				// nullability
-			               );
-
-		columnList[2] = new SystemColumnImpl(	
-								convertIdCase( "SCHEMAID"),			// column name
-								3,	// column number
-								0,					// precision
-								0,					// scale
-								true,				// nullability
-								"CHAR",				// dataType
-								true,				// built-in type
-								36					// maxLength
-			                   );
-
-		columnList[3] =
-					new SystemColumnImpl(
-							convertIdCase( "JAVACLASSNAME"),		// column name
-							4,
-							0,					// precision
-							0,					// scale
-							false,				// nullability
-							"LONG VARCHAR",			// dataType
-							true,				// built-in type
-							Integer.MAX_VALUE	// maxLength
-							);
-
-		columnList[4] =
-					new SystemColumnImpl(
-							convertIdCase( "ALIASTYPE"),		// column name
-							5,
-							0,					// precision
-							0,					// scale
-							false,				// nullability
-							"CHAR",			// dataType
-							true,				// built-in type
-							1					// maxLength
-							);
-
-		columnList[5] =
-					new SystemColumnImpl(
-							convertIdCase( "NAMESPACE"),		// column name
-							6,
-							0,					// precision
-							0,					// scale
-							false,				// nullability
-							"CHAR",			// dataType
-							true,				// built-in type
-							1					// maxLength
-							);
-
-		columnList[6] =
-					new SystemColumnImpl(
-							convertIdCase( "SYSTEMALIAS"),		// column name
-							7,
-							0,					// precision
-							0,					// scale
-							false,				// nullability
-							"BOOLEAN",			// dataType
-							true,				// built-in type
-							0					// maxLength
-							);
-
-		columnList[7] = 
-					new SystemColumnImpl(	
-							convertIdCase( "ALIASINFO"),			// column name
-							8,	// column number
-							0,					// precision
-							0,					// scale
-							true,				// nullability
-							"org.apache.derby.catalog.AliasInfo",	    // dataType
-							false,				// built-in type
-							TypeDescriptor.MAXIMUM_WIDTH_UNKNOWN // maxLength
-			               );
-
-		columnList[8] =
-					new SystemColumnImpl(
-							convertIdCase( "SPECIFICNAME"),
-							9,	// column number
-							false				// nullability
-			               );
-
-		return	columnList;
-	}
+    /**
+     * Builds a list of columns suitable for creating this Catalog.
+     * DERBY-1734 fixed an issue where older code created the
+     * BOOLEAN column SYSTEMALIAS with maximum length 0 instead of 1.
+     * DERBY-1742 was opened to track if upgrade changes are needed.
+     *
+     *
+     * @return array of SystemColumn suitable for making this catalog.
+     */
+    public SystemColumn[]   buildColumnList()
+    {
+      return new SystemColumn[] {
+        
+        SystemColumnImpl.getUUIDColumn("ALIASID", false),
+        SystemColumnImpl.getIdentifierColumn("ALIAS", false),
+        SystemColumnImpl.getUUIDColumn("SCHEMAID", true),
+        SystemColumnImpl.getColumn("JAVACLASSNAME",
+                java.sql.Types.LONGVARCHAR, false, Integer.MAX_VALUE),
+        SystemColumnImpl.getIndicatorColumn("ALIASTYPE"),
+        SystemColumnImpl.getIndicatorColumn("NAMESPACE"),
+        SystemColumnImpl.getColumn("SYSTEMALIAS",
+                JDBC30Translation.SQL_TYPES_BOOLEAN, false),
+        SystemColumnImpl.getJavaColumn("ALIASINFO",
+                "org.apache.derby.catalog.AliasInfo", true),
+        SystemColumnImpl.getIdentifierColumn("SPECIFICNAME", false)
+        };
+    }
 }

Modified: db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/SystemColumnImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/SystemColumnImpl.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/SystemColumnImpl.java (original)
+++ db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/SystemColumnImpl.java Fri Aug 25 10:49:03 2006
@@ -21,6 +21,8 @@
 
 package org.apache.derby.impl.sql.catalog;
 
+import java.sql.Types;
+
 import	org.apache.derby.iapi.sql.dictionary.SystemColumn;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.types.DataTypeDescriptor;
@@ -36,38 +38,139 @@
  * @author Rick Hillegas
  */
 
-public class SystemColumnImpl implements SystemColumn
+class SystemColumnImpl implements SystemColumn
 {
 	private	final String	name;
-	private	final int		id;
-    
+   
     /**
      * Fully described type of the column.
      */
     private final DataTypeDescriptor type;
+    
+    /**
+     * Create a system column for a builtin type.
+     * 
+     * @param name
+     *            name of column
+     * @param jdbcTypeId
+     *            JDBC type id from java.sql.Types
+     * @param nullability
+     *            Whether or not column accepts nulls.
+     */
+    static SystemColumn getColumn(String name, int jdbcTypeId,
+            boolean nullability) {
+        return new SystemColumnImpl(name, DataTypeDescriptor
+                .getBuiltInDataTypeDescriptor(jdbcTypeId, nullability));
+    }
+    
+    /**
+     * Create a system column for a builtin type.
+     * 
+     * @param name
+     *            name of column
+     * @param jdbcTypeId
+     *            JDBC type id from java.sql.Types
+     * @param nullability
+     *            Whether or not column accepts nulls.
+     */
+    static SystemColumn getColumn(String name, int jdbcTypeId,
+            boolean nullability,int maxLength) {
+        return new SystemColumnImpl(name, DataTypeDescriptor
+                .getBuiltInDataTypeDescriptor(jdbcTypeId, nullability, maxLength));
+    }
+    
+    /**
+     * Create a system column for an identifer with consistent type of
+     * VARCHAR(128)
+     * 
+     * @param name
+     *            Name of the column.
+     * @param nullability
+     *            Nullability of the column.
+     * @return Object representing the column.
+     */
+    static SystemColumn getIdentifierColumn(String name, boolean nullability) {
+        return new SystemColumnImpl(name, DataTypeDescriptor
+                .getBuiltInDataTypeDescriptor(Types.VARCHAR, nullability, 128));
+    }
+
+    /**
+     * Create a system column for a character representation of a UUID with
+     * consistent type of CHAR(36)
+     * 
+     * @param name
+     *            Name of the column.
+     * @param nullability
+     *            Nullability of the column.
+     * @return Object representing the column.
+     */
+    static SystemColumn getUUIDColumn(String name, boolean nullability) {
+        return new SystemColumnImpl(name, DataTypeDescriptor
+                .getBuiltInDataTypeDescriptor(Types.CHAR, nullability, 36));
+    }
+
+    /**
+     * Create a system column for a character representation of an indicator
+     * column with consistent type of CHAR(1) NOT NULL
+     * 
+     * @param name
+     *            Name of the column.
+     * @return Object representing the column.
+     */
+    static SystemColumn getIndicatorColumn(String name) {
+        return new SystemColumnImpl(name, DataTypeDescriptor
+                .getBuiltInDataTypeDescriptor(Types.CHAR, false, 1));
+    }
+
+    /**
+     * Create a system column for a java column.
+     * 
+     * @param name
+     *            Name of the column.
+     * @param javaClassName
+     * @param nullability
+     *            Nullability of the column.
+     * @return Object representing the column.
+     */
+    static SystemColumn getJavaColumn(String name, String javaClassName,
+            boolean nullability) {
+
+        TypeId typeId = TypeId.getUserDefinedTypeId(javaClassName, false);
+
+        DataTypeDescriptor dtd = new DataTypeDescriptor(typeId, nullability);
+        return new SystemColumnImpl(name, dtd);
+    }
+
+    /**
+     * Create a SystemColumnImpl representing the given name and type.
+     */
+    private SystemColumnImpl(String name, DataTypeDescriptor type) {
+        this.name = name;
+        this.type = type;
+    }
 
 	/**
-	 * Constructor to create a description of a column in a system table.
-	 *
-	 *	@param	name of column.
-	 *	@param	id of column.
-	 *	@param	precision of data in column.
-	 *	@param	scale of data in column.
-	 *	@param	nullability Whether or not column accepts nulls.
-	 *	@param	dataType Datatype of column.
-	 *	@param	maxLength Maximum length of data in column.
-	 */
-	public	SystemColumnImpl(	String	name,
+     * Constructor to create a description of a column in a system table.
+     * 
+     * @param name
+     *            of column.
+     * @param id
+     *            of column.
+     * @param nullability
+     *            Whether or not column accepts nulls.
+     * @param dataType
+     *            Datatype of column.
+     * @param maxLength
+     *            Maximum length of data in column.
+     */
+	SystemColumnImpl(	String	name,
 								int		id,
-								int		precision,
-								int		scale,
 								boolean	nullability,
 								String	dataType,
 								boolean	builtInType,
 								int		maxLength )
 	{
 		this.name			= name;
-		this.id				= id;
         
         TypeId  typeId;
 
@@ -83,12 +186,23 @@
 
         this.type = new DataTypeDescriptor(
                                typeId,
-                               precision,
-                               scale,
+                               0,
+                               0,
                                nullability,
                                maxLength
                                );
 	}
+    SystemColumnImpl(   String  name,
+            int     id,
+            int ignoreP,
+            int ignoreS,
+            boolean nullability,
+            String  dataType,
+            boolean builtInType,
+            int     maxLength )
+{
+        this(name, id, nullability, dataType, builtInType, maxLength);
+}
 
 	/**
 	 * Constructor to create a description of a column in a system table.
@@ -98,11 +212,11 @@
 	 *	@param	id of column.
 	 *	@param	nullability Whether or not column accepts nulls.
 	 */
-	public	SystemColumnImpl(	String	name,
+	SystemColumnImpl(	String	name,
 								int		id,
 								boolean	nullability)
 	{
-        this(name, id, 0, 0, nullability, "VARCHAR", true, 128);
+        this(name, id, nullability, "VARCHAR", true, 128);
 	}
 
 	/**
@@ -113,16 +227,6 @@
 	public String	getName()
 	{
 		return	name;
-	}
-
-	/**
-	 * Gets the id of this column.
-	 *
-	 * @return	The column id.
-	 */
-	public int	getID()
-	{
-		return	id;
 	}
 
     /**

Modified: db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/TabInfoImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/TabInfoImpl.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/TabInfoImpl.java (original)
+++ db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/catalog/TabInfoImpl.java Fri Aug 25 10:49:03 2006
@@ -60,7 +60,7 @@
 *
 * @author jamie
 */
-public class TabInfoImpl implements TabInfo
+class TabInfoImpl implements TabInfo
 {
 	private IndexInfoImpl[]				indexes;
 	private String						name;
@@ -77,7 +77,7 @@
 	 *
 	 * @param crf				the associated CatalogRowFactory
 	 */
-	public TabInfoImpl(CatalogRowFactory crf)
+	TabInfoImpl(CatalogRowFactory crf)
 	{
 		this.name = crf.getCatalogName();
 		this.heapConglomerate = -1;

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java Fri Aug 25 10:49:03 2006
@@ -1,6 +1,6 @@
 /*
 
-   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi._Suite
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang._Suite
 
        Licensed to the Apache Software Foundation (ASF) under one
        or more contributor license agreements.  See the NOTICE file

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java Fri Aug 25 10:49:03 2006
@@ -112,22 +112,20 @@
 		
 		ByteArrayOutputStream rawBytes =
 			new ByteArrayOutputStream(20 * 1024);
-		
-		PrintStream printOut = new PrintStream(rawBytes);
-	
+			
 		Connection conn = getXConnection();
 		org.apache.derby.tools.ij.runScript(
 				conn,
 				sqlIn,
 				inputEncoding,
-				printOut,
+                rawBytes,
 				outputEncoding);
 		
 		if (!conn.isClosed() && !conn.getAutoCommit())
 		    conn.commit();
 		
-		printOut.flush();
-		printOut.close();
+        rawBytes.flush();
+        rawBytes.close();
 		sqlIn.close();
 			
 		

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Fri Aug 25 10:49:03 2006
@@ -19,11 +19,17 @@
  */
 package org.apache.derbyTesting.junit;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
 import java.io.Reader;
+import java.io.UnsupportedEncodingException;
 import java.sql.*;
 
+import org.apache.derby.tools.ij;
+
 
 /**
  * Base class for JDBC JUnit tests.
@@ -177,6 +183,45 @@
     public Connection openConnection(String databaseName) throws SQLException
     {
         return getTestConfiguration().openConnection(databaseName);
+    }
+    
+    /**
+     * Run a SQL script through ij discarding the output
+     * using this object's default connection. Intended for
+     * setup scripts.
+     * @throws UnsupportedEncodingException 
+     * @throws SQLException 
+     */
+    public int runScript(InputStream script, String encoding)
+        throws UnsupportedEncodingException, SQLException
+    {
+        // Sink output.
+        OutputStream sink = new OutputStream() {
+            public void write(byte[] b, int off, int len) {}
+            public void write(int b) {}
+        };
+        
+        // Use the same encoding as the input for the output.    
+        return ij.runScript(getXConnection(), script, encoding,
+                sink, encoding);       
+    }
+    
+    /**
+     * Run a set of SQL commands from a String discarding the output.
+     * Commands are separated by a semi-colon. Connection used
+     * is this objects default connection.
+     * @param sqlCommands
+     * @return Number of errors executing the script.
+     * @throws UnsupportedEncodingException
+     * @throws SQLException
+     */
+    public int runSQLCommands(String sqlCommands)
+        throws UnsupportedEncodingException, SQLException
+    {
+        byte[] raw = sqlCommands.getBytes("UTF-8");
+        ByteArrayInputStream in = new ByteArrayInputStream(raw);
+        
+        return runScript(in, "UTF-8");
     }
     
     /**

Modified: db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/Main.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/Main.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/Main.java (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/Main.java Fri Aug 25 10:49:03 2006
@@ -216,7 +216,7 @@
 	        out = LocalizedResource.getInstance().getNewOutput(System.out);
 		}
 		utilInstance = getutilMain(1, out);
-		utilInstance.initConnections();
+		utilInstance.initFromEnvironment();
 	}
 
 	/**

Modified: db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ij.jj
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ij.jj?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ij.jj (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ij.jj Fri Aug 25 10:49:03 2006
@@ -128,6 +128,14 @@
 	ij(ijTokenManager tm, utilMain utilInstance) {
 		this(tm);
 		this.utilInstance = utilInstance;
+	}
+	
+	/**
+	   Initialize this parser from the environment
+	   (system properties). Used when ij is being run
+	   as a command line program.
+	*/
+	void initFromEnvironment() {
 
 		// load all protocols specified via properties
 		//

Modified: db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/mtTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/mtTestCase.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/mtTestCase.java (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/mtTestCase.java Fri Aug 25 10:49:03 2006
@@ -241,7 +241,7 @@
 	
 		out.println("--------------"+file+"-----------------");
 		utilInstance = new utilMain(1, out, ignoreErrors);
-		utilInstance.initConnections();
+		utilInstance.initFromEnvironment();
 		utilInstance.setMtUse(true);
 		utilInstance.go(in, out, (java.util.Properties) null);
 		log.flush();

Modified: db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/utilMain.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/utilMain.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/utilMain.java (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/utilMain.java Fri Aug 25 10:49:03 2006
@@ -78,6 +78,16 @@
 	private LocalizedOutput out = null;
 	private Properties connAttributeDefaults;
 	private Hashtable ignoreErrors;
+	/**
+	 * True if to display the error code when
+	 * displaying a SQLException.
+	 */
+	private final boolean showErrorCode;
+    
+    /**
+     * Value of the system property ij.execptionTrace
+     */
+    private final String ijExceptionTrace;
 
 	protected boolean isJCC;	//The driver being used is JCC
 
@@ -136,6 +146,13 @@
 		ijParser = new ij(ijTokMgr, this);
 		this.out = out;
 		this.ignoreErrors = ignoreErrors;
+		
+		showErrorCode = 
+			Boolean.valueOf(
+					util.getSystemProperty("ij.showErrorCode")
+					).booleanValue();
+        
+        ijExceptionTrace = util.getSystemProperty("ij.exceptionTrace");
 
 		this.numConnections = numConnections;
 		/* 1 StatementFinder and ConnectionEnv per connection/user. */
@@ -159,8 +176,10 @@
 	 * Initialize the connections from the environment.
 	 *
 	 */
-	public void initConnections()
+	public void initFromEnvironment()
 	{
+		ijParser.initFromEnvironment();
+		
 		for (int ictr = 0; ictr < numConnections; ictr++)
 		{
 			try {
@@ -257,23 +276,25 @@
 	 * @param conn
 	 * @param in
 	 */
-	public void goScript(Connection conn,
+	public int goScript(Connection conn,
 			LocalizedInput in)
 	{
 		JDBCDisplayUtil.showSelectCount = false;
 		connEnv[0].addSession(conn, (String) null);
 		fileInput = initialFileInput = !in.isStandardInput();
 		commandGrabber[0].ReInit(in);
-		runScriptGuts();
+		return runScriptGuts();
 	}
 	
 	/**
 	 * Run the guts of the script. Split out to allow
 	 * calling from the full ij and the minimal goScript.
+     * @return The number of errors seen in the script.
 	 *
 	 */
-	private void runScriptGuts() {
+	private int runScriptGuts() {
 
+        int scriptErrorCount = 0;
 		
 		boolean done = false;
 		String command = null;
@@ -345,18 +366,23 @@
 				}
 
     			} catch (ParseException e) {
-					if (command != null) doCatch(command);
+ 					if (command != null)
+                        scriptErrorCount += doCatch(command) ? 0 : 1;
 				} catch (TokenMgrError e) {
-					if (command != null) doCatch(command);
+ 					if (command != null)
+                        scriptErrorCount += doCatch(command) ? 0 : 1;
     			} catch (SQLException e) {
+                    scriptErrorCount++;
 					// SQL exception occurred in ij's actions; print and continue
 					// unless it is considered fatal.
 					handleSQLException(out,e);
     			} catch (ijException e) {
+                    scriptErrorCount++;
 					// exception occurred in ij's actions; print and continue
     			  	out.println(langUtil.getTextMessage("IJ_IjErro0",e.getMessage()));
 					doTrace(e);
     			} catch (Throwable e) {
+                    scriptErrorCount++;
     			  	out.println(langUtil.getTextMessage("IJ_JavaErro0",e.toString()));
 					doTrace(e);
 				}
@@ -364,6 +390,8 @@
 			/* Go to the next connection/user, if there is one */
 			currCE = ++currCE % connEnv.length;
 		}
+        
+        return scriptErrorCount;
 	}
 	
 	/**
@@ -470,12 +498,13 @@
 	 * catch processing on failed commands. This really ought to
 	 * be in ij somehow, but it was easier to catch in Main.
 	 */
-	private void doCatch(String command) {
+	private boolean doCatch(String command) {
 		// this retries the failed statement
 		// as a JSQL statement; it uses the
 		// ijParser since that maintains our
 		// connection and state.
 
+        
 	    try {
 			boolean	elapsedTimeOn = ijParser.getElapsedTimeState();
 			long	beginTime = 0;
@@ -494,6 +523,7 @@
 				out.println(langUtil.getTextMessage("IJ_ElapTime0Mil_4", 
 				langUtil.getNumberAsString(endTime - beginTime)));
 			}
+            return true;
 
 	    } catch (SQLException e) {
 			// SQL exception occurred in ij's actions; print and continue
@@ -509,6 +539,7 @@
 	  		out.println(langUtil.getTextMessage("IJ_JavaErro0_7", t.toString()));
 			doTrace(t);
 	    }
+        return false;
 	}
 
 	/**
@@ -524,7 +555,7 @@
 		String sqlState = null;
 		SQLException fatalException = null;
 
-		if (Boolean.getBoolean("ij.showErrorCode")) {
+		if (showErrorCode) {
 			errorCode = langUtil.getTextMessage("IJ_Erro0", 
 			langUtil.getNumberAsString(e.getErrorCode()));
 		}
@@ -557,7 +588,7 @@
 			String st1 = JDBCDisplayUtil.mapNull(e.getSQLState(),langUtil.getTextMessage("IJ_NoSqls"));
 			String st2 = JDBCDisplayUtil.mapNull(e.getMessage(),langUtil.getTextMessage("IJ_NoMess"));
 			out.println(langUtil.getTextMessage("IJ_Erro012",  st1, st2, errorCode));
-			JDBCDisplayUtil.doTrace(out, e);
+			doTrace(e);
 		}
 		if (fatalException != null)
 		{
@@ -569,7 +600,7 @@
 	 * stack trace dumper
 	 */
 	private void doTrace(Throwable t) {
-		if (util.getSystemProperty("ij.exceptionTrace") != null) {
+		if (ijExceptionTrace != null) {
 			t.printStackTrace(out);
 		}
 		out.flush();

Modified: db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/JDBCDisplayUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/JDBCDisplayUtil.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/JDBCDisplayUtil.java (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/JDBCDisplayUtil.java Fri Aug 25 10:49:03 2006
@@ -67,40 +67,6 @@
         LocalizedResource.getInstance();
     }
 
-
-	//-----------------------------------------------------------------
-	// Methods for initialization resource bundle and codeset's output
-	
-	/**
-	 * init method - will init the class to support a locale and
-	 * codeset based on the derby.ui.locale and derby.ui.codeset
-	 * properties if exists or using the default values from the JVM.
-	 */
-	static public boolean init() {
-		return (LocalizedResource.getInstance() != null);
-	}
-
-	/**
-	 * init method - will init the class to support a locale and
-	 * codeset based on the derby.ui.locale properties and on the 
-     * given codeset if exists or using the default values from the JVM.
-	 */
-	public static boolean init(String codeset) {
-		return init(codeset, null);
-	}
-
-	/**
-	 * init method - will init the class to support a locale and
-	 * codeset based on the given codeset and locale.
-	 * If the parameters are null it will try to init use derby.ui.locale
-	 * and derby.ui.codeset properties if exists or using the default
-	 * values from the JVM.
-	 */
-	public static boolean init(String pCodeset, String pLocale) {
-		LocalizedResource.getInstance().init(pCodeset, pLocale,null);
-		return true;
-	}
-
 	//-----------------------------------------------------------------
 	// Methods for displaying and checking errors
 

Modified: db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/ij.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/ij.java?rev=436875&r1=436874&r2=436875&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/ij.java (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/ij.java Fri Aug 25 10:49:03 2006
@@ -31,6 +31,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
 import java.sql.Connection;
@@ -74,11 +75,12 @@
   /**
    * Run a SQL script from an InputStream and write
    * the resulting output to the provided PrintStream.
+   * SQL commands are separated by a semi-colon ';' character.
    * 
    * @param conn Connection to be used as the script's default connection. 
    * @param sqlIn InputStream for the script.
    * @param inputEncoding Encoding of the script.
-   * @param sqlOut PrintStream for the script's output
+   * @param sqlOut OutputStream for the script's output
    * @param outputEncoding Output encoding to use.
    * @return Number of SQLExceptions thrown during the execution, -1 if not known.
    * @throws UnsupportedEncodingException
@@ -87,7 +89,7 @@
 		  Connection conn,
 		  InputStream sqlIn,
 		  String inputEncoding,
-		  PrintStream sqlOut,
+		  OutputStream sqlOut,
 		  String outputEncoding)
 		  throws UnsupportedEncodingException
   {
@@ -119,9 +121,7 @@
 	  
 	  utilMain um = ijE.getutilMain(1, lo);
 
-	  um.goScript(conn, li);
-	  
-	  return -1;
+	  return um.goScript(conn, li);
   }
 
   private ij() { // no instances allowed