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 ba...@apache.org on 2005/06/06 21:19:36 UTC

svn commit: r180459 [1/2] - in /incubator/derby/code/trunk/java: engine/org/apache/derby/catalog/ engine/org/apache/derby/catalog/types/ engine/org/apache/derby/iapi/reference/ engine/org/apache/derby/iapi/services/io/ engine/org/apache/derby/iapi/sql/compile/ engine/org/apache/derby/iapi/sql/dictionary/ engine/org/apache/derby/impl/sql/catalog/ engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/impl/sql/execute/ engine/org/apache/derby/loc/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNet/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/org/apache/derbyTesting/functionTests/tests/tools/ tools/org/apache/derby/impl/tools/dblook/ tools/org/apache/derby/loc/ tools/org/apache/derby/tools/

Author: bandaram
Date: Mon Jun  6 12:19:34 2005
New Revision: 180459

URL: http://svn.apache.org/viewcvs?rev=180459&view=rev
Log:
Derby-335: Add synonym support to Derby. See the following for more description of the functionality.

Submitted by Satheesh Bandaram (satheesh@sourcery.org)

Couple of changes still pending to complete this feature:

    1) Add registering and checking for Dependencies. These ensure all required objects have been droped before droping synonyms and dropping of synonyms invalidate all required objects.
    2) Add more tests and possible minor code cleanups.

Synonym Functionality:
----------------------
Synonym provides an alternate name for a table or a view that is present in the
same schema or another schema. A synonym can also be created for another
synonym, causing nesting of synonyms. A synonym can be used in SELECT, INSERT,
UPDATE, DELETE or LOCK TABLE statements instead of the original qualified table
or view name. Note that a synonym can be created for a table or a view that
doesn't yet exists. But the target table/view must be present before the
synonym can be used. 

Synonyms are supported by all major database vendors, including Oracle, DB2 and
mySQL. DB2 also allows CREATE ALIAS statement, which does exactly same as
CREATE SYNONYM. Creating aliases instead of synonyms is not supported by Oracle
or mySQL, so I propose that Derby not support creating aliases. Synonyms are not
part of SQL-2003 spec, but is a common-SQL statement among major database
vendors. SQL standard doesn't pay attention to DDLs as much, so I suspect they
skipped synonyms. 

I will be adding two new DDL statements to Derby: 

CREATE SYNONYM <SynonymSchema>.<SynonymName> FOR <TargetSchema>.<TargetName> 
DROP SYNONYM <SynonymSchema>.<SynonymName> 

Synonyms share the same namespace as tables or views. It is not possible to
create a synonym with same name as a table that already exists in the same
schema. Similarly, a table/view can't be created that matches a synonym already
present. 



Added:
    incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/types/SynonymAliasInfo.java   (with props)
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/synonym.out   (with props)
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/synonym.out   (with props)
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/synonym.out   (with props)
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/synonym.sql   (with props)
Modified:
    incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasInfo.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/NodeFactory.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSTABLESRowFactory.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropAliasNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropAliasConstantAction.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_makeDB.sql
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_test.java
    incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dblook/DB_StoredProcedure.java
    incubator/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties
    incubator/derby/code/trunk/java/tools/org/apache/derby/tools/dblook.java

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasInfo.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasInfo.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasInfo.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasInfo.java Mon Jun  6 12:19:34 2005
@@ -28,6 +28,7 @@
  * <ul>
  * <li>method alias
  * <li>class alias
+ * <li>synonym
  * <li>user-defined aggregate
  * </ul>
  *
@@ -39,18 +40,22 @@
 	 */
 	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_PROCEDURE_AS_STRING		= "P";
 	public static final String ALIAS_TYPE_FUNCTION_AS_STRING		= "F";
+	public static final String ALIAS_TYPE_SYNONYM_AS_STRING  		= "S";
 
 	/**
 	 * Public statics for the various alias name spaces as both char and String.
 	 */
 	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_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";
 
 	/**
 	 * Get the name of the static method that the alias 

Added: incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/types/SynonymAliasInfo.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/types/SynonymAliasInfo.java?rev=180459&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/types/SynonymAliasInfo.java (added)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/types/SynonymAliasInfo.java Mon Jun  6 12:19:34 2005
@@ -0,0 +1,107 @@
+/*
+
+   Derby - Class org.apache.derby.catalog.types.SynonymAliasInfo
+
+   Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+
+   Licensed 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 S (Synonym) alias.
+ *
+ * @see AliasInfo
+ */
+public class SynonymAliasInfo implements AliasInfo, Formatable
+{
+	private String schemaName = null;
+	private String tableName = null;
+
+	public SynonymAliasInfo() {
+	}
+
+	/**
+		Create a SynonymAliasInfo for synonym.
+	*/
+	public SynonymAliasInfo(String schemaName, String tableName)
+	{
+		this.schemaName = schemaName;
+		this.tableName = tableName;
+	}
+
+	public String getSynonymTable() {
+		return tableName;
+	}
+
+	public String getSynonymSchema() {
+		return schemaName;
+	}
+
+	// Formatable methods
+
+	/**
+	 * 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
+	{
+		schemaName = (String) in.readObject();
+		tableName = (String) in.readObject();
+	}
+
+	/**
+	 * 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.writeObject(schemaName);
+		out.writeObject(tableName);
+	}
+ 
+	/**
+	 * Get the formatID which corresponds to this class.
+	 *
+	 *	@return	the formatID of this class
+	 */
+	public	int	getTypeFormatId()	{ return StoredFormatIds.SYNONYM_INFO_V01_ID; }
+
+	public String toString() {
+		return "\"" + schemaName + "\".\"" + tableName + "\"";
+	}
+
+	public String getMethodName()
+	{
+		return null;
+	}
+}
+

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

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java Mon Jun  6 12:19:34 2005
@@ -630,6 +630,7 @@
 	String LANG_COL_NOT_NULL									   	   = "01503";
 	String LANG_INDEX_DUPLICATE									   	   = "01504";
 	String LANG_VALUE_TRUNCATED                                        = "01505";
+	String LANG_SYNONYM_UNDEFINED                                      = "01522";
 	String LANG_NULL_ELIMINATED_IN_SET_FUNCTION						   = "01003";
 
 	String LANG_NO_ROW_FOUND									   	   = "02000";
@@ -707,6 +708,7 @@
 	String LANG_NO_AGGREGATES_IN_WHERE_CLAUSE                          = "42903";
 	String LANG_DB2_VIEW_REQUIRES_COLUMN_NAMES                         = "42908";
 	String LANG_DELETE_RULE_VIOLATION		   					       = "42915";
+	String LANG_SYNONYM_CIRCULAR   		   					           = "42916";
 	String LANG_DB2_ON_CLAUSE_INVALID		   					       = "42972";
 	String LANG_SYNTAX_ERROR                                           = "42X01";
 	String LANG_LEXICAL_ERROR                                          = "42X02";

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java Mon Jun  6 12:19:34 2005
@@ -515,6 +515,7 @@
         /* 451 */   "org.apache.derby.catalog.types.RoutineAliasInfo",
 		/* 452 */   null,
 		/* 453 */   "org.apache.derby.impl.store.raw.log.ChecksumOperation",
-		/* 454 */   "org.apache.derby.impl.store.raw.data.CompressSpacePageOperation"
+		/* 454 */   "org.apache.derby.impl.store.raw.data.CompressSpacePageOperation",
+		/* 455 */   "org.apache.derby.catalog.types.SynonymAliasInfo"
 };
 }

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java Mon Jun  6 12:19:34 2005
@@ -1384,6 +1384,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);
 
 	/******************************************************************
 	**
@@ -1810,7 +1811,7 @@
          * Make sure this is updated when a new module is added
          */
         public static final int MAX_ID_2 =
