db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r617238 - in /db/derby/code/trunk/java/engine/org/apache/derby: catalog/ catalog/types/ iapi/types/ impl/sql/compile/
Date Thu, 31 Jan 2008 21:06:08 GMT
Author: djd
Date: Thu Jan 31 13:06:03 2008
New Revision: 617238

URL: http://svn.apache.org/viewvc?rev=617238&view=rev
Log:
DERBY-2917 (partial) Cleanup of code relating to row multi-set types (used as the return type
for Derby's table functions.
1) Add methods to the api (TypeDescriptor) side to fetch information about the row's types
and column names, rather than have all callers have knowledge of the type implementation.
2) Treat a row multi-set type as only a catalog type (TypeDescriptor). Runtime types only
make sense for the types of the individual columns (when used in a query).

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/GetProcedureColumns.java
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/TypeDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/GetProcedureColumns.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/GetProcedureColumns.java?rev=617238&r1=617237&r2=617238&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/GetProcedureColumns.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/GetProcedureColumns.java Thu
Jan 31 13:06:03 2008
@@ -33,7 +33,6 @@
 import org.apache.derby.iapi.sql.ResultColumnDescriptor;
 import org.apache.derby.impl.jdbc.EmbedResultSetMetaData;
 import org.apache.derby.catalog.types.RoutineAliasInfo;
-import org.apache.derby.catalog.types.RowMultiSetImpl;
 
 import org.apache.derby.shared.common.reference.JDBC40Translation;
 /**
@@ -107,7 +106,7 @@
 	private boolean isFunction;
 	private int          rowCount;
 	private int          returnedTableColumnCount;
-	private RowMultiSetImpl tableFunctionReturnType;
+	private TypeDescriptor tableFunctionReturnType;
     
 	// state for procedures.
 	private RoutineAliasInfo procedure;
@@ -144,8 +143,8 @@
             
 			rowCount = procedure.getParameterCount();
 			if ( procedure.isTableFunction() ) {
-			    tableFunctionReturnType = (RowMultiSetImpl) ((DataTypeDescriptor) procedure.getReturnType()).getTypeId().getBaseTypeId();
-			    returnedTableColumnCount = tableFunctionReturnType.getColumnNames().length;
+			    tableFunctionReturnType = procedure.getReturnType();
+			    returnedTableColumnCount = tableFunctionReturnType.getRowColumnNames().length;
 			    rowCount += returnedTableColumnCount;
 			    functionParamCursor = -1;
 		        }
@@ -175,8 +174,8 @@
 		if ( procedure.isTableFunction() && (  paramCursor >= procedure.getParameterCount()
) ) {
 			int     idx = paramCursor - procedure.getParameterCount();
             
-			sqlType      = tableFunctionReturnType.getTypes()[ idx ];
-			columnName   = tableFunctionReturnType.getColumnNames()[ idx ];
+			sqlType      = tableFunctionReturnType.getRowTypes()[ idx ];
+			columnName   = tableFunctionReturnType.getRowColumnNames()[ idx ];
 			columnType   = (short) JDBC40Translation.FUNCTION_COLUMN_RESULT;
 		}
 		else if (paramCursor > -1) {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/TypeDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/TypeDescriptor.java?rev=617238&r1=617237&r2=617238&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/TypeDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/TypeDescriptor.java Thu Jan 31
13:06:03 2008
@@ -175,5 +175,23 @@
 	 * Return true if this is a Row Multiset type
 	  */
 	public	boolean isRowMultiSet();
+    
+    /**
+     * If this catalog type is a row multi-set type
+     * then return its array of catalog types.
+     * 
+     * @return Catalog ypes comprising the row,
+     * null if this is not a row type.
+     */
+    public TypeDescriptor[] getRowTypes();
+
+    /**
+     * If this catalog type is a row multi-set type
+     * then return its array of column names.
+     * 
+     * @return Column names comprising the row,
+     * null if this is not a row type.
+     */
+    public String[] getRowColumnNames();
 }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java?rev=617238&r1=617237&r2=617238&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
