Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 62629 invoked from network); 6 Jun 2005 19:20:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Jun 2005 19:20:17 -0000 Received: (qmail 19671 invoked by uid 500); 6 Jun 2005 19:20:15 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 19618 invoked by uid 500); 6 Jun 2005 19:20:15 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 19599 invoked by uid 500); 6 Jun 2005 19:20:15 -0000 Delivered-To: apmail-incubator-derby-cvs@incubator.apache.org Received: (qmail 19468 invoked by uid 99); 6 Jun 2005 19:20:14 -0000 X-ASF-Spam-Status: No, hits=-7.9 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME,WEIRD_QUOTING X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 06 Jun 2005 12:19:59 -0700 Received: (qmail 55912 invoked by uid 65534); 6 Jun 2005 19:19:45 -0000 Message-ID: <20050606191945.55905.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: 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/ Date: Mon, 06 Jun 2005 19:19:36 -0000 To: derby-cvs@incubator.apache.org From: bandaram@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: bandaram Date: Mon Jun 6 12:19:34 2005 New Revision: 180459 URL: http://svn.apache.org/viewcvs?rev=3D180459&view=3Drev Log: Derby-335: Add synonym support to Derby. See the following for more descrip= tion 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 requ= ired objects have been droped before droping synonyms and dropping of synon= yms 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, INSE= RT, UPDATE, DELETE or LOCK TABLE statements instead of the original qualified t= able 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.=20 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 Or= acle or mySQL, so I propose that Derby not support creating aliases. Synonyms ar= e 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 t= hey skipped synonyms.=20 I will be adding two new DDL statements to Derby:=20 CREATE SYNONYM . FOR .=20 DROP SYNONYM .=20 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 alr= eady present.=20 Added: incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/types/S= ynonymAliasInfo.java (with props) incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functio= nTests/master/DerbyNet/synonym.out (with props) incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functio= nTests/master/DerbyNetClient/synonym.out (with props) incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functio= nTests/master/synonym.out (with props) incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functio= nTests/tests/lang/synonym.sql (with props) Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasIn= fo.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/i= o/RegisteredFormatIds.java incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i= o/StoredFormatIds.java incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compil= e/NodeFactory.java incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictio= nary/AliasDescriptor.java incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictio= nary/TableDescriptor.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalo= g/SYSALIASESRowFactory.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalo= g/SYSTABLESRowFactory.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/CreateAliasNode.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/DMLModStatementNode.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/DropAliasNode.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/FromBaseTable.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/LockTableNode.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/NodeFactoryImpl.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/QueryTreeNode.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/UpdateNode.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/sqlgrammar.jj incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execut= e/CreateAliasConstantAction.java incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execut= e/DropAliasConstantAction.java incubator/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en= .properties incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functio= nTests/master/DerbyNet/dblook_test_net.out incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functio= nTests/master/DerbyNetClient/dblook_test_net.out incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functio= nTests/master/dblook_test.out incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functio= nTests/tests/lang/copyfiles.ant incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functio= nTests/tests/tools/dblook_makeDB.sql incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functio= nTests/tests/tools/dblook_test.java incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dbloo= k/DB_StoredProcedure.java incubator/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessage= s=2Eproperties incubator/derby/code/trunk/java/tools/org/apache/derby/tools/dblook.java Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/A= liasInfo.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/o= rg/apache/derby/catalog/AliasInfo.java?rev=3D180459&r1=3D180458&r2=3D180459= &view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasIn= fo.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/AliasIn= fo.java Mon Jun 6 12:19:34 2005 @@ -28,6 +28,7 @@ *
    *
  • method alias *
  • class alias + *
  • synonym *
  • user-defined aggregate *