-                (MIN_ID_2 + 454);
+                (MIN_ID_2 + 455);
 
         // DO NOT USE 4 BYTE IDS ANYMORE
         static public final int MAX_ID_4 =

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/NodeFactory.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/NodeFactory.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/NodeFactory.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/NodeFactory.java Mon Jun  6 12:19:34 2005
@@ -590,7 +590,7 @@
 	public abstract QueryTreeNode
 	getCreateAliasNode(
 		Object aliasName,
-		String fullStaticMethodName,
+		Object targetName,
 		Object aliasSpecificInfo,
 		char aliasType,
 		Boolean delimitedIdentifier,

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/AliasDescriptor.java Mon Jun  6 12:19:34 2005
@@ -288,17 +288,23 @@
 	/** @see TupleDescriptor#getDescriptorType */
 	public String getDescriptorType()
 	{
-		switch (aliasType)
+		return getAliasType(aliasType);
+	}
+	
+	public static final String getAliasType(char nameSpace)
+	{
+		switch (nameSpace)
 		{
 			case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
 				return "PROCEDURE";
 			case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
 				return "FUNCTION";
-			default:
-				return  null;
+			case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
+				return "SYNONYM";
 		}
+		return  null;
 	}
-	
+
 	/** @see TupleDescriptor#getDescriptorName */
 	public String getDescriptorName()
 	{

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java Mon Jun  6 12:19:34 2005
@@ -101,6 +101,7 @@
 	public static final int SYSTEM_TABLE_TYPE = 1;
 	public static final int VIEW_TYPE = 2;
 	public static final int GLOBAL_TEMPORARY_TABLE_TYPE = 3;
+	public static final int SYNONYM_TYPE = 4;
 
 	public static final char	ROW_LOCK_GRANULARITY = 'R';
 	public static final char	TABLE_LOCK_GRANULARITY = 'T';
@@ -559,6 +560,18 @@
 	}
 
 	/**
+	 * Is this descriptor represents a synonym?
+	 *
+	 * @return boolean              Whether or not this represents a synonym
+	 */
+	public boolean isSynonymDescriptor()
+	{
+		if (tableType == TableDescriptor.SYNONYM_TYPE)
+			return true;
+		return false;
+	}
+
+	/**
 	 * Gets the number of indexes on the table, including the backing indexes.
 	 *
 	 * @return the number of columns in the table.
@@ -1265,5 +1278,8 @@
 	public String getDescriptorName() { return tableName; }
 
 	/** @see TupleDescriptor#getDescriptorType */
-	public String getDescriptorType() { return "Table/View"; }
+	public String getDescriptorType() 
+	{
+		return (tableType == TableDescriptor.SYNONYM_TYPE) ? "Synonym" : "Table/View";
+	}
 }

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java Mon Jun  6 12:19:34 2005
@@ -191,6 +191,7 @@
 				{
 					case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
 					case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
+					case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
 						break;
 
 					default:
@@ -370,6 +371,7 @@
 			{
 				case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: 
 				case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR: 
+				case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 
 					break;
 
 				default: 
@@ -391,6 +393,7 @@
 			{
 				case AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR: 
 				case AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR: 
+				case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 
 					break;
 
 				default: 

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSTABLESRowFactory.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSTABLESRowFactory.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSTABLESRowFactory.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSTABLESRowFactory.java Mon Jun  6 12:19:34 2005
@@ -172,7 +172,7 @@
 			tableName = descriptor.getName();
 
 			/* RESOLVE - Table Type should really be a char in the descriptor
-			 * T, S, V instead of 0, 1, 2
+			 * T, S, V, S instead of 0, 1, 2, 3
 			 */
 			tabIType = descriptor.getTableType();
 			switch (tabIType)
@@ -187,6 +187,10 @@
 					tabSType = "V";
 					break;		
 
+			    case TableDescriptor.SYNONYM_TYPE:
+					tabSType = "A";
+					break;		
+
 			    default:
 					if (SanityManager.DEBUG)
 						SanityManager.THROWASSERT("invalid table type");
@@ -328,6 +332,9 @@
 				break;
 			case 'V' :
 				tableTypeEnum = TableDescriptor.VIEW_TYPE;
+				break;
+			case 'A' :
+				tableTypeEnum = TableDescriptor.SYNONYM_TYPE;
 				break;
 			default:
 				if (SanityManager.DEBUG)

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java Mon Jun  6 12:19:34 2005
@@ -36,6 +36,8 @@
 import org.apache.derby.iapi.types.TypeId;
 
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
 
 import org.apache.derby.iapi.error.StandardException;
 
@@ -48,6 +50,7 @@
 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.SynonymAliasInfo;
 
 import java.lang.reflect.Member;
 import java.util.Vector;
@@ -72,7 +75,7 @@
 	 * Initializer for a CreateAliasNode
 	 *
 	 * @param aliasName				The name of the alias
-	 * @param javaClassName			The full class name
+	 * @param targetObject			Target name
 	 * @param methodName		    The method name
 	 * @param aliasType				The alias type
 	 * @param delimitedIdentifier	Whether or not to treat the class name
@@ -83,7 +86,7 @@
 	 */
 	public void init(
 						Object aliasName,
-						Object javaClassName,
+						Object targetObject,
 						Object methodName,
 						Object aliasSpecificInfo,
 						Object aliasType,
@@ -91,21 +94,20 @@
 		throws StandardException
 	{		
 		TableName qn = (TableName) aliasName;
-
-		initAndCheck(qn);
-			
-		this.javaClassName = (String) javaClassName;
-		this.methodName = (String) methodName;
 		this.aliasType = ((Character) aliasType).charValue();
-		this.delimitedIdentifier =
-								((Boolean) delimitedIdentifier).booleanValue();
 
+		initAndCheck(qn);
 
 		switch (this.aliasType)
 		{
 			case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
 			case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
 			{
+				this.javaClassName = (String) targetObject;
+				this.methodName = (String) methodName;
+				this.delimitedIdentifier =
+								((Boolean) delimitedIdentifier).booleanValue();
+
 				//routineElements contains the description of the procedure.
 				// 
 				// 0 - Object[] 3 element array for parameters
@@ -197,6 +199,14 @@
 				}
 				break;
 
+			case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
+				String targetSchema;
+				TableName t = (TableName) targetObject;
+				if (t.getSchemaName() != null)
+					targetSchema = t.getSchemaName();
+				else targetSchema = getSchemaDescriptor().getSchemaName();
+				aliasInfo = new SynonymAliasInfo(targetSchema, t.getTableName());
+				break;
 
 			default:
 				if (SanityManager.DEBUG)
@@ -213,6 +223,8 @@
 		{
 		case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
 			return "CREATE PROCEDURE";
+		case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
+			return "CREATE SYNONYM";
 		default:
 			return "CREATE FUNCTION";
 		}
@@ -233,7 +245,26 @@
 
 	public QueryTreeNode bind() throws StandardException
 	{
-		// Procedures do not check class or method validity until runtime execution of the procedure.
+		// Procedures and functions do not check class or method validity until
+		// runtime execution. Synonyms do need some validity checks.
+		if (aliasType != AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)
+			return this;
+
+		String targetSchema = ((SynonymAliasInfo)aliasInfo).getSynonymSchema();
+		String targetTable = ((SynonymAliasInfo)aliasInfo).getSynonymTable();
+		if (this.getObjectName().equals(targetSchema, targetTable))
+			throw StandardException.newException(SQLState.LANG_SYNONYM_CIRCULAR,
+						this.getFullName(),
+						targetSchema+"."+targetTable);
+
+		// Raise error if targetSchema doesn't exists
+		SchemaDescriptor targetSD = getSchemaDescriptor(targetSchema);
+
+		// Synonym can't be defined on temporary tables.
+		TableDescriptor targetTD = getTableDescriptor(targetTable, targetSD);
+		if (targetTD != null &&
+			targetTD.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE)
+			throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES);
 
 		return this;
 	}
@@ -249,6 +280,9 @@
 		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:

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java Mon Jun  6 12:19:34 2005
@@ -215,16 +215,23 @@
 			/*
 			** Get the TableDescriptor for the table we are inserting into
 			*/
-			String sntc = targetTableName.getSchemaName();
-
-			SchemaDescriptor sdtc = getSchemaDescriptor(sntc);
+			SchemaDescriptor sdtc = getSchemaDescriptor(targetTableName.getSchemaName());
 
 			targetTableDescriptor = getTableDescriptor(
 							targetTableName.getTableName(), sdtc);
 
 			if (targetTableDescriptor == null)
 			{
-				throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, targetTableName);
+				// Check if the reference is for a synonym.
+				TableName synonymTab = resolveTableToSynonym(targetTableName);
+				if (synonymTab == null)
+					throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, targetTableName);
+				targetTableName = synonymTab;
+				sdtc = getSchemaDescriptor(targetTableName.getSchemaName());
+
+				targetTableDescriptor = getTableDescriptor(synonymTab.getTableName(), sdtc);
+				if (targetTableDescriptor == null)
+					throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, targetTableName);
 			}
 
 			// Views are currently not updatable */

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropAliasNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropAliasNode.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropAliasNode.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropAliasNode.java Mon Jun  6 12:19:34 2005
@@ -75,6 +75,10 @@
 				nameSpace = AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR;
 				break;
 
+			case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
+				nameSpace = AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR;
+				break;
+
 			default:
 				if (SanityManager.DEBUG)
 				{
@@ -148,6 +152,9 @@
 				break;
 			case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
 				typeName = "FUNCTION";
+				break;
+			case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
+				typeName = "SYNONYM";
 				break;
 		}
 		return typeName;

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java Mon Jun  6 12:19:34 2005
@@ -2369,7 +2369,16 @@
 		}
 		else
 		{
-			throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);
+			// Check if the reference is for a synonym.
+			TableName synonymTab = resolveTableToSynonym(tableName);
+			if (synonymTab == null)
+				throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);
+			tableName = synonymTab;
+			sd = getSchemaDescriptor(tableName.getSchemaName());
+
+			tableDescriptor = getTableDescriptor(synonymTab.getTableName(), sd);
+			if (tableDescriptor == null)
+				throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);
 		}
 
 		return	tableDescriptor;

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java Mon Jun  6 12:19:34 2005
@@ -130,7 +130,16 @@
 
 		if (lockTableDescriptor == null)
 		{
-			throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);
+			// Check if the reference is for a synonym.
+			TableName synonymTab = resolveTableToSynonym(tableName);
+			if (synonymTab == null)
+				throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);
+			tableName = synonymTab;
+			sd = getSchemaDescriptor(tableName.getSchemaName());
+
+			lockTableDescriptor = getTableDescriptor(synonymTab.getTableName(), sd);
+			if (lockTableDescriptor == null)
+				throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);
 		}
 
 		//throw an exception if user is attempting to lock a temporary table

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java Mon Jun  6 12:19:34 2005
@@ -596,7 +596,7 @@
 	public	QueryTreeNode
 	getCreateAliasNode(
 		Object aliasName,
-		String fullStaticMethodName,
+		Object targetName,
 		Object aliasSpecificInfo,
 		char aliasType,
 		Boolean delimitedIdentifier,
@@ -605,37 +605,39 @@
 	{
 		int nodeType;
 		String methodName = null;
-		String javaClassName = fullStaticMethodName;
 		String targetMethodName = null;
 		String targetClassName = null;
 
 		nodeType = C_NodeTypes.CREATE_ALIAS_NODE;
 
-        int lastPeriod;
-        int paren = fullStaticMethodName.indexOf('(');
-        if (paren == -1) {
-            // not a Java signature - split based on last period
-            lastPeriod = fullStaticMethodName.lastIndexOf('.');
-        } else {
-            // a Java signature - split on last period before the '('
-            lastPeriod = fullStaticMethodName.substring(0, paren).lastIndexOf('.');
-        }
-        if (lastPeriod == -1 || lastPeriod == fullStaticMethodName.length()-1) {
-            throw StandardException.newException(SQLState.LANG_INVALID_FULL_STATIC_METHOD_NAME, fullStaticMethodName);
-        }
-        javaClassName = fullStaticMethodName.substring(0, lastPeriod);
-        methodName = fullStaticMethodName.substring(lastPeriod + 1);
+		if (aliasType != AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)
+		{
+        	int lastPeriod;
+        	String fullStaticMethodName = (String) targetName;
+        	int paren = fullStaticMethodName.indexOf('(');
+        	if (paren == -1) {
+            	// not a Java signature - split based on last period
+            	lastPeriod = fullStaticMethodName.lastIndexOf('.');
+        	} else {
+            	// a Java signature - split on last period before the '('
+            	lastPeriod = fullStaticMethodName.substring(0, paren).lastIndexOf('.');
+        	}
+        	if (lastPeriod == -1 || lastPeriod == fullStaticMethodName.length()-1) {
+            	throw StandardException.newException(SQLState.LANG_INVALID_FULL_STATIC_METHOD_NAME, fullStaticMethodName);
+        	}
+        	String javaClassName = fullStaticMethodName.substring(0, lastPeriod);
+        	methodName = fullStaticMethodName.substring(lastPeriod + 1);
+			targetName = javaClassName;
+		}
 
 		return getNode(
 			nodeType,
 			aliasName,
-			javaClassName,
+			targetName,
 			methodName,
 			aliasSpecificInfo,
 			new Character(aliasType),
 			delimitedIdentifier,
 			cm );
 	}
-
-
 }

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java Mon Jun  6 12:19:34 2005
@@ -46,6 +46,7 @@
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
+import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.sql.execute.ConstantAction;
@@ -60,6 +61,7 @@
 import org.apache.derby.iapi.sql.depend.DependencyManager;
 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
 import org.apache.derby.catalog.AliasInfo;
