db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r882569 - in /db/derby/code/trunk/java: engine/org/apache/derby/catalog/ engine/org/apache/derby/catalog/types/ engine/org/apache/derby/iapi/services/io/ engine/org/apache/derby/iapi/sql/dictionary/ engine/org/apache/derby/impl/sql/catalog/...
Date Fri, 20 Nov 2009 14:25:05 GMT
Author: rhillegas
Date: Fri Nov 20 14:24:57 2009
New Revision: 882569

URL: http://svn.apache.org/viewvc?rev=882569&view=rev
Log:
DERBY-651: Add CREATE/DROP TYPE. This initial increment does not allow you to create table
columns or parameters whose types are used-defined.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/UDTAliasInfo.java   (with
props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasInfo.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.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/DropAliasNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_6.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasInfo.java?rev=882569&r1=882568&r2=882569&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasInfo.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasInfo.java Fri Nov 20 14:24:57
2009
@@ -39,10 +39,12 @@
 	/**
 	 * Public statics for the various alias types as both char and String.
 	 */
+	public static final char ALIAS_TYPE_UDT_AS_CHAR		= 'A';
 	public static final char ALIAS_TYPE_PROCEDURE_AS_CHAR		= 'P';
 	public static final char ALIAS_TYPE_FUNCTION_AS_CHAR		= 'F';
 	public static final char ALIAS_TYPE_SYNONYM_AS_CHAR             = 'S';	
 
+	public static final String ALIAS_TYPE_UDT_AS_STRING		= "A";
 	public static final String ALIAS_TYPE_PROCEDURE_AS_STRING		= "P";
 	public static final String ALIAS_TYPE_FUNCTION_AS_STRING		= "F";
 	public static final String ALIAS_TYPE_SYNONYM_AS_STRING  		= "S";
@@ -50,10 +52,12 @@
 	/**
 	 * Public statics for the various alias name spaces as both char and String.
 	 */
+	public static final char ALIAS_NAME_SPACE_UDT_AS_CHAR	= 'A';
 	public static final char ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR	= 'P';
 	public static final char ALIAS_NAME_SPACE_FUNCTION_AS_CHAR	= 'F';
 	public static final char ALIAS_NAME_SPACE_SYNONYM_AS_CHAR       = 'S';
 
+	public static final String ALIAS_NAME_SPACE_UDT_AS_STRING	= "A";
 	public static final String ALIAS_NAME_SPACE_PROCEDURE_AS_STRING	= "P";
 	public static final String ALIAS_NAME_SPACE_FUNCTION_AS_STRING	= "F";
 	public static final String ALIAS_NAME_SPACE_SYNONYM_AS_STRING   = "S";

Added: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/UDTAliasInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/UDTAliasInfo.java?rev=882569&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/UDTAliasInfo.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/UDTAliasInfo.java Fri Nov
20 14:24:57 2009
@@ -0,0 +1,122 @@
+/*
+
+   Derby - Class org.apache.derby.catalog.types.UDTAliasInfo
+
+   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.catalog.types;
+
+import org.apache.derby.iapi.services.io.Formatable;
+import org.apache.derby.iapi.services.io.StoredFormatIds;
+import org.apache.derby.catalog.AliasInfo;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+/**
+ * Describe an A (Abstract Data Type) alias. For the first release of USer
+ * Defined Types, this is a vacuous object. Future revs may add real information
+ * to this object. The UDTAliasInfo maintains a version stamp so that it
+ * can evolve its persistent form over time.
+ *
+ * @see AliasInfo
+ */
+public class UDTAliasInfo implements AliasInfo, Formatable
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private static final int FIRST_VERSION = 0;
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    // no-arg constructor for Formatable machinery
+	public UDTAliasInfo() {}
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // AliasInfo BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+	public boolean isTableFunction() {return false; }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // Formatable BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+	/**
+	 * Read this object from a stream of stored objects.
+	 *
+	 * @param in read this.
+	 *
+	 * @exception IOException					thrown on error
+	 * @exception ClassNotFoundException		thrown on error
+	 */
+	public void readExternal( ObjectInput in )
+		 throws IOException, ClassNotFoundException
+	{
+        // as the persistent form evolves, switch on this value
+        int oldVersion = in.readInt();
+	}
+
+	/**
+	 * Write this object to a stream of stored objects.
+	 *
+	 * @param out write bytes here.
+	 *
+	 * @exception IOException		thrown on error
+	 */
+	public void writeExternal( ObjectOutput out )
+		 throws IOException
+	{
+		out.writeInt( FIRST_VERSION );
+	}
+ 
+	/**
+	 * Get the formatID which corresponds to this class.
+	 *
+	 *	@return	the formatID of this class
+	 */
+	public	int	getTypeFormatId()	{ return StoredFormatIds.UDT_INFO_V01_ID; }
+
+	public String toString() {
+		return "";
+	}
+
+	public String getMethodName()
+	{
+		return null;
+	}
+}
+

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/UDTAliasInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java?rev=882569&r1=882568&r2=882569&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
Fri Nov 20 14:24:57 2009
@@ -533,5 +533,8 @@
         /* 469 */   "org.apache.derby.catalog.types.RowMultiSetImpl",
         /* 470 */   "org.apache.derby.impl.store.access.btree.index.B2I",
         /* 471 */   "org.apache.derby.impl.sql.catalog.CoreDDFinderClassInfo",