* @@ -39,18 +40,22 @@ */ public static final char ALIAS_TYPE_PROCEDURE_AS_CHAR =3D 'P'; public static final char ALIAS_TYPE_FUNCTION_AS_CHAR =3D 'F'; + public static final char ALIAS_TYPE_SYNONYM_AS_CHAR =3D 'S';=09 =20 public static final String ALIAS_TYPE_PROCEDURE_AS_STRING =3D "P"; public static final String ALIAS_TYPE_FUNCTION_AS_STRING =3D "F"; + public static final String ALIAS_TYPE_SYNONYM_AS_STRING =3D "S"; =20 /** * Public statics for the various alias name spaces as both char and Stri= ng. */ public static final char ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR =3D 'P'; public static final char ALIAS_NAME_SPACE_FUNCTION_AS_CHAR =3D 'F'; + public static final char ALIAS_NAME_SPACE_SYNONYM_AS_CHAR =3D 'S'; =20 public static final String ALIAS_NAME_SPACE_PROCEDURE_AS_STRING =3D "P"; public static final String ALIAS_NAME_SPACE_FUNCTION_AS_STRING =3D "F"; + public static final String ALIAS_NAME_SPACE_SYNONYM_AS_STRING =3D "S"; =20 /** * Get the name of the static method that the alias=20 Added: incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/type= s/SynonymAliasInfo.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/o= rg/apache/derby/catalog/types/SynonymAliasInfo.java?rev=3D180459&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/types/S= ynonymAliasInfo.java (added) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/catalog/types/S= ynonymAliasInfo.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 appl= icable. + + 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 =3D null; + private String tableName =3D null; + + public SynonymAliasInfo() { + } + + /** + Create a SynonymAliasInfo for synonym. + */ + public SynonymAliasInfo(String schemaName, String tableName) + { + this.schemaName =3D schemaName; + this.tableName =3D 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 =3D (String) in.readObject(); + tableName =3D (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); + } +=20 + /** + * 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 =3D native Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/refe= rence/SQLState.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/o= rg/apache/derby/iapi/reference/SQLState.java?rev=3D180459&r1=3D180458&r2=3D= 180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- 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 =3D "01503"; String LANG_INDEX_DUPLICATE =3D "01504"; String LANG_VALUE_TRUNCATED =3D "0= 1505"; + String LANG_SYNONYM_UNDEFINED =3D "0= 1522"; String LANG_NULL_ELIMINATED_IN_SET_FUNCTION =3D "01003"; =20 String LANG_NO_ROW_FOUND =3D "02000"; @@ -707,6 +708,7 @@ String LANG_NO_AGGREGATES_IN_WHERE_CLAUSE =3D "4= 2903"; String LANG_DB2_VIEW_REQUIRES_COLUMN_NAMES =3D "4= 2908"; String LANG_DELETE_RULE_VIOLATION =3D "42915"; + String LANG_SYNONYM_CIRCULAR =3D "42916"; String LANG_DB2_ON_CLAUSE_INVALID =3D "42972"; String LANG_SYNTAX_ERROR =3D "4= 2X01"; String LANG_LEXICAL_ERROR =3D "4= 2X02"; Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/serv= ices/io/RegisteredFormatIds.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/o= rg/apache/derby/iapi/services/io/RegisteredFormatIds.java?rev=3D180459&r1= =3D180458&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i= o/RegisteredFormatIds.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i= o/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.CompressSpacePageOpera= tion" + /* 454 */ "org.apache.derby.impl.store.raw.data.CompressSpacePageOpera= tion", + /* 455 */ "org.apache.derby.catalog.types.SynonymAliasInfo" }; } Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/serv= ices/io/StoredFormatIds.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/o= rg/apache/derby/iapi/services/io/StoredFormatIds.java?rev=3D180459&r1=3D180= 458&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i= o/StoredFormatIds.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i= o/StoredFormatIds.java Mon Jun 6 12:19:34 2005 @@ -1384,6 +1384,7 @@ =20 =20 public static final int ROUTINE_INFO_V01_ID =3D (MIN_ID_2 + 451); + public static final int SYNONYM_INFO_V01_ID =3D (MIN_ID_2 + 455); =20 /****************************************************************** ** @@ -1810,7 +1811,7 @@ * Make sure this is updated when a new module is added */ public static final int MAX_ID_2 =3D - (MIN_ID_2 + 454); + (MIN_ID_2 + 455); =20 // DO NOT USE 4 BYTE IDS ANYMORE static public final int MAX_ID_4 =3D 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/o= rg/apache/derby/iapi/sql/compile/NodeFactory.java?rev=3D180459&r1=3D180458&= r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compil= e/NodeFactory.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compil= e/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/o= rg/apache/derby/iapi/sql/dictionary/AliasDescriptor.java?rev=3D180459&r1=3D= 180458&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictio= nary/AliasDescriptor.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictio= nary/AliasDescriptor.java Mon Jun 6 12:19:34 2005 @@ -288,17 +288,23 @@ /** @see TupleDescriptor#getDescriptorType */ public String getDescriptorType() { - switch (aliasType) + return getAliasType(aliasType); + } +=09 + 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; } -=09 + /** @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/o= rg/apache/derby/iapi/sql/dictionary/TableDescriptor.java?rev=3D180459&r1=3D= 180458&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictio= nary/TableDescriptor.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictio= nary/TableDescriptor.java Mon Jun 6 12:19:34 2005 @@ -101,6 +101,7 @@ public static final int SYSTEM_TABLE_TYPE =3D 1; public static final int VIEW_TYPE =3D 2; public static final int GLOBAL_TEMPORARY_TABLE_TYPE =3D 3; + public static final int SYNONYM_TYPE =3D 4; =20 public static final char ROW_LOCK_GRANULARITY =3D 'R'; public static final char TABLE_LOCK_GRANULARITY =3D 'T'; @@ -559,6 +560,18 @@ } =20 /** + * Is this descriptor represents a synonym? + * + * @return boolean Whether or not this represents a synonym + */ + public boolean isSynonymDescriptor() + { + if (tableType =3D=3D 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; } =20 /** @see TupleDescriptor#getDescriptorType */ - public String getDescriptorType() { return "Table/View"; } + public String getDescriptorType()=20 + { + return (tableType =3D=3D TableDescriptor.SYNONYM_TYPE) ? "Synonym" : "Ta= ble/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/o= rg/apache/derby/impl/sql/catalog/SYSALIASESRowFactory.java?rev=3D180459&r1= =3D180458&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalo= g/SYSALIASESRowFactory.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalo= g/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; =20 default: @@ -370,6 +371,7 @@ { case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:=20 case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:=20 + case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:=20 break; =20 default:=20 @@ -391,6 +393,7 @@ { case AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR:=20 case AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR:=20 + case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:=20 break; =20 default:=20 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/o= rg/apache/derby/impl/sql/catalog/SYSTABLESRowFactory.java?rev=3D180459&r1= =3D180458&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalo= g/SYSTABLESRowFactory.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalo= g/SYSTABLESRowFactory.java Mon Jun 6 12:19:34 2005 @@ -172,7 +172,7 @@ tableName =3D descriptor.getName(); =20 /* 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 =3D descriptor.getTableType(); switch (tabIType) @@ -187,6 +187,10 @@ tabSType =3D "V"; break; =09 =20 + case TableDescriptor.SYNONYM_TYPE: + tabSType =3D "A"; + break; =09 + default: if (SanityManager.DEBUG) SanityManager.THROWASSERT("invalid table type"); @@ -328,6 +332,9 @@ break; case 'V' : tableTypeEnum =3D TableDescriptor.VIEW_TYPE; + break; + case 'A' : + tableTypeEnum =3D 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/o= rg/apache/derby/impl/sql/compile/CreateAliasNode.java?rev=3D180459&r1=3D180= 458&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/CreateAliasNode.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/CreateAliasNode.java Mon Jun 6 12:19:34 2005 @@ -36,6 +36,8 @@ import org.apache.derby.iapi.types.TypeId; =20 import org.apache.derby.iapi.sql.dictionary.DataDictionary; +import org.apache.derby.iapi.sql.dictionary.TableDescriptor; +import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; =20 import org.apache.derby.iapi.error.StandardException; =20 @@ -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; =20 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 { =09 TableName qn =3D (TableName) aliasName; - - initAndCheck(qn); - =09 - this.javaClassName =3D (String) javaClassName; - this.methodName =3D (String) methodName; this.aliasType =3D ((Character) aliasType).charValue(); - this.delimitedIdentifier =3D - ((Boolean) delimitedIdentifier).booleanValue(); =20 + initAndCheck(qn); =20 switch (this.aliasType) { case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR: { + this.javaClassName =3D (String) targetObject; + this.methodName =3D (String) methodName; + this.delimitedIdentifier =3D + ((Boolean) delimitedIdentifier).booleanValue(); + //routineElements contains the description of the procedure. //=20 // 0 - Object[] 3 element array for parameters @@ -197,6 +199,14 @@ } break; =20 + case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: + String targetSchema; + TableName t =3D (TableName) targetObject; + if (t.getSchemaName() !=3D null) + targetSchema =3D t.getSchemaName(); + else targetSchema =3D getSchemaDescriptor().getSchemaName(); + aliasInfo =3D new SynonymAliasInfo(targetSchema, t.getTableName()); + break; =20 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 @@ =20 public QueryTreeNode bind() throws StandardException { - // Procedures do not check class or method validity until runtime execut= ion of the procedure. + // Procedures and functions do not check class or method validity until + // runtime execution. Synonyms do need some validity checks. + if (aliasType !=3D AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR) + return this; + + String targetSchema =3D ((SynonymAliasInfo)aliasInfo).getSynonymSchema(); + String targetTable =3D ((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 =3D getSchemaDescriptor(targetSchema); + + // Synonym can't be defined on temporary tables. + TableDescriptor targetTD =3D getTableDescriptor(targetTable, targetSD); + if (targetTD !=3D null && + targetTD.getTableType() =3D=3D TableDescriptor.GLOBAL_TEMPORARY_TABLE_T= YPE) + throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWE= D_ON_SESSION_SCHEMA_TABLES); =20 return this; } @@ -249,6 +280,9 @@ switch (aliasType) { case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR: + schemaName =3D getSchemaDescriptor().getSchemaName(); + break; + case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: schemaName =3D 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/o= rg/apache/derby/impl/sql/compile/DMLModStatementNode.java?rev=3D180459&r1= =3D180458&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/DMLModStatementNode.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/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 =3D targetTableName.getSchemaName(); - - SchemaDescriptor sdtc =3D getSchemaDescriptor(sntc); + SchemaDescriptor sdtc =3D getSchemaDescriptor(targetTableName.getSchema= Name()); =20 targetTableDescriptor =3D getTableDescriptor( targetTableName.getTableName(), sdtc); =20 if (targetTableDescriptor =3D=3D null) { - throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, ta= rgetTableName); + // Check if the reference is for a synonym. + TableName synonymTab =3D resolveTableToSynonym(targetTableName); + if (synonymTab =3D=3D null) + throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, t= argetTableName); + targetTableName =3D synonymTab; + sdtc =3D getSchemaDescriptor(targetTableName.getSchemaName()); + + targetTableDescriptor =3D getTableDescriptor(synonymTab.getTableName()= , sdtc); + if (targetTableDescriptor =3D=3D null) + throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, t= argetTableName); } =20 // 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/o= rg/apache/derby/impl/sql/compile/DropAliasNode.java?rev=3D180459&r1=3D18045= 8&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/DropAliasNode.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/DropAliasNode.java Mon Jun 6 12:19:34 2005 @@ -75,6 +75,10 @@ nameSpace =3D AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR; break; =20 + case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: + nameSpace =3D 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 =3D "FUNCTION"; + break; + case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: + typeName =3D "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/o= rg/apache/derby/impl/sql/compile/FromBaseTable.java?rev=3D180459&r1=3D18045= 8&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/FromBaseTable.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/FromBaseTable.java Mon Jun 6 12:19:34 2005 @@ -2369,7 +2369,16 @@ } else { - throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tab= leName); + // Check if the reference is for a synonym. + TableName synonymTab =3D resolveTableToSynonym(tableName); + if (synonymTab =3D=3D null) + throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, ta= bleName); + tableName =3D synonymTab; + sd =3D getSchemaDescriptor(tableName.getSchemaName()); + + tableDescriptor =3D getTableDescriptor(synonymTab.getTableName(), sd); + if (tableDescriptor =3D=3D null) + throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, ta= bleName); } =20 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/o= rg/apache/derby/impl/sql/compile/LockTableNode.java?rev=3D180459&r1=3D18045= 8&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/LockTableNode.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/LockTableNode.java Mon Jun 6 12:19:34 2005 @@ -130,7 +130,16 @@ =20 if (lockTableDescriptor =3D=3D null) { - throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tab= leName); + // Check if the reference is for a synonym. + TableName synonymTab =3D resolveTableToSynonym(tableName); + if (synonymTab =3D=3D null) + throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, ta= bleName); + tableName =3D synonymTab; + sd =3D getSchemaDescriptor(tableName.getSchemaName()); + + lockTableDescriptor =3D getTableDescriptor(synonymTab.getTableName(), s= d); + if (lockTableDescriptor =3D=3D null) + throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, ta= bleName); } =20 //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/o= rg/apache/derby/impl/sql/compile/NodeFactoryImpl.java?rev=3D180459&r1=3D180= 458&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/NodeFactoryImpl.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/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 =3D null; - String javaClassName =3D fullStaticMethodName; String targetMethodName =3D null; String targetClassName =3D null; =20 nodeType =3D C_NodeTypes.CREATE_ALIAS_NODE; =20 - int lastPeriod; - int paren =3D fullStaticMethodName.indexOf('('); - if (paren =3D=3D -1) { - // not a Java signature - split based on last period - lastPeriod =3D fullStaticMethodName.lastIndexOf('.'); - } else { - // a Java signature - split on last period before the '(' - lastPeriod =3D fullStaticMethodName.substring(0, paren).lastIn= dexOf('.'); - } - if (lastPeriod =3D=3D -1 || lastPeriod =3D=3D fullStaticMethodName= .length()-1) { - throw StandardException.newException(SQLState.LANG_INVALID_FUL= L_STATIC_METHOD_NAME, fullStaticMethodName); - } - javaClassName =3D fullStaticMethodName.substring(0, lastPeriod); - methodName =3D fullStaticMethodName.substring(lastPeriod + 1); + if (aliasType !=3D AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR) + { + int lastPeriod; + String fullStaticMethodName =3D (String) targetName; + int paren =3D fullStaticMethodName.indexOf('('); + if (paren =3D=3D -1) { + // not a Java signature - split based on last period + lastPeriod =3D fullStaticMethodName.lastIndexOf('.'); + } else { + // a Java signature - split on last period before the '(' + lastPeriod =3D fullStaticMethodName.substring(0, paren).lastI= ndexOf('.'); + } + if (lastPeriod =3D=3D -1 || lastPeriod =3D=3D fullStaticMethodNam= e=2Elength()-1) { + throw StandardException.newException(SQLState.LANG_INVALID_FU= LL_STATIC_METHOD_NAME, fullStaticMethodName); + } + String javaClassName =3D fullStaticMethodName.substring(0, lastPe= riod); + methodName =3D fullStaticMethodName.substring(lastPeriod + 1); + targetName =3D javaClassName; + } =20 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/o= rg/apache/derby/impl/sql/compile/QueryTreeNode.java?rev=3D180459&r1=3D18045= 8&r2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/QueryTreeNode.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/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; =20 //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 =3D getDataDictionary().getTableDescriptor(tableName,= schema); + if (td =3D=3D null || td.isSynonymDescriptor()) + return null; + return td; } =20 /** @@ -1467,6 +1472,49 @@ } } return sdCatalog; + } + + /** + * Resolve table/view reference to a synonym. May have to follow a synony= m 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 Standard= Exception + { + DataDictionary dd =3D getDataDictionary(); + String nextSynonymTable =3D tabName.getTableName(); + String nextSynonymSchema =3D tabName.getSchemaName(); + boolean found =3D false; + + // Circular synonym references should have been detected at the DDL time= , so + // the following loop shouldn't loop forever. + for (;;) + { + SchemaDescriptor nextSD =3D getSchemaDescriptor(nextSynonymSchema, fals= e); + if (nextSD =3D=3D null || nextSD.getUUID() =3D=3D null) + break; +=09 + AliasDescriptor nextAD =3D dd.getAliasDescriptor(nextSD.getUUID().toStr= ing(), + nextSynonymTable, AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR); + if (nextAD =3D=3D null) + break; + + found =3D true; + SynonymAliasInfo info =3D ((SynonymAliasInfo)nextAD.getAliasInfo()); + nextSynonymTable =3D info.getSynonymTable(); + nextSynonymSchema =3D info.getSynonymSchema(); + } + + if (!found) + return null; + + TableName tableName =3D new TableName(); + tableName.init(nextSynonymSchema, nextSynonymTable); + return tableName; } =20 /** 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/o= rg/apache/derby/impl/sql/compile/UpdateNode.java?rev=3D180459&r1=3D180458&r= 2=3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/UpdateNode.java (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/UpdateNode.java Mon Jun 6 12:19:34 2005 @@ -201,6 +201,11 @@ =20 DataDictionary dataDictionary =3D getDataDictionary(); =20 + // check if targetTable is a synonym + TableName synonymTab =3D resolveTableToSynonym(this.targetTableName); + if (synonymTab !=3D null) + this.targetTableName =3D synonymTab; + bindTables(dataDictionary); =20 // 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/o= rg/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=3D180459&r1=3D180458&r2= =3D180459&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/sqlgrammar.jj (original) +++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compil= e/sqlgrammar.jj Mon Jun 6 12:19:34 2005 @@ -1868,6 +1868,7 @@ | | | +| | | | @@ -2413,7 +2414,8 @@ ( statementNode =3D schemaDefinition() | statementNode =3D viewDefinition(beginToken) | - statementNode =3D triggerDefinition() + statementNode =3D triggerDefinition() | + statementNode =3D synonymDefinition() ) { } @@ -9048,6 +9050,32 @@ } } =20 +QueryTreeNode +synonymDefinition() throws StandardException : +{ + TableName synonymName; + TableName targetName; +} +{ + synonymName =3D qualifiedName(Limits.MAX_IDENTIFIER_LENGTH) = + targetName =3D 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); } =20 +| aliasName =3D qualifiedName(Limits.MAX_IDENTIFIER_LENGTH) + { + checkVersion(DataDictionary.DD_VERSION_DERBY_10_1, "DROP SYNONYM"); + + return dropAliasNode(aliasName, AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR); + } } =20 QueryTreeNode @@ -11537,6 +11571,7 @@ | tok =3D | tok =3D | tok =3D + | tok =3D | tok =3D