+import org.apache.derby.catalog.types.SynonymAliasInfo;
 import java.util.Properties;
 import java.util.Vector;
 import java.sql.Types;
@@ -1373,7 +1375,10 @@
 			return null;
 
 		//it is not a temporary table, so go through the data dictionary to find the physical persistent table
-		return getDataDictionary().getTableDescriptor(tableName, schema);
+		TableDescriptor td = getDataDictionary().getTableDescriptor(tableName, schema);
+		if (td == null || td.isSynonymDescriptor())
+			return null;
+		return td;
 	}
 
 	/**
@@ -1467,6 +1472,49 @@
 			}
 		}
 		return sdCatalog;
+	}
+
+	/**
+	 * Resolve table/view reference to a synonym. May have to follow a synonym chain.
+	 *
+	 * @param	tabName to match for a synonym
+	 *
+	 * @return	Synonym TableName if a match is found, NULL otherwise.
+	 *
+	 * @exception StandardException		Thrown on error
+	 */
+	public TableName resolveTableToSynonym(TableName tabName) throws StandardException
+	{
+		DataDictionary dd = getDataDictionary();
+		String nextSynonymTable = tabName.getTableName();
+		String nextSynonymSchema = tabName.getSchemaName();
+		boolean found = false;
+
+		// Circular synonym references should have been detected at the DDL time, so
+		// the following loop shouldn't loop forever.
+		for (;;)
+		{
+			SchemaDescriptor nextSD = getSchemaDescriptor(nextSynonymSchema, false);
+			if (nextSD == null || nextSD.getUUID() == null)
+				break;
+	
+			AliasDescriptor nextAD = dd.getAliasDescriptor(nextSD.getUUID().toString(),
+						 nextSynonymTable, AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR);
+			if (nextAD == null)
+				break;
+
+			found = true;
+			SynonymAliasInfo info = ((SynonymAliasInfo)nextAD.getAliasInfo());
+			nextSynonymTable = info.getSynonymTable();
+			nextSynonymSchema = info.getSynonymSchema();
+		}
+
+		if (!found)
+			return null;
+
+		TableName tableName = new TableName();
+		tableName.init(nextSynonymSchema, nextSynonymTable);
+		return tableName;
 	}
 
 	/**

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java Mon Jun  6 12:19:34 2005
@@ -201,6 +201,11 @@
 
 		DataDictionary dataDictionary = getDataDictionary();
 
+		// check if targetTable is a synonym
+		TableName synonymTab = resolveTableToSynonym(this.targetTableName);
+		if (synonymTab != null)
+			this.targetTableName = synonymTab;
+
 		bindTables(dataDictionary);
 
 		// wait to bind named target table until the cursor

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Mon Jun  6 12:19:34 2005
@@ -1868,6 +1868,7 @@
 |	<SQL_TSI_YEAR: "sql_tsi_year">
 |	<START: "start">
 |	<STATEMENT: "statement">
+|	<SYNONYM: "synonym">
 |	<THEN: "then">
 |	<TIME: "time">
 |	<TIMESTAMP: "timestamp">
@@ -2413,7 +2414,8 @@
 		(
             statementNode = schemaDefinition() |
             statementNode = viewDefinition(beginToken) |
-           statementNode = triggerDefinition()
+            statementNode = triggerDefinition() |
+            statementNode = synonymDefinition()
         )
         {
         }
@@ -9048,6 +9050,32 @@
 	}
 }
 
+QueryTreeNode
+synonymDefinition() throws StandardException :
+{
+	TableName synonymName;
+	TableName targetName;
+}
+{
+    <SYNONYM> synonymName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH) <FOR>
+		 targetName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH)
+	{
+		checkVersion(DataDictionary.DD_VERSION_DERBY_10_1,
+			     "CREATE SYNONYM");
+
+		return  (StatementNode) getNodeFactory().getCreateAliasNode
+			(
+				synonymName,
+				targetName,
+				null,
+				AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR,
+				Boolean.FALSE,
+				getContextManager()
+			);
+	}
+}
+
+
 Boolean
 beforeOrAfter() :
 {}
@@ -11044,6 +11072,12 @@
 	{
 		return dropAliasNode(aliasName, AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR);
 	}  
+|	<SYNONYM> aliasName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH)
+	{
+		checkVersion(DataDictionary.DD_VERSION_DERBY_10_1, "DROP SYNONYM");
+
+		return dropAliasNode(aliasName, AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR);
+	}
 }
 
 QueryTreeNode
@@ -11537,6 +11571,7 @@
     |       tok = <STABILITY>
 	|	tok = <START>
 	|	tok = <STATEMENT>
+	|	tok = <SYNONYM>
 	|	tok = <STYLE>
 	|	tok = <T>
 	|	tok = <THEN>

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateAliasConstantAction.java Mon Jun  6 12:19:34 2005
@@ -26,7 +26,9 @@
 
 import org.apache.derby.iapi.sql.execute.ConstantAction;
 
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
+import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
@@ -48,6 +50,7 @@
 
 import org.apache.derby.catalog.AliasInfo;
 import org.apache.derby.catalog.types.RoutineAliasInfo;
+import org.apache.derby.catalog.types.SynonymAliasInfo;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -76,9 +79,7 @@
 	 *  @param aliasName		Name of alias.
 	 *  @param schemaName		Name of alias's schema.
 	 *  @param javaClassName	Name of java class.
-	 *  @param methodName		Name of method.
-	 *  @param targetClassName	Name of java class at Target database.
-	 *  @param targetMethodName	Name of method at Target database.
+	 *  @param aliasInfo		AliasInfo
 	 *  @param aliasType		The type of the alias
 	 */
 	CreateAliasConstantAction(
@@ -103,6 +104,10 @@
 				nameSpace = AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR;
 				break;
 
+			case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
+				nameSpace = AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR;
+				break;
+
 			default:
 				if (SanityManager.DEBUG)
 				{
@@ -132,6 +137,10 @@
 				type = "CREATE FUNCTION ";
 				break;
 
+			case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
+				type = "CREATE SYNONYM ";
+				break;
+
 			default:
 				if (SanityManager.DEBUG)
 				{
@@ -167,6 +176,7 @@
           				(LanguageConnectionContext.CONTEXT_ID);
 		}
 		DataDictionary dd = lcc.getDataDictionary();
+		TransactionController tc = lcc.getTransactionExecute();
 
 		/* Verify the method alias:
 		**		Aggregates - just verify the class
@@ -176,7 +186,6 @@
 		*/
 		String checkMethodName = null;
 
-			
 		String checkClassName = javaClassName;
 
 		if (aliasInfo != null)
@@ -188,7 +197,9 @@
 		{
 		case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
 		case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
+		case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
 			break;
+
 		default:
 		{
 
@@ -271,7 +282,7 @@
 									 false,
 									 aliasInfo, null);
 
-		// perform duplicate rule checking for routine
+		// perform duplicate rule checking
 		switch (aliasType) {
 		case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
 		case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
@@ -296,6 +307,58 @@
 			}
 		}
 		break;
+		case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
+			// If target table/view exists already, error.
+			TableDescriptor targetTD = dd.getTableDescriptor(aliasName, sd);
+			if (targetTD != null)
+			{
+				throw StandardException.newException(
+								SQLState.LANG_OBJECT_ALREADY_EXISTS,
+								targetTD.getDescriptorType(),
+								targetTD.getDescriptorName());
+			}
+
+			// Detect synonym cycles, if present.
+			String nextSynTable = ((SynonymAliasInfo)aliasInfo).getSynonymTable();
+			String nextSynSchema = ((SynonymAliasInfo)aliasInfo).getSynonymSchema();
+			SchemaDescriptor nextSD;
+			for (;;)
+			{
+				nextSD = dd.getSchemaDescriptor(nextSynSchema, tc, false);
+				if (nextSD == null)
+					break;
+				
+				AliasDescriptor nextAD = dd.getAliasDescriptor(nextSD.getUUID().toString(),
+						 nextSynTable, nameSpace);
+				if (nextAD == null)
+					break;
+
+				SynonymAliasInfo info = (SynonymAliasInfo) nextAD.getAliasInfo();
+				nextSynTable = info.getSynonymTable();
+				nextSynSchema = info.getSynonymSchema();
+
+				if (aliasName.equals(nextSynTable) && schemaName.equals(nextSynSchema))
+					throw StandardException.newException(SQLState.LANG_SYNONYM_CIRCULAR,
+							aliasName, ((SynonymAliasInfo)aliasInfo).getSynonymTable());
+			}
+
+			// If synonym final target is not present, raise a warning
+			if (nextSD != null)
+				targetTD = dd.getTableDescriptor(nextSynTable, nextSD);
+			if (nextSD == null || targetTD == null)
+				activation.addWarning(
+					StandardException.newWarning(SQLState.LANG_SYNONYM_UNDEFINED,
+								aliasName, nextSynSchema+"."+nextSynTable));
+
+			// To prevent any possible deadlocks with SYSTABLES, we insert a row into
+			// SYSTABLES also for synonyms. This also ensures tables/views/synonyms share
+			// same namespace
+			TableDescriptor td;
+			DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
+			td = ddg.newTableDescriptor(aliasName, sd, TableDescriptor.SYNONYM_TYPE,
+						TableDescriptor.DEFAULT_LOCK_GRANULARITY);
+			dd.addDescriptor(td, sd, DataDictionary.SYSTABLES_CATALOG_NUM, false, tc);
+		
 		default:
 			break;
 		}
@@ -303,5 +366,4 @@
 		dd.addDescriptor(ads, null, DataDictionary.SYSALIASES_CATALOG_NUM,
 						 false, lcc.getTransactionExecute());
 	}