+        /* 472 */       "org.apache.derby.impl.sql.catalog.CoreDDFinderClassInfo",
+        /* 473 */       "org.apache.derby.impl.sql.catalog.CoreDDFinderClassInfo",
+        /* 474 */       "org.apache.derby.catalog.types.UDTAliasInfo",
 };
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java?rev=882569&r1=882568&r2=882569&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
Fri Nov 20 14:24:57 2009
@@ -1457,6 +1457,7 @@
 
     public static final int ROUTINE_INFO_V01_ID = (MIN_ID_2 + 451);
     public static final int SYNONYM_INFO_V01_ID = (MIN_ID_2 + 455);
+    public static final int UDT_INFO_V01_ID = (MIN_ID_2 + 474);
 
     /******************************************************************
     **
@@ -1909,7 +1910,7 @@
      * Make sure this is updated when a new module is added
      */
     public static final int MAX_ID_2 =
-            (MIN_ID_2 + 473);
+            (MIN_ID_2 + 474);
 
     // DO NOT USE 4 BYTE IDS ANYMORE
     static public final int MAX_ID_4 =

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java?rev=882569&r1=882568&r2=882569&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java
Fri Nov 20 14:24:57 2009
@@ -304,6 +304,8 @@
 				return "FUNCTION";
 			case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
 				return "SYNONYM";
+			case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR:
+				return "TYPE";
 		}
 		return  null;
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java?rev=882569&r1=882568&r2=882569&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java
Fri Nov 20 14:24:57 2009
@@ -171,6 +171,7 @@
 					case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
 					case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
 					case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
+					case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR:
 						break;
 
 					default:
@@ -300,6 +301,7 @@
 				case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: 
 				case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR: 
 				case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 
+				case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR: 
 					break;
 
 				default: 
@@ -322,6 +324,7 @@
 				case AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR: 
 				case AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR: 
 				case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 
+				case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR: 
 					break;
 
 				default: 

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=882569&r1=882568&r2=882569&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
Fri Nov 20 14:24:57 2009
@@ -42,6 +42,7 @@
 import org.apache.derby.catalog.types.RoutineAliasInfo;
 import org.apache.derby.catalog.types.SynonymAliasInfo;
 import org.apache.derby.catalog.types.TypeDescriptorImpl;
+import org.apache.derby.catalog.types.UDTAliasInfo;
 
 import java.util.Vector;
 