Thu Jan 31 13:06:03 2008
@@ -398,7 +398,7 @@
 	 */
 	public	boolean isRowMultiSet()
 	{
-		return false;
+		return typeId instanceof RowMultiSetImpl;
 	}
 
 	/** @see TypeDescriptor#getCollationType() */
@@ -573,4 +573,18 @@
 	 *	@return	the formatID of this class
 	 */
 	public	int	getTypeFormatId()	{ return StoredFormatIds.DATA_TYPE_IMPL_DESCRIPTOR_V01_ID;
}
+
+    public String[] getRowColumnNames() {
+        if (!isRowMultiSet())
+            return null;
+
+        return ((RowMultiSetImpl) typeId).getColumnNames();
+    }
+
+    public TypeDescriptor[] getRowTypes() {
+        if (!isRowMultiSet())
+            return null;
+
+        return ((RowMultiSetImpl) typeId).getTypes();
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java?rev=617238&r1=617237&r2=617238&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java Thu
Jan 31 13:06:03 2008
@@ -323,14 +323,14 @@
 	}
     
 	/**
-	 * Get a DataTypeServices that corresponds to a SQL Row Multiset
+	 * Get a catalog type that corresponds to a SQL Row Multiset
 	 *
 	 * @param columnNames   Names of the columns in the Row Muliset
 	 * @param types                 Types of the columns in the Row Muliset
 	 *
 	 * @return	A new DataTypeDescriptor describing the SQL Row Multiset
 	 */