-
 }

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropAliasConstantAction.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropAliasConstantAction.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropAliasConstantAction.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropAliasConstantAction.java Mon Jun  6 12:19:34 2005
@@ -24,6 +24,7 @@
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
@@ -102,6 +103,7 @@
 	{
 		LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
 		DataDictionary dd = lcc.getDataDictionary();
+		TransactionController tc = lcc.getTransactionExecute();
 		DependencyManager dm = dd.getDependencyManager();
 
 
@@ -129,7 +131,7 @@
 		// RESOLVE - fix error message
 		if (ad == null)
 		{
-			throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "Method alias",  aliasName);
+			throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, ad.getAliasType(nameSpace),  aliasName);
 		}
 
 		/* Prepare all dependents to invalidate.  (This is their chance
@@ -151,8 +153,16 @@
 
 		dm.invalidateFor(ad, invalidationType, lcc);
 
+		if (ad.getAliasType() == AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)
+		{
+			DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
+			TableDescriptor td = ddg.newTableDescriptor(aliasName, sd,
+				TableDescriptor.SYNONYM_TYPE, TableDescriptor.DEFAULT_LOCK_GRANULARITY);
+			dd.dropTableDescriptor(td, sd, tc);
+		}
+			
 		/* Drop the alias */
-		dd.dropAliasDescriptor(ad, lcc.getTransactionExecute());
+		dd.dropAliasDescriptor(ad, tc);
 
 	}
 }

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties Mon Jun  6 12:19:34 2005
@@ -351,6 +351,7 @@
 01503=The column {0} on table {1} has been modified by adding a not null constraint.
 01504=The new index is a duplicate of an existing index: {0}.
 01505=The value {0} may be truncated.
+01522=The newly defined synonym ''{0}'' resolved to the object ''{1}'' which is currently undefined.
 01003=Null values were eliminated from the argument of a column function.
 0100E=XX Attempt to return too many result sets. 
 02000=No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table.
@@ -413,6 +414,7 @@
 42903=Invalid use of an aggregate function.
 42908=The CREATE VIEW statement does not include a column list.
 42915=Foreign  Key ''{0}'' is invalid because ''{1}''. 
