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 dj...@apache.org on 2006/08/21 22:31:08 UTC

svn commit: r433349 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/sql/dictionary/SystemColumn.java impl/sql/catalog/DataDictionaryImpl.java impl/sql/catalog/SystemColumnImpl.java

Author: djd
Date: Mon Aug 21 13:31:07 2006
New Revision: 433349

URL: http://svn.apache.org/viewvc?rev=433349&view=rev
Log:
DERBY-1734 (partial) Add some utilitiy static factory methods to SystemColumnImpl to allow
easier building of system column lists for CatalogRowFactory. Remove column position (identifer)
from SystemColumn since it was redundant information. Still passed in some constructors of
SystemColumnImpl until all of the CatalogRowFactory implementations are modified to have
cleaner buildColumnList methods.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SystemColumn.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SystemColumnImpl.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SystemColumn.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SystemColumn.java?rev=433349&r1=433348&r2=433349&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SystemColumn.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SystemColumn.java Mon Aug 21 13:31:07 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/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=433349&r1=433348&r2=433349&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java Mon Aug 21 13:31:07 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/trunk/java/engine/org/apache/derby/impl/sql/catalog/SystemColumnImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SystemColumnImpl.java?rev=433349&r1=433348&r2=433349&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SystemColumnImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SystemColumnImpl.java Mon Aug 21 13:31:07 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,123 @@
  * @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 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 +170,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 +196,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 +211,6 @@
 	public String	getName()
 	{
 		return	name;
-	}
-
-	/**
-	 * Gets the id of this column.
-	 *
-	 * @return	The column id.
-	 */
-	public int	getID()
-	{
-		return	id;
 	}
 
     /**