-	public static DataTypeDescriptor getRowMultiSet
+	public static TypeDescriptor getRowMultiSet
 	(
 		String[]	                        columnNames,
 		DataTypeDescriptor[]	types
@@ -343,7 +343,7 @@
 		RowMultiSetImpl rms = new RowMultiSetImpl(columnNames, catalogTypes);
 		TypeId              typeID = new TypeId( StoredFormatIds.ROW_MULTISET_CATALOG_ID, rms );
 
-		return new DataTypeDescriptor( typeID, true);
+		return new DataTypeDescriptor( typeID, true).getCatalogType();
 	}
 
 	/*
@@ -1749,6 +1749,20 @@
             name = name + " (" + getCollationName() + ")";
         }
         return name;    
+    }
+
+    // TEMP: DERBY-2917 - refactoring type system
+    public String[] getRowColumnNames() {
+        if (SanityManager.DEBUG)
+            SanityManager.THROWASSERT("Row type must always be a catalog type");
+        return null;
+    }
+
+    // TEMP: DERBY-2917 - refactoring type system
+    public TypeDescriptor[] getRowTypes() {
+        if (SanityManager.DEBUG)
+            SanityManager.THROWASSERT("Row type must always be a catalog type");
+        return null;
     }
 }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java?rev=617238&r1=617237&r2=617238&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
Thu Jan 31 13:06:03 2008
@@ -40,7 +40,6 @@
 import org.apache.derby.catalog.AliasInfo;
 import org.apache.derby.catalog.TypeDescriptor;
 import org.apache.derby.catalog.types.RoutineAliasInfo;
-import org.apache.derby.catalog.types.RowMultiSetImpl;
 import org.apache.derby.catalog.types.SynonymAliasInfo;
 import org.apache.derby.catalog.types.TypeDescriptorImpl;
 
@@ -315,12 +314,11 @@
 		if ( aliasInfo.isTableFunction() )
         {
             RoutineAliasInfo    info = (RoutineAliasInfo) aliasInfo;
-            RowMultiSetImpl     tableFunctionReturnType = (RowMultiSetImpl) ((DataTypeDescriptor)
info.getReturnType()).getTypeId().getBaseTypeId();
-            TypeDescriptor[]    types = tableFunctionReturnType.getTypes();
-            int                 returnedTableColumnCount = types.length;
+            TypeDescriptor[]    types = info.getReturnType().getRowTypes();
+
             SchemaDescriptor    sd = getSchemaDescriptor();
 
-            for ( int i = 0; i < returnedTableColumnCount; i++ )
+            for ( int i = 0; i < types.length; i++ )
             {
                 TypeDescriptorImpl  tdi = (TypeDescriptorImpl) types[ i ];
                 if ( tdi.isStringType() )

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java?rev=617238&r1=617237&r2=617238&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java Thu Jan
31 13:06:03 2008
@@ -62,7 +62,6 @@
 import org.apache.derby.catalog.TypeDescriptor;
 import org.apache.derby.catalog.UUID;
 import org.apache.derby.catalog.types.RoutineAliasInfo;
-import org.apache.derby.catalog.types.RowMultiSetImpl;
 
 import org.apache.derby.vti.DeferModification;
 import org.apache.derby.vti.VTICosting;
@@ -1595,13 +1594,9 @@
         (TypeDescriptor td)
         throws StandardException
     {
-        DataTypeDescriptor      returnType = (DataTypeDescriptor) td;
-        RowMultiSetImpl         rmsi = (RowMultiSetImpl) returnType.getTypeId().getBaseTypeId();
-        String[]                        columnNames = rmsi.getColumnNames();
-        TypeDescriptor[]    types = rmsi.getTypes();
-        int                                     count = columnNames.length;
-        
-        for ( int i = 0; i < count; i++ )
+        String[] columnNames = td.getRowColumnNames();
+        TypeDescriptor[] types = td.getRowTypes();
+        for ( int i = 0; i < columnNames.length; i++ )
         {
             resultColumns.addColumn( exposedName, columnNames[ i ],
                     DataTypeDescriptor.getType(types[i]));

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=617238&r1=617237&r2=617238&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Thu Jan
31 13:06:03 2008
@@ -10135,14 +10135,14 @@
 functionDefinition() throws StandardException :
 {
 	TableName functionName;
-	DataTypeDescriptor  returnType;
+	TypeDescriptor  returnType;
 	Object[] functionElements = new Object[9];
 }
 {
 		<FUNCTION> functionName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH)
 		functionElements[0] = functionParameterList()
 		<RETURNS> returnType = functionReturnDataType() 
-		( routineElement(false, returnType.getTypeId().isRowMultiSetTypeId(), functionElements)
) +
+		( routineElement(false, returnType.isRowMultiSet(), functionElements) ) +
 		{
 		    functionElements[8] = returnType;
 		    checkRequiredRoutineClause(JAVA_ROUTINE_CLAUSES, functionElements);
@@ -10200,10 +10200,10 @@
 /*
  * <A NAME="functionReturnDataType">functionReturnDataType</A>
  */
-DataTypeDescriptor
+TypeDescriptor
 functionReturnDataType() throws StandardException :
 {
-    DataTypeDescriptor	typeDescriptor;
+    TypeDescriptor	typeDescriptor;
 }
 {
     (
@@ -10219,10 +10219,9 @@
 /*
  * <A NAME="functionTableType">functionTableType</A>
  */
-DataTypeDescriptor
+TypeDescriptor
 functionTableType() throws StandardException :
 {
-	DataTypeDescriptor      typeDescriptor;
 	ArrayList                       names = new ArrayList();
 	ArrayList                         types = new ArrayList();
 	String[]                          nameArray;
@@ -10255,9 +10254,7 @@
 		    { throw StandardException.newException( SQLState.LANG_XML_NOT_ALLOWED_DJRS ); }
 		}
 
-		typeDescriptor = DataTypeDescriptor.getRowMultiSet( nameArray, typeArray );
-
-		return typeDescriptor;
+		return DataTypeDescriptor.getRowMultiSet( nameArray, typeArray );
 	}
 }
 



Mime
View raw message