+42916=Synonym ''{0}'' cannot be created for ''{1}'' as it would result in a circular synonym chain.
 42972=An ON clause associated with a JOIN operator is not valid.
 42X01=Syntax error: {0}.
 42X02={0}.

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out (original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out Mon Jun  6 12:19:34 2005
@@ -63,6 +63,36 @@
 <systemname>
 -----
 <systemid>
+SYNONYM1
+APP
+null
+S
+S
+false
+"APP"."T1"
+<systemname>
+-----
+<systemid>
+SYNONYM2
+BAR
+null
+S
+S
+false
+"BAR"."MULTI WORD NAME"
+<systemname>
+-----
+<systemid>
+SYNONYM3
+BAR
+null
+S
+S
+false
+"APP"."T11"
+<systemname>
+-----
+<systemid>
 procTwo
 APP
 org.apache.derbyTesting.functionTests.util.ProcedureTest
@@ -1589,6 +1619,24 @@
 REMOVED
 T
 APP
+R
+-----
+SYNONYM1
+SYNONYM1
+A
+APP
+R
+-----
+SYNONYM2
+SYNONYM2
+A
+BAR
+R
+-----
+SYNONYM3
+SYNONYM3
+A
+BAR
 R
 -----
 T10

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/synonym.out
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/synonym.out?rev=180459&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/synonym.out (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/synonym.out Mon Jun  6 12:19:34 2005
@@ -0,0 +1,210 @@
+ij> -- tests for synonym support
+set schema APP;
+0 rows inserted/updated/deleted
+ij> -- negative tests
+----- Create a synonym to itself. Error.
+create synonym syn for syn;
+ERROR 42916: Synonym 'SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> create synonym syn for APP.syn;
+ERROR 42916: Synonym 'SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> create synonym APP.syn for syn;
+ERROR 42916: Synonym 'APP.SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> create synonym APP.syn for APP.syn;
+ERROR 42916: Synonym 'APP.SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> -- Create a simple synonym loop. Error.
+create synonym synonym1 for synonym;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'SYNONYM1' resolved to the object 'APP.SYNONYM' which is currently undefined. : 
+ij> create synonym synonym for synonym1;
+ERROR 42916: Synonym 'SYNONYM' cannot be created for 'SYNONYM1' as it would result in a circular synonym chain.
+ij> drop synonym synonym1;
+0 rows inserted/updated/deleted
+ij> -- Create a larger synonym loop.
+create synonym ts1 for ts;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS1' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts2 for ts1;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS2' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts3 for ts2;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS3' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts4 for ts3;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS4' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts5 for ts4;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS5' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts6 for ts5;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS6' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts for ts6;
+ERROR 42916: Synonym 'TS' cannot be created for 'TS6' as it would result in a circular synonym chain.
+ij> drop synonym App.ts1;
+0 rows inserted/updated/deleted
+ij> drop synonym "APP".ts2;
+0 rows inserted/updated/deleted
+ij> drop synonym TS3;
+0 rows inserted/updated/deleted
+ij> drop synonym ts4;
+0 rows inserted/updated/deleted
+ij> drop synonym ts5;
+0 rows inserted/updated/deleted
+ij> drop synonym app.ts6;
+0 rows inserted/updated/deleted
+ij> -- Synonyms and table/view share same namespace. Negative tests for this.
+create table table1 (i int, j int);
+0 rows inserted/updated/deleted
+ij> insert into table1 values (1,1), (2,2);
+2 rows inserted/updated/deleted
+ij> create view view1 as select i, j from table1;
+0 rows inserted/updated/deleted
+ij> create synonym table1 for t1;
+ERROR X0Y68: Table/View 'TABLE1' already exists.
+ij> create synonym APP.Table1 for t1;
+ERROR X0Y68: Table/View 'TABLE1' already exists.
+ij> create synonym app.TABLE1 for "APP"."T";
+ERROR X0Y68: Table/View 'TABLE1' already exists.
+ij> create synonym APP.VIEW1 for v1;
+ERROR X0Y68: Table/View 'VIEW1' already exists.
+ij> create synonym "APP"."VIEW1" for app.v;
+ERROR X0Y68: Table/View 'VIEW1' already exists.
+ij> -- Synonyms can't be created on temporary tables
+declare global temporary table session.t1 (c1 int) not logged;
+0 rows inserted/updated/deleted
+ij> create synonym synForTemp for session.t1;
+ERROR XCL51: The requested function can not reference tables in SESSION schema.
+ij> create synonym synForTemp for session."T1";
+ERROR XCL51: The requested function can not reference tables in SESSION schema.
+ij> -- Creating a table or a view when a synonym of that name is present. Error.
+create synonym myTable for table1;
+0 rows inserted/updated/deleted
+ij> create table myTable(i int, j int);
+ERROR X0Y32: Table/View 'MYTABLE' already exists in Schema 'APP'.
+ij> create view myTable as select * from table1;
+ERROR X0Y32: Table/View 'MYTABLE' already exists in Schema 'APP'.
+ij> -- Positive test cases
+----- Using synonym in DML
+select * from myTable;
+ERROR X0Y79: Statement.executeUpdate() cannot be called with a statement that returns a ResultSet.
+ij> select * from table1;
+I |J          
+-----
+1 |1          
+2 |2          
+ij> insert into myTable values (3,3), (4,4);
+2 rows inserted/updated/deleted
+ij> select * from mytable;
+I |J          
+-----
+1 |1          
+2 |2          
+3 |3          
+4 |4          
+ij> update myTable set i=3 where j=4;
+1 row inserted/updated/deleted
+ij> select * from mytable;
+I |J          
+-----
+1 |1          
+2 |2          
+3 |3          
+3 |4          
+ij> select * from table1;
+I |J          
+-----
+1 |1          
+2 |2          
+3 |3          
+3 |4          
+ij> delete from myTable where i> 2;
+2 rows inserted/updated/deleted
+ij> select * from "APP"."MYTABLE";
+I |J          
+-----
+1 |1          
+2 |2          
+ij> select * from APP.table1;
+I |J          
+-----
+1 |1          
+2 |2          
+ij> -- Try some cursors
+get cursor c1 as 'select * from myTable';
+ij> next c1;
+I |J          
+-----
+1 |1          
+ij> next c1;
+I |J          
+-----
+2 |2          
+ij> close c1;
+ij> -- Try updatable cursors
+autocommit off;
+ij> get cursor c2 as 'select * from myTable for update';
+ij> next c2;
+I |J          
+-----
+1 |1          
+ij> update myTable set i=5 where current of c2;
+1 row inserted/updated/deleted
+ij> close c2;
+ij> autocommit on;
+ij> select * from table1;
+I |J          
+-----
+5 |1          
+2 |2          
+ij> -- Try updatable cursors, with synonym at the top, base table inside.
+autocommit off;
+ij> get cursor c2 as 'select * from app.table1 for update';
+ij> next c2;
+I |J          
+-----
+5 |1          
+ij> update myTable set i=6 where current of c2;
+1 row inserted/updated/deleted
+ij> close c2;
+ij> autocommit on;
+ij> select * from table1;
+I |J          
+-----
+6 |1          
+2 |2          
+ij> -- trigger tests
+create table table2 (i int, j int);
+0 rows inserted/updated/deleted
+ij> -- Should fail
+create trigger tins after insert on myTable referencing new_table as new for each statement mode db2sql insert into table2 select i,j from table1;
+ERROR 42Y55: 'CREATE TRIGGER' cannot be performed on 'MYTABLE' because it does not exist.
+ij> -- Should pass
+create trigger tins after insert on table1 referencing new_table as new for each statement mode db2sql insert into table2 select i,j from table1;
+0 rows inserted/updated/deleted
+ij> drop trigger tins;
+0 rows inserted/updated/deleted
+ij> create trigger triggerins after insert on table2 referencing new_table as new for each statement mode db2sql insert into myTable select i,j from new;
+0 rows inserted/updated/deleted
+ij> select * from myTable;
+I |J          
+-----
+6 |1          
+2 |2          
+ij> insert into table2 values (5, 5);
+1 row inserted/updated/deleted
+ij> select * from myTable;
+I |J          
+-----
+6 |1          
+2 |2          
+5 |5          
+ij> drop table table2;
+0 rows inserted/updated/deleted
+ij> -- TODO: Add more tests here
+----- drop and recreate schema test
+----- More negative tests once dependency checking is added
+drop view view1;
+0 rows inserted/updated/deleted
+ij> drop table table1;
+0 rows inserted/updated/deleted
+ij> 

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/synonym.out
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out (original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out Mon Jun  6 12:19:34 2005
@@ -63,6 +63,36 @@
 <systemname>
 -----
 <systemid>
+SYNONYM1
+APP
+null
+S
+S
+false
+"APP"."T1"
+<systemname>
+-----
+<systemid>
+SYNONYM2
+BAR
+null
+S
+S
+false
+"BAR"."MULTI WORD NAME"
+<systemname>
+-----
+<systemid>
+SYNONYM3
+BAR
+null
+S
+S
+false
+"APP"."T11"
+<systemname>
+-----
+<systemid>
 procTwo
 APP
 org.apache.derbyTesting.functionTests.util.ProcedureTest
@@ -1589,6 +1619,24 @@
 REMOVED
 T
 APP
+R
+-----
+SYNONYM1
+SYNONYM1
+A
+APP
+R
+-----
+SYNONYM2
+SYNONYM2
+A
+BAR
+R
+-----
+SYNONYM3
+SYNONYM3
+A
+BAR
 R
 -----
 T10

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/synonym.out
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/synonym.out?rev=180459&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/synonym.out (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/synonym.out Mon Jun  6 12:19:34 2005
@@ -0,0 +1,210 @@
+ij> -- tests for synonym support
+set schema APP;
+0 rows inserted/updated/deleted
+ij> -- negative tests
+----- Create a synonym to itself. Error.
+create synonym syn for syn;
+ERROR 42916: Synonym 'SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> create synonym syn for APP.syn;
+ERROR 42916: Synonym 'SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> create synonym APP.syn for syn;
+ERROR 42916: Synonym 'APP.SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> create synonym APP.syn for APP.syn;
+ERROR 42916: Synonym 'APP.SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> -- Create a simple synonym loop. Error.
+create synonym synonym1 for synonym;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'SYNONYM1' resolved to the object 'APP.SYNONYM' which is currently undefined. : 
+ij> create synonym synonym for synonym1;
+ERROR 42916: Synonym 'SYNONYM' cannot be created for 'SYNONYM1' as it would result in a circular synonym chain.
+ij> drop synonym synonym1;
+0 rows inserted/updated/deleted
+ij> -- Create a larger synonym loop.
+create synonym ts1 for ts;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS1' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts2 for ts1;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS2' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts3 for ts2;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS3' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts4 for ts3;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS4' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts5 for ts4;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS5' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts6 for ts5;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS6' resolved to the object 'APP.TS' which is currently undefined. : 
+ij> create synonym ts for ts6;
+ERROR 42916: Synonym 'TS' cannot be created for 'TS6' as it would result in a circular synonym chain.
+ij> drop synonym App.ts1;
+0 rows inserted/updated/deleted
+ij> drop synonym "APP".ts2;
+0 rows inserted/updated/deleted
+ij> drop synonym TS3;
+0 rows inserted/updated/deleted
+ij> drop synonym ts4;
+0 rows inserted/updated/deleted
+ij> drop synonym ts5;
+0 rows inserted/updated/deleted
+ij> drop synonym app.ts6;
+0 rows inserted/updated/deleted
+ij> -- Synonyms and table/view share same namespace. Negative tests for this.
+create table table1 (i int, j int);
+0 rows inserted/updated/deleted
+ij> insert into table1 values (1,1), (2,2);
+2 rows inserted/updated/deleted
+ij> create view view1 as select i, j from table1;
+0 rows inserted/updated/deleted
+ij> create synonym table1 for t1;
+ERROR X0Y68: Table/View 'TABLE1' already exists.
+ij> create synonym APP.Table1 for t1;
+ERROR X0Y68: Table/View 'TABLE1' already exists.
+ij> create synonym app.TABLE1 for "APP"."T";
+ERROR X0Y68: Table/View 'TABLE1' already exists.
+ij> create synonym APP.VIEW1 for v1;
+ERROR X0Y68: Table/View 'VIEW1' already exists.
+ij> create synonym "APP"."VIEW1" for app.v;
+ERROR X0Y68: Table/View 'VIEW1' already exists.
+ij> -- Synonyms can't be created on temporary tables
+declare global temporary table session.t1 (c1 int) not logged;
+0 rows inserted/updated/deleted
+ij> create synonym synForTemp for session.t1;
+ERROR XCL51: The requested function can not reference tables in SESSION schema.
+ij> create synonym synForTemp for session."T1";
+ERROR XCL51: The requested function can not reference tables in SESSION schema.
+ij> -- Creating a table or a view when a synonym of that name is present. Error.
+create synonym myTable for table1;
+0 rows inserted/updated/deleted
+ij> create table myTable(i int, j int);
+ERROR X0Y32: Table/View 'MYTABLE' already exists in Schema 'APP'.
+ij> create view myTable as select * from table1;
+ERROR X0Y32: Table/View 'MYTABLE' already exists in Schema 'APP'.
+ij> -- Positive test cases
+----- Using synonym in DML
+select * from myTable;
+ERROR X0Y79: Statement.executeUpdate() cannot be called with a statement that returns a ResultSet.
+ij> select * from table1;
+I |J          
+-----
+1 |1          
+2 |2          
+ij> insert into myTable values (3,3), (4,4);
+2 rows inserted/updated/deleted
+ij> select * from mytable;
+I |J          
+-----
+1 |1          
+2 |2          
+3 |3          
+4 |4          
+ij> update myTable set i=3 where j=4;
+1 row inserted/updated/deleted
+ij> select * from mytable;
+I |J          
+-----
+1 |1          
+2 |2          
+3 |3          
+3 |4          
+ij> select * from table1;
+I |J          
+-----
+1 |1          
+2 |2          
+3 |3          
+3 |4          
+ij> delete from myTable where i> 2;
+2 rows inserted/updated/deleted
+ij> select * from "APP"."MYTABLE";
+I |J          
+-----
+1 |1          
+2 |2          
+ij> select * from APP.table1;
+I |J          
+-----
+1 |1          
+2 |2          
+ij> -- Try some cursors
+get cursor c1 as 'select * from myTable';
+ij> next c1;
+I |J          
+-----
+1 |1          
+ij> next c1;
+I |J          
+-----
+2 |2          
+ij> close c1;
+ij> -- Try updatable cursors
+autocommit off;
+ij> get cursor c2 as 'select * from myTable for update';
+ij> next c2;
+I |J          
+-----
+1 |1          
+ij> update myTable set i=5 where current of c2;
+1 row inserted/updated/deleted
+ij> close c2;
+ij> autocommit on;
+ij> select * from table1;
+I |J          
+-----
+5 |1          
+2 |2          
+ij> -- Try updatable cursors, with synonym at the top, base table inside.
+autocommit off;
+ij> get cursor c2 as 'select * from app.table1 for update';
+ij> next c2;
+I |J          
+-----
+5 |1          
+ij> update myTable set i=6 where current of c2;
+1 row inserted/updated/deleted
+ij> close c2;
+ij> autocommit on;
+ij> select * from table1;
+I |J          
+-----
+6 |1          
+2 |2          
+ij> -- trigger tests
+create table table2 (i int, j int);
+0 rows inserted/updated/deleted
+ij> -- Should fail
+create trigger tins after insert on myTable referencing new_table as new for each statement mode db2sql insert into table2 select i,j from table1;
+ERROR 42Y55: 'CREATE TRIGGER' cannot be performed on 'MYTABLE' because it does not exist.
+ij> -- Should pass
+create trigger tins after insert on table1 referencing new_table as new for each statement mode db2sql insert into table2 select i,j from table1;
+0 rows inserted/updated/deleted
+ij> drop trigger tins;
+0 rows inserted/updated/deleted
+ij> create trigger triggerins after insert on table2 referencing new_table as new for each statement mode db2sql insert into myTable select i,j from new;
+0 rows inserted/updated/deleted
+ij> select * from myTable;
+I |J          
+-----
+6 |1          
+2 |2          
+ij> insert into table2 values (5, 5);
+1 row inserted/updated/deleted
+ij> select * from myTable;
+I |J          
+-----
+6 |1          
+2 |2          
+5 |5          
+ij> drop table table2;
+0 rows inserted/updated/deleted
+ij> -- TODO: Add more tests here
+----- drop and recreate schema test
+----- More negative tests once dependency checking is added
+drop view view1;
+0 rows inserted/updated/deleted
+ij> drop table table1;
+0 rows inserted/updated/deleted
+ij> 

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/synonym.out
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out (original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out Mon Jun  6 12:19:34 2005
@@ -56,6 +56,36 @@
 <systemname>
 ----
 <systemid>
+SYNONYM1
+APP
+null
+S
+S
+false
+"APP"."T1"
+<systemname>
+----
+<systemid>
+SYNONYM2
+BAR
+null
+S
+S
+false
+"BAR"."MULTI WORD NAME"
+<systemname>
+----
+<systemid>
+SYNONYM3
+BAR
+null
+S
+S
+false
+"APP"."T11"
+<systemname>
+----
+<systemid>
 procTwo
 APP
 org.apache.derbyTesting.functionTests.util.ProcedureTest
@@ -1584,6 +1614,24 @@
 APP
 R
 ----
+SYNONYM1
+SYNONYM1
+A
+APP
+R
+----
+SYNONYM2
+SYNONYM2
+A
+BAR
+R
+----
+SYNONYM3
+SYNONYM3
+A
+BAR
+R
+----
 T10
 T10
 T
@@ -1932,6 +1980,36 @@
 <systemname>
 ----
 <systemid>
+SYNONYM1
+APP
+null
+S
+S
+false
+"APP"."T1"
+<systemname>
+----
+<systemid>
+SYNONYM2
+BAR
+null
+S
+S
+false
+"BAR"."MULTI WORD NAME"
+<systemname>
+----
+<systemid>
+SYNONYM3
+BAR
+null
+S
+S
+false
+"APP"."T11"
+<systemname>
+----
+<systemid>
 procTwo
 APP
 org.apache.derbyTesting.functionTests.util.ProcedureTest
@@ -3460,6 +3538,24 @@
 APP
 R
 ----
+SYNONYM1
+SYNONYM1
+A
+APP
+R
+----
+SYNONYM2
+SYNONYM2
+A
+BAR
+R
+----
+SYNONYM3
+SYNONYM3
+A
+BAR
+R
+----
 T10
 T10
 T
@@ -3768,6 +3864,26 @@
 inoutparams4(OUT A DECIMAL(4,2),IN B VARCHAR(255)) LANGUAGE JAVA PARAMETER STYLE JAVA MODIFIES SQL DATA
 <systemname>
 ----
+<systemid>
+SYNONYM2
+BAR
+null
+S
+S
+false
+"BAR"."MULTI WORD NAME"
+<systemname>
+----
+<systemid>
+SYNONYM3
+BAR
+null
+S
+S
+false
+"APP"."T11"
+<systemname>
+----
 ========== SYSCHECKS ==========
 <systemname>
 (i > 0)
@@ -4235,6 +4351,18 @@
 BAR
 R
 ----
+SYNONYM2
+SYNONYM2
+A
+BAR
+R
+----
+SYNONYM3
+SYNONYM3
+A
+BAR
+R
+----
 T1
 T1
 T
@@ -4311,6 +4439,26 @@
 System Tables for: wombat_new
 ----------------=================---------------
 ========== SYSALIASES ==========
+<systemid>
+SYNONYM2
+BAR
+null
+S
+S
+false
+"BAR"."MULTI WORD NAME"
+<systemname>
+----
+<systemid>
+SYNONYM3
+BAR
+null
+S
+S
+false
+"APP"."T11"
+<systemname>
+----
 ========== SYSCHECKS ==========
 <systemname>
 (i > 0)
@@ -4497,6 +4645,18 @@
 BAR
 R
 ----
+SYNONYM2
+SYNONYM2
+A
+BAR
+R
+----
+SYNONYM3
+SYNONYM3
+A
+BAR
+R
+----
 T3
 T3
 T
@@ -4527,6 +4687,36 @@
 System Tables for: wombat_new
 ----------------=================---------------
 ========== SYSALIASES ==========
+<systemid>
+SYNONYM1
+APP
+null
+S
+S
+false
+"APP"."T1"
+<systemname>
+----
+<systemid>
+SYNONYM2
+BAR
+null
+S
+S
+false
+"BAR"."MULTI WORD NAME"
+<systemname>
+----
+<systemid>
+SYNONYM3
+BAR
+null
+S
+S
+false
+"APP"."T11"
+<systemname>
+----
 ========== SYSCHECKS ==========
 ========== SYSCOLUMNS ==========
 --- Columns for Tables ---
@@ -4713,6 +4903,24 @@
 null
 ----
 ========== SYSTABLES ==========
+SYNONYM1
+SYNONYM1
+A
+APP
+R
+----
+SYNONYM2
+SYNONYM2
+A
+BAR
+R
+----
+SYNONYM3
+SYNONYM3
+A
+BAR
+R
+----
 T1
 T1
 T

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/synonym.out
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/synonym.out?rev=180459&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/synonym.out (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/synonym.out Mon Jun  6 12:19:34 2005
@@ -0,0 +1,213 @@
+ij> -- tests for synonym support
+set schema APP;
+0 rows inserted/updated/deleted
+ij> -- negative tests
+-- Create a synonym to itself. Error.
+create synonym syn for syn;
+ERROR 42916: Synonym 'SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> create synonym syn for APP.syn;
+ERROR 42916: Synonym 'SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> create synonym APP.syn for syn;
+ERROR 42916: Synonym 'APP.SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> create synonym APP.syn for APP.syn;
+ERROR 42916: Synonym 'APP.SYN' cannot be created for 'APP.SYN' as it would result in a circular synonym chain.
+ij> -- Create a simple synonym loop. Error.
+create synonym synonym1 for synonym;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'SYNONYM1' resolved to the object 'APP.SYNONYM' which is currently undefined.
+ij> create synonym synonym for synonym1;
+ERROR 42916: Synonym 'SYNONYM' cannot be created for 'SYNONYM1' as it would result in a circular synonym chain.
+ij> drop synonym synonym1;
+0 rows inserted/updated/deleted
+ij> -- Create a larger synonym loop.
+create synonym ts1 for ts;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS1' resolved to the object 'APP.TS' which is currently undefined.
+ij> create synonym ts2 for ts1;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS2' resolved to the object 'APP.TS' which is currently undefined.
+ij> create synonym ts3 for ts2;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS3' resolved to the object 'APP.TS' which is currently undefined.
+ij> create synonym ts4 for ts3;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS4' resolved to the object 'APP.TS' which is currently undefined.
+ij> create synonym ts5 for ts4;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS5' resolved to the object 'APP.TS' which is currently undefined.
+ij> create synonym ts6 for ts5;
+0 rows inserted/updated/deleted
+WARNING 01522: The newly defined synonym 'TS6' resolved to the object 'APP.TS' which is currently undefined.
+ij> create synonym ts for ts6;
+ERROR 42916: Synonym 'TS' cannot be created for 'TS6' as it would result in a circular synonym chain.
+ij> drop synonym App.ts1;
+0 rows inserted/updated/deleted
+ij> drop synonym "APP".ts2;
+0 rows inserted/updated/deleted
+ij> drop synonym TS3;
+0 rows inserted/updated/deleted
+ij> drop synonym ts4;
+0 rows inserted/updated/deleted
+ij> drop synonym ts5;
+0 rows inserted/updated/deleted
+ij> drop synonym app.ts6;
+0 rows inserted/updated/deleted
+ij> -- Synonyms and table/view share same namespace. Negative tests for this.
+create table table1 (i int, j int);
+0 rows inserted/updated/deleted
+ij> insert into table1 values (1,1), (2,2);
+2 rows inserted/updated/deleted
+ij> create view view1 as select i, j from table1;
+0 rows inserted/updated/deleted
+ij> create synonym table1 for t1;
+ERROR X0Y68: Table/View 'TABLE1' already exists.
+ij> create synonym APP.Table1 for t1;
+ERROR X0Y68: Table/View 'TABLE1' already exists.
+ij> create synonym app.TABLE1 for "APP"."T";
+ERROR X0Y68: Table/View 'TABLE1' already exists.
+ij> create synonym APP.VIEW1 for v1;
+ERROR X0Y68: Table/View 'VIEW1' already exists.
+ij> create synonym "APP"."VIEW1" for app.v;
+ERROR X0Y68: Table/View 'VIEW1' already exists.
+ij> -- Synonyms can't be created on temporary tables
+declare global temporary table session.t1 (c1 int) not logged;
+0 rows inserted/updated/deleted
+ij> create synonym synForTemp for session.t1;
+ERROR XCL51: The requested function can not reference tables in SESSION schema.
+ij> create synonym synForTemp for session."T1";
+ERROR XCL51: The requested function can not reference tables in SESSION schema.
+ij> -- Creating a table or a view when a synonym of that name is present. Error.
+create synonym myTable for table1;
+0 rows inserted/updated/deleted
+ij> create table myTable(i int, j int);
+ERROR X0Y32: Table/View 'MYTABLE' already exists in Schema 'APP'.
+ij> create view myTable as select * from table1;
+ERROR X0Y32: Table/View 'MYTABLE' already exists in Schema 'APP'.
+ij> -- Positive test cases
+-- Using synonym in DML
+select * from myTable;
+I          |J          
+-----------------------
+1          |1          
+2          |2          
+ij> select * from table1;
+I          |J          
+-----------------------
+1          |1          
+2          |2          
+ij> insert into myTable values (3,3), (4,4);
+2 rows inserted/updated/deleted
+ij> select * from mytable;
+I          |J          
+-----------------------
+1          |1          
+2          |2          
+3          |3          
+4          |4          
+ij> update myTable set i=3 where j=4;
+1 row inserted/updated/deleted
+ij> select * from mytable;
+I          |J          
+-----------------------
+1          |1          
+2          |2          
+3          |3          
+3          |4          
+ij> select * from table1;
+I          |J          
+-----------------------
+1          |1          
+2          |2          
+3          |3          
+3          |4          
+ij> delete from myTable where i> 2;
+2 rows inserted/updated/deleted
+ij> select * from "APP"."MYTABLE";
+I          |J          
+-----------------------
+1          |1          
+2          |2          
+ij> select * from APP.table1;
+I          |J          
+-----------------------
+1          |1          
+2          |2          
+ij> -- Try some cursors
+get cursor c1 as 'select * from myTable';
+ij> next c1;
+I          |J          
+-----------------------
+1          |1          
+ij> next c1;
+I          |J          
+-----------------------
+2          |2          
+ij> close c1;
+ij> -- Try updatable cursors
+autocommit off;
+ij> get cursor c2 as 'select * from myTable for update';
+ij> next c2;
+I          |J          
+-----------------------
+1          |1          
+ij> update myTable set i=5 where current of c2;
+1 row inserted/updated/deleted
+ij> close c2;
+ij> autocommit on;
+ij> select * from table1;
+I          |J          
+-----------------------
+5          |1          
+2          |2          
+ij> -- Try updatable cursors, with synonym at the top, base table inside.
+autocommit off;
+ij> get cursor c2 as 'select * from app.table1 for update';
+ij> next c2;
+I          |J          
+-----------------------
+5          |1          
+ij> update myTable set i=6 where current of c2;
+1 row inserted/updated/deleted
+ij> close c2;
+ij> autocommit on;
+ij> select * from table1;
+I          |J          
+-----------------------
+6          |1          
+2          |2          
+ij> -- trigger tests
+create table table2 (i int, j int);
+0 rows inserted/updated/deleted
+ij> -- Should fail
+create trigger tins after insert on myTable referencing new_table as new for each statement mode db2sql insert into table2 select i,j from table1;
+ERROR 42Y55: 'CREATE TRIGGER' cannot be performed on 'MYTABLE' because it does not exist.
+ij> -- Should pass
+create trigger tins after insert on table1 referencing new_table as new for each statement mode db2sql insert into table2 select i,j from table1;
+0 rows inserted/updated/deleted
+ij> drop trigger tins;
+0 rows inserted/updated/deleted
+ij> create trigger triggerins after insert on table2 referencing new_table as new for each statement mode db2sql insert into myTable select i,j from new;
+0 rows inserted/updated/deleted
+ij> select * from myTable;
+I          |J          
+-----------------------
+6          |1          
+2          |2          
+ij> insert into table2 values (5, 5);
+1 row inserted/updated/deleted
+ij> select * from myTable;
+I          |J          
+-----------------------
+6          |1          
+2          |2          
+5          |5          
+ij> drop table table2;
+0 rows inserted/updated/deleted
+ij> -- TODO: Add more tests here
+-- drop and recreate schema test
+-- More negative tests once dependency checking is added
+drop view view1;
+0 rows inserted/updated/deleted
+ij> drop table table1;
+0 rows inserted/updated/deleted
+ij> 

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/synonym.out
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant (original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/copyfiles.ant Mon Jun  6 12:19:34 2005
@@ -187,6 +187,7 @@
 supersimple.sql
 supersimple_derby.properties
 syscat.sql
+synonym.sql
 tempRestrictions.sql
 triggerBeforeTrig.sql
 triggerGeneral.sql

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/synonym.sql
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/synonym.sql?rev=180459&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/synonym.sql (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/synonym.sql Mon Jun  6 12:19:34 2005
@@ -0,0 +1,132 @@
+-- tests for synonym support
+
+set schema APP;
+-- negative tests
+-- Create a synonym to itself. Error.
+create synonym syn for syn;
+create synonym syn for APP.syn;
+create synonym APP.syn for syn;
+create synonym APP.syn for APP.syn;
+
+-- Create a simple synonym loop. Error.
+create synonym synonym1 for synonym;
+create synonym synonym for synonym1;
+drop synonym synonym1;
+
+-- Create a larger synonym loop.
+create synonym ts1 for ts;
+create synonym ts2 for ts1;
+create synonym ts3 for ts2;
+create synonym ts4 for ts3;
+create synonym ts5 for ts4;
+create synonym ts6 for ts5;
+create synonym ts for ts6;
+drop synonym App.ts1;
+drop synonym "APP".ts2;
+drop synonym TS3;
+drop synonym ts4;
+drop synonym ts5;
+drop synonym app.ts6;
+
+-- Synonyms and table/view share same namespace. Negative tests for this.
+create table table1 (i int, j int);
+insert into table1 values (1,1), (2,2);
+create view view1 as select i, j from table1;
+
+create synonym table1 for t1;
+create synonym APP.Table1 for t1;
+create synonym app.TABLE1 for "APP"."T";
+
+create synonym APP.VIEW1 for v1;
+create synonym "APP"."VIEW1" for app.v;
+
+-- Synonyms can't be created on temporary tables
+declare global temporary table session.t1 (c1 int) not logged;
+create synonym synForTemp for session.t1;
+create synonym synForTemp for session."T1";
+
+-- Creating a table or a view when a synonym of that name is present. Error.
+create synonym myTable for table1;
+
+create table myTable(i int, j int);
+
+create view myTable as select * from table1;
+
+
+-- Positive test cases
+
+-- Using synonym in DML
+select * from myTable;
+select * from table1;
+insert into myTable values (3,3), (4,4);
+
+select * from mytable;
+
+update myTable set i=3 where j=4;
+
+select * from mytable;
+select * from table1;
+
+delete from myTable where i> 2;
+
+select * from "APP"."MYTABLE";
+select * from APP.table1;
+
+-- Try some cursors
+get cursor c1 as 'select * from myTable';
+
+next c1;
+next c1;
+
+close c1;
+
+-- Try updatable cursors
+
+autocommit off;
+get cursor c2 as 'select * from myTable for update';
+
+next c2;
+update myTable set i=5 where current of c2;
+close c2;
+
+autocommit on;
+
+select * from table1;
+
+-- Try updatable cursors, with synonym at the top, base table inside.
+autocommit off;
+get cursor c2 as 'select * from app.table1 for update';
+
+next c2;
+update myTable set i=6 where current of c2;
+close c2;
+
+autocommit on;
+
+select * from table1;
+
+-- trigger tests
+create table table2 (i int, j int);
+
+-- Should fail
+create trigger tins after insert on myTable referencing new_table as new for each statement mode db2sql insert into table2 select i,j from table1;
+
+-- Should pass
+create trigger tins after insert on table1 referencing new_table as new for each statement mode db2sql insert into table2 select i,j from table1;
+
+drop trigger tins;
+
+create trigger triggerins after insert on table2 referencing new_table as new for each statement mode db2sql insert into myTable select i,j from new;
+
+select * from myTable;
+insert into table2 values (5, 5);
+select * from myTable;
+
+drop table table2;
+
+-- TODO: Add more tests here
+-- drop and recreate schema test
+-- More negative tests once dependency checking is added
+
+drop view view1;
+drop table table1;

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

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_makeDB.sql
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_makeDB.sql?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_makeDB.sql (original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_makeDB.sql Mon Jun  6 12:19:34 2005
@@ -103,6 +103,16 @@
 create index """Quoted""Schema"""."Ix""5" on "tee""""Hee" (n desc);
 
 -- ----------------------------------------------
+-- Synonyms
+-- ----------------------------------------------
+create synonym synonym1 for t1;
+create synonym bar.synonym2 for bar."MULTI WORD NAME";
+
+set schema bar;
+create synonym synonym3 for app.t11;
+set schema app;
+
+-- ----------------------------------------------
 -- Views
 -- ----------------------------------------------
 

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_test.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_test.java?rev=180459&r1=180458&r2=180459&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_test.java (original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_test.java Mon Jun  6 12:19:34 2005
@@ -912,7 +912,7 @@
 					rowValues = null;
 					break;
 				}
-				else if (colName.equals("JAVACLASSNAME") &&
+				else if (colName.equals("JAVACLASSNAME") && (value != null) &&
 					(value.indexOf("org.apache.derby") != -1) &&
 					(value.indexOf(".util.") == -1)) {
 				// this is a -- hack -- to see if the alias is a