@@ -102,6 +103,13 @@
 
 		switch (this.aliasType)
 		{
+			case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR:
+				this.javaClassName = (String) targetObject;
+				aliasInfo = new UDTAliasInfo();
+
+				implicitCreateSchema = true;
+                break;
+                
 			case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
 			case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
 			{
@@ -228,6 +236,8 @@
 	{
 		switch (this.aliasType)
 		{
+		case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR:
+			return "CREATE TYPE";
 		case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
 			return "CREATE PROCEDURE";
 		case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
@@ -310,6 +320,13 @@
 		if (aliasType != AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)
 			return;
 
+        // validity checking for UDTs
+        if ( aliasType == AliasInfo.ALIAS_TYPE_UDT_AS_CHAR )
+        {
+            // nothing to do yet
+            return;
+        }
+
 		// Don't allow creating synonyms in SESSION schema. Causes confusion if
 		// a temporary table is created later with same name.
 		if (isSessionSchema(getSchemaDescriptor().getSchemaName()))
@@ -335,18 +352,7 @@
 	 */
 	public ConstantAction	makeConstantAction() throws StandardException
 	{
-		String schemaName;
-		switch (aliasType) {
-		case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
-		case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
-			schemaName = getSchemaDescriptor().getSchemaName();
-			break;
-		case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
-			schemaName = getSchemaDescriptor().getSchemaName();
-			break;
-		default:
-			schemaName = null;
-		}
+		String schemaName = getSchemaDescriptor().getSchemaName();
 
 		return	getGenericConstantActionFactory().getCreateAliasConstantAction(
 											  getRelativeName(),

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropAliasNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropAliasNode.java?rev=882569&r1=882568&r2=882569&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropAliasNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropAliasNode.java Fri
Nov 20 14:24:57 2009
@@ -79,6 +79,10 @@
 				nameSpace = AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR;
 				break;
 
+			case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR:
+				nameSpace = AliasInfo.ALIAS_NAME_SPACE_UDT_AS_CHAR;
+				break;
+
 			default:
 				if (SanityManager.DEBUG)
 				{
@@ -156,6 +160,9 @@
 			case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
 				typeName = "SYNONYM";
 				break;
+			case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR:
+				typeName = "TYPE";
+				break;
 		}
 		return typeName;
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java?rev=882569&r1=882568&r2=882569&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
Fri Nov 20 14:24:57 2009
@@ -685,7 +685,10 @@
 
 		nodeType = C_NodeTypes.CREATE_ALIAS_NODE;
 
-		if (aliasType != AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)
+		if (
+            (aliasType != AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR) &&
+            (aliasType != AliasInfo.ALIAS_TYPE_UDT_AS_CHAR)
+            )
 		{
         	int lastPeriod;
         	String fullStaticMethodName = (String) targetName;

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=882569&r1=882568&r2=882569&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 Fri Nov
20 14:24:57 2009
@@ -2873,6 +2873,7 @@
         }
 |		statementNode = procedureDefinition()
 |		statementNode = functionDefinition()
+|		statementNode = udtDefinition()
 |
 		statementNode = indexDefinition()
         {
@@ -10548,6 +10549,31 @@
 	}
 }
 
+/**
+	CREATE TYPE
+*/
+
+StatementNode
+udtDefinition() throws StandardException :
+{
+	TableName udtName;
+	String externalName;
+}
+{
+		<TYPE> udtName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH)
+		<EXTERNAL> <NAME> externalName = string()
+		<LANGUAGE>  <JAVA>
+		{
+			checkVersion(DataDictionary.DD_VERSION_DERBY_10_6, "CREATE TYPE");
+			return getCreateAliasNode(
+							udtName,
+							externalName,
+							null,
+							AliasInfo.ALIAS_TYPE_UDT_AS_CHAR,
+							Boolean.FALSE);
+		}
+}
+
 StatementNode
 viewDefinition(Token beginToken) throws StandardException :
 {
@@ -13101,6 +13127,12 @@
 
 		return dropAliasNode(aliasName, AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR);
 	}
+|	<TYPE> aliasName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH) <RESTRICT>
+	{
+		checkVersion(DataDictionary.DD_VERSION_DERBY_10_6, "DROP TYPE");
+
+		return dropAliasNode(aliasName, AliasInfo.ALIAS_TYPE_UDT_AS_CHAR);
+	}
 }
 
 StatementNode

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java?rev=882569&r1=882568&r2=882569&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java
Fri Nov 20 14:24:57 2009
@@ -92,6 +92,10 @@
 				nameSpace = AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR;
 				break;
 
+			case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR:
+				nameSpace = AliasInfo.ALIAS_NAME_SPACE_UDT_AS_CHAR;
+				break;
+
 			default:
 				if (SanityManager.DEBUG)
 				{
@@ -125,6 +129,10 @@
 				type = "CREATE SYNONYM ";
 				break;
 
+			case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR:
+				type = "CREATE TYPE ";
+				break;
+
 			default:
 				if (SanityManager.DEBUG)
 				{
@@ -141,9 +149,9 @@
 
 	/**
 	 *	This is the guts of the Execution-time logic for
-     *  CREATE FUNCTION, PROCEDURE or SYNONYM.
+     *  CREATE FUNCTION, PROCEDURE, SYNONYM, and TYPE.
      *  <P>
-     *  A routine (function or procedure) is represented as:
+     *  A function, procedure, or udt is represented as:
      *  <UL>
      *  <LI> AliasDescriptor
      *  </UL>
@@ -202,7 +210,7 @@
             DDLConstantAction.getSchemaDescriptorForCreate(dd, activation, schemaName);
 
 		//
-		// Create a new method alias descriptor with aliasID filled in.
+		// Create a new alias descriptor with aliasID filled in.
 		// 
 		UUID aliasID = dd.getUUIDFactory().createUUID();
 
@@ -217,6 +225,12 @@
 
 		// perform duplicate rule checking
 		switch (aliasType) {
+		case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR:
+
+            AliasDescriptor duplicateUDT = dd.getAliasDescriptor( sd.getUUID().toString(),
aliasName, nameSpace );
+            if ( duplicateUDT != null ) { throw StandardException.newException( SQLState.LANG_OBJECT_ALREADY_EXISTS,
ads.getDescriptorType(), aliasName ); }
+            break;
+            
 		case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
 		case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
 		{

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java?rev=882569&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
Fri Nov 20 14:24:57 2009
@@ -0,0 +1,150 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.UDTTest
+
+   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.derbyTesting.functionTests.tests.lang;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+
+/**
+ * <p>
+ * Test user defined types. See DERBY-651.
+ * </p>
+ */
+public class UDTTest  extends GeneratedColumnsHelper
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public static final String OBJECT_EXISTS = "X0Y68";
+    public static final String NONEXISTENT_OBJECT = "42Y55";
+    public static final String SYNTAX_ERROR = "42X01";
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+
+    /**
+     * Create a new instance.
+     */
+
+    public UDTTest(String name)
+    {
+        super(name);
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // JUnit BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+
+    /**
+     * Construct top level suite in this JUnit test
+     */
+    public static Test suite()
+    {
+        TestSuite suite = (TestSuite) TestConfiguration.embeddedSuite(UDTTest.class);
+        Test        result = new CleanDatabaseTestSetup( suite );
+
+        return result;
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // TESTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Basic syntax.
+     * </p>
+     */
+    public void test_01_basicSyntax() throws Exception
+    {
+        Connection conn = getConnection();
+
+        goodStatement( conn, "create schema adt_schema\n" );
+
+        // create some types
+        makeGoodTypes( conn );
+
+        // duplicate type names should raise errors
+        expectExecutionError( conn, OBJECT_EXISTS, "create type fooType external name 'mypackage.foo'
language java\n" );
+        expectExecutionError( conn, OBJECT_EXISTS, "create type adt_schema.fooType external
name 'mypackage.foo' language java\n" );
+        expectExecutionError( conn, OBJECT_EXISTS, "create type \"smallint\" external name
'mypackage.foo' language java\n" );
+        expectExecutionError( conn, OBJECT_EXISTS, "create type \"SMALLINT\" external name
'mypackage.foo' language java\n" );
+
+        // only RESTRICTed drops allowed now
+        expectCompilationError( SYNTAX_ERROR, "drop type fooType\n" );
+
+        // drop some types
+        goodStatement( conn, "drop type fooType restrict\n" );
+        goodStatement( conn, "drop type adt_schema.fooType restrict\n" );
+        goodStatement( conn, "drop type \"smallint\" restrict\n" );
+        goodStatement( conn, "drop type \"SMALLINT\" restrict\n" );
+
+        // can't drop a non-existent type
+        expectCompilationError( NONEXISTENT_OBJECT, "drop type fooType restrict\n" );
+        expectCompilationError( NONEXISTENT_OBJECT, "drop type adt_schema.fooType restrict\n"
);
+        expectCompilationError( NONEXISTENT_OBJECT, "drop type \"smallint\" restrict\n" );
+        expectCompilationError( NONEXISTENT_OBJECT, "drop type \"SMALLINT\" restrict\n" );
+
+        // re-create the types
+        makeGoodTypes( conn );
+    }
+    private void makeGoodTypes( Connection conn ) throws Exception
+    {
+        goodStatement( conn, "create type fooType external name 'mypackage.foo' language
java\n" );
+        goodStatement( conn, "create type adt_schema.fooType external name 'mypackage.foo'
language java\n" );
+        goodStatement( conn, "create type \"smallint\" external name 'mypackage.foo' language
java\n" );
+        goodStatement( conn, "create type \"SMALLINT\" external name 'mypackage.foo' language
java\n" );
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // MINIONS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=882569&r1=882568&r2=882569&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Fri Nov 20 14:24:57 2009
@@ -200,6 +200,7 @@
         suite.addTest(GeneratedColumnsTest.suite());
         suite.addTest(GeneratedColumnsPermsTest.suite());
         suite.addTest(RestrictedVTITest.suite());
+        suite.addTest(UDTTest.suite());
         suite.addTest(AlterColumnTest.suite());
         suite.addTest(UserLobTest.suite());
         suite.addTest(OffsetFetchNextTest.suite());

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_6.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_6.java?rev=882569&r1=882568&r2=882569&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_6.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_6.java
Fri Nov 20 14:24:57 2009
@@ -57,6 +57,7 @@
 
     private static  final   String  BAD_SYNTAX = "42X01";
     private static  final   String  TABLE_DOES_NOT_EXIST = "42X05";
+    private static  final   String  UPGRADE_REQUIRED = "XCL47";
 
     private static  final   String  QUERY_4215 =
         "select r.grantor\n" +
@@ -64,6 +65,9 @@
         "where r.aliasid = a.aliasid\n" +
         "and a.alias = 'SYSCS_INPLACE_COMPRESS_TABLE'\n"
         ;
+
+    private static final   String CREATE_TYPE_DDL = "create type fooType external name 'mypackage.foo'
language java\n";
+    private static final   String DROP_TYPE_DDL = "drop type fooType restrict\n";
     
     public Changes10_6(String name) {
         super(name);
@@ -225,7 +229,6 @@
 
         s.close();
     }
-
     /**
      * Vet the permissions on SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE.
      * There should be only one permissions tuple for this system procedure and
@@ -246,6 +249,46 @@
         rs.close();
     }
 
+    /**
+     * Make sure that you can only create UDTs in a hard-upgraded database.
+     * See https://issues.apache.org/jira/browse/DERBY-651
+     */
+    public void testUDTs() throws Exception
+    {        
+    	Statement s = createStatement();
+
+        int phase = getPhase();
+
+        //println( "Phase = " + phase );
+        
+        switch ( phase )
+        {
+        case PH_CREATE:
+        case PH_POST_SOFT_UPGRADE:
+            
+            assertStatementError( BAD_SYNTAX, s, CREATE_TYPE_DDL );
+            assertStatementError( BAD_SYNTAX, s, DROP_TYPE_DDL );
+            
+            break;
+
+        case PH_SOFT_UPGRADE:
+
+            assertStatementError( UPGRADE_REQUIRED, s, CREATE_TYPE_DDL );
+            assertStatementError( UPGRADE_REQUIRED, s, DROP_TYPE_DDL );
+            
+            break;
+
+        case PH_HARD_UPGRADE:
+
+            s.execute( CREATE_TYPE_DDL );
+            s.execute( DROP_TYPE_DDL );
+            
+            break;
+        }
+
+        s.close();
+    }
+
     
     /**
      * We would like to just cast the alias descriptor to



Mime
View raw message