db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r810151 - in /db/derby/code/trunk: java/engine/org/apache/derby/iapi/sql/compile/ java/engine/org/apache/derby/iapi/sql/depend/ java/engine/org/apache/derby/iapi/sql/dictionary/ java/engine/org/apache/derby/impl/sql/catalog/ java/engine/org...
Date Tue, 01 Sep 2009 18:06:31 GMT
Author: rhillegas
Date: Tue Sep  1 18:06:30 2009
New Revision: 810151

URL: http://svn.apache.org/viewvc?rev=810151&view=rev
Log:
DERBY-712: Committed Suran Jayathilaka's create_drop_sequence_d.patch. This adds CREATE/DROP
SEQUENCE commands.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateSequenceNode.java
  (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropSequenceNode.java
  (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateSequenceConstantAction.java
  (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/depend/DependencyManager.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SequenceDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSSEQUENCESRowFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
    db/derby/code/trunk/tools/jar/DBMSnodes.properties

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java?rev=810151&r1=810150&r2=810151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java Tue
Sep  1 18:06:30 2009
@@ -236,8 +236,12 @@
 	// OFFSET, FETCH FIRST node
 	static final int ROW_COUNT_NODE = 223;
 
+    // sequences
+    static final int CREATE_SEQUENCE_NODE = 224;
+    static final int DROP_SEQUENCE_NODE = 225;
+
     // Final value in set, keep up to date!
-    static final int FINAL_VALUE = ROW_COUNT_NODE;
+    static final int FINAL_VALUE = DROP_SEQUENCE_NODE;
 
     /**
      * Extensions to this interface can use nodetypes > MAX_NODE_TYPE with out fear of
collision

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/depend/DependencyManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/depend/DependencyManager.java?rev=810151&r1=810150&r2=810151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/depend/DependencyManager.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/depend/DependencyManager.java
Tue Sep  1 18:06:30 2009
@@ -35,7 +35,7 @@
 	The dependency manager tracks needs that dependents have of providers. This
 	is a general purpose interface which is associated with a
 	DataDictinary object; infact the dependencymanager is really the
-	datadictionary keeping track of dependcies between objects that it handles
+	datadictionary keeping track of dependencies between objects that it handles
 	(descriptors) as well as prepared statements.
 	<p>
 	The primary example of this is a prepared statement's needs of 
@@ -335,7 +335,9 @@
 	// current role for privileges by recreating the activation.
 	public static final int RECHECK_PRIVILEGES = 48;
 
-	/**
+    public static final int DROP_SEQUENCE = 49;
+
+    /**
      * Extensions to this interface may use action codes > MAX_ACTION_CODE without fear
of
      * clashing with action codes in this base interface.
      */

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SequenceDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SequenceDescriptor.java?rev=810151&r1=810150&r2=810151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SequenceDescriptor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SequenceDescriptor.java
Tue Sep  1 18:06:30 2009
@@ -24,19 +24,22 @@
 import org.apache.derby.catalog.UUID;
 import org.apache.derby.catalog.DependableFinder;
 import org.apache.derby.catalog.Dependable;
-import org.apache.derby.catalog.TypeDescriptor;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
 import org.apache.derby.iapi.sql.depend.Provider;
+import org.apache.derby.iapi.sql.depend.DependencyManager;
+import org.apache.derby.iapi.sql.depend.Dependent;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 import org.apache.derby.iapi.types.DataTypeDescriptor;
+import org.apache.derby.iapi.store.access.TransactionController;
 import org.apache.derby.impl.sql.catalog.DDdependableFinder;
 
 /**
  * This class is used by rows in the SYS.SYSSEQUENCES system table.
  */
 public class SequenceDescriptor extends TupleDescriptor
-        implements Provider, UniqueSQLObjectDescriptor {
+        implements Provider, Dependent, UniqueSQLObjectDescriptor {
 
     private UUID sequenceUUID;
     private String sequenceName;
@@ -107,6 +110,86 @@
         }
     }
 
+    /**
+     * Drop this sequence descriptor
+     *
+     * @throws StandardException Could not be dropped.
+     */
+    public void drop(LanguageConnectionContext lcc) throws StandardException
+    {
+        DataDictionary dd = getDataDictionary();
+        DependencyManager dm = getDataDictionary().getDependencyManager();
+        TransactionController tc = lcc.getTransactionExecute();
+
+        // invalidate compiled statements which depend on this sequence
+        dm.invalidateFor(this, DependencyManager.DROP_SEQUENCE, lcc);
+
+        // drop the sequence
+        dd.dropSequenceDescriptor(this, tc);
+
+        // Clear the dependencies for the sequence
+        dm.clearDependencies(lcc, this);
+
+    }
+
+    /**
+	 * Check that all of the dependent's dependencies are valid.
+	 *
+	 * @return true if the dependent is currently valid
+	 */
+	public synchronized boolean isValid()
+	{
+		return true;
+	}
+
+    /**
+	 * Prepare to mark the dependent as invalid (due to at least one of
+	 * its dependencies being invalid).
+	 *
+	 * @param action	The action causing the invalidation
+	 * @param p			the provider
+	 * @param lcc		the language connection context
+	 *
+	 * @exception StandardException thrown if unable to make it invalid
+	 */
+	public void prepareToInvalidate
+	(
+		Provider 					p,
+		int							action,
+		LanguageConnectionContext	lcc
+	) throws StandardException
+	{
+		switch (action)
+		{   			
+			default:
+				break;
+		}
+	}
+    /**
+	 * Mark the dependent as invalid (due to at least one of
+	 * its dependencies being invalid).
+	 *
+	 * @param 	lcc the language connection context
+	 * @param	action	The action causing the invalidation
+	 *
+	 * @exception StandardException thrown if called in sanity mode
+	 */
+	public void makeInvalid(int action, LanguageConnectionContext lcc) throws StandardException
+	{
+		switch (action)
+		{
+			// invalidate this sequence descriptor
+			case DependencyManager.USER_RECOMPILE_REQUEST:
+				DependencyManager dm = getDataDictionary().getDependencyManager();
+				dm.invalidateFor(this, DependencyManager.PREPARED_STATEMENT_RELEASE, lcc);
+				break;
+
+			default:
+				break;
+		}
+
+	}
+
     public String getName() {
         return sequenceName;
     }
@@ -115,6 +198,19 @@
         return schemaDescriptor;
     }
 
+    /**
+     * @see TupleDescriptor#getDescriptorType
+     */
+    public String getDescriptorType() {
+        return "Sequence";
+    }
+
+    /**
+     * @see TupleDescriptor#getDescriptorName
+     */
+    public String getDescriptorName() {
+        return sequenceName; }
+
     //////////////////////////////////////////////
     //
     // PROVIDER INTERFACE

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSSEQUENCESRowFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSSEQUENCESRowFactory.java?rev=810151&r1=810150&r2=810151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSSEQUENCESRowFactory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSSEQUENCESRowFactory.java
Tue Sep  1 18:06:30 2009
@@ -232,8 +232,18 @@
         suuid = getUUIDFactory().recreateUUID(schemaIdString);
 
         // fourth column is the data type of this sequene generator
-        DataTypeDescriptor dataType = (DataTypeDescriptor) row.getColumn(SYSSEQUENCES_SEQUENCEDATATYPE).
+        /*
+          ** What is stored in the column is a TypeDescriptorImpl, which
+          ** points to a BaseTypeIdImpl.  These are simple types that are
+          ** intended to be movable to the client, so they don't have
+          ** the entire implementation.  We need to wrap them in DataTypeServices
+          ** and TypeId objects that contain the full implementations for
+          ** language processing.
+          */
+        TypeDescriptor catalogType = (TypeDescriptor) row.getColumn(SYSSEQUENCES_SEQUENCEDATATYPE).
                 getObject();
+        DataTypeDescriptor dataTypeServices =
+                DataTypeDescriptor.getType(catalogType);
 
         col = row.getColumn(SYSSEQUENCES_CURRENT_VALUE);
         currentValue = col.getLong();
@@ -257,7 +267,7 @@
                 (dd.getSchemaDescriptor(suuid, null),
                         ouuid,
                         sequenceName,
-                        dataType,
+                        dataTypeServices,
                         currentValue,
                         startValue,
                         minimumValue,

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java?rev=810151&r1=810150&r2=810151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java Tue
Sep  1 18:06:30 2009
@@ -91,7 +91,9 @@
 
 	static final String CREATE_SCHEMA_NODE_NAME = "org.apache.derby.impl.sql.compile.CreateSchemaNode";
 
-	static final String CREATE_TABLE_NODE_NAME = "org.apache.derby.impl.sql.compile.CreateTableNode";
+    static final String CREATE_SEQUENCE_NODE_NAME = "org.apache.derby.impl.sql.compile.CreateSequenceNode";
+
+    static final String CREATE_TABLE_NODE_NAME = "org.apache.derby.impl.sql.compile.CreateTableNode";
 
 	static final String CREATE_TRIGGER_NODE_NAME = "org.apache.derby.impl.sql.compile.CreateTriggerNode";
 
@@ -126,7 +128,9 @@
 
 	static final String DROP_SCHEMA_NODE_NAME = "org.apache.derby.impl.sql.compile.DropSchemaNode";
 
-	static final String DROP_TABLE_NODE_NAME = "org.apache.derby.impl.sql.compile.DropTableNode";
+    static final String DROP_SEQUENCE_NODE_NAME = "org.apache.derby.impl.sql.compile.DropSequenceNode";
+
+    static final String DROP_TABLE_NODE_NAME = "org.apache.derby.impl.sql.compile.DropTableNode";
 
 	static final String DROP_TRIGGER_NODE_NAME = "org.apache.derby.impl.sql.compile.DropTriggerNode";
 

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateSequenceNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateSequenceNode.java?rev=810151&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateSequenceNode.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateSequenceNode.java
Tue Sep  1 18:06:30 2009
@@ -0,0 +1,106 @@
+/*
+
+   Derby - Class org.apache.derby.impl.sql.compile.CreateSequenceNode
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.impl.sql.compile;
+
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.services.sanity.SanityManager;
+import org.apache.derby.iapi.sql.compile.CompilerContext;
+import org.apache.derby.iapi.sql.execute.ConstantAction;
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
+
+/**
+ * A CreateSequenceNode is the root of a QueryTree that
+ * represents a CREATE SEQUENCE statement.
+ */
+
+public class CreateSequenceNode extends DDLStatementNode {
+    private TableName sequenceName;
+
+    public static final int SEQUENCE_ELEMENT_COUNT = 1;
+
+    /**
+     * Initializer for a CreateSequenceNode
+     *
+     * @param sequenceName The name of the new sequence
+     * @throws org.apache.derby.iapi.error.StandardException
+     *          Thrown on error
+     */
+    public void init(Object sequenceName) throws StandardException {
+        this.sequenceName = (TableName) sequenceName;
+        initAndCheck(sequenceName);
+
+        // automcatically create the schema if it doesn't exist
+        implicitCreateSchema = true;
+    }
+
+    /**
+     * Convert this object to a String.  See comments in QueryTreeNode.java
+     * for how this should be done for tree printing.
+     *
+     * @return This object as a String
+     */
+
+    public String toString() {
+        if (SanityManager.DEBUG) {
+            return super.toString() +
+                    "sequenceName: " + "\n" + sequenceName + "\n";
+        } else {
+            return "";
+        }
+    }
+
+    /**
+     * Bind this CreateSequenceNode.
+     * The main objectives of this method are to resolve the schema name, determine privilege
checks,
+     * and vet the variables in the CREATE SEQUENCE statement.
+     */
+    public void bindStatement() throws StandardException {
+        CompilerContext cc = getCompilerContext();
+
+        // implicitly create the schema if it does not exist.
+        // this method also compiles permissions checks
+        SchemaDescriptor sd = getSchemaDescriptor();
+
+//        sequenceName.bind( getDataDictionary() );
+        // set the default schema name if the user did not explicitly specify a schema
+        if (sequenceName.getSchemaName() == null) {
+            sequenceName.setSchemaName(sd.getSchemaName());
+        }
+    }
+
+    public String statementToString() {
+        return "CREATE SEQUENCE";
+    }
+
+    // We inherit the generate() method from DDLStatementNode.
+
+    /**
+     * Create the Constant information that will drive the guts of Execution.
+     *
+     * @throws org.apache.derby.iapi.error.StandardException
+     *          Thrown on failure
+     */
+    public ConstantAction makeConstantAction() {
+        return getGenericConstantActionFactory().
+                getCreateSequenceConstantAction(sequenceName);
+    }
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateSequenceNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropSequenceNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropSequenceNode.java?rev=810151&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropSequenceNode.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropSequenceNode.java
Tue Sep  1 18:06:30 2009
@@ -0,0 +1,90 @@
+/*
+
+   Derby - Class org.apache.derby.impl.sql.compile.DropSequenceNode
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.impl.sql.compile;
+
+import org.apache.derby.iapi.sql.execute.ConstantAction;
+import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
+import org.apache.derby.iapi.sql.dictionary.SequenceDescriptor;
+
+/**
+ * A DropSequenceNode  represents a DROP SEQUENCE statement.
+ */
+
+public class DropSequenceNode extends DDLStatementNode {
+    private TableName dropItem;
+
+    /**
+     * Initializer for a DropSequenceNode
+     *
+     * @param dropSequenceName The name of the sequence being dropped
+     * @throws StandardException
+     */
+    public void init(Object dropSequenceName)
+            throws StandardException {
+        dropItem = (TableName) dropSequenceName;
+        initAndCheck(dropItem);
+    }
+
+    public String statementToString() {
+        return "DROP ".concat(dropItem.getTableName());
+    }
+
+    /**
+     * Bind this DropSequenceNode.
+     *
+     * @throws StandardException Thrown on error
+     */
+    public void bindStatement() throws StandardException {
+        DataDictionary dataDictionary = getDataDictionary();
+        String sequenceName = getRelativeName();
+
+        SequenceDescriptor seqDesc = null;
+        SchemaDescriptor sd = getSchemaDescriptor();
+
+        if (sd.getUUID() != null) {
+            seqDesc = dataDictionary.getSequenceDescriptor
+                    (sd, sequenceName);
+        }
+        if (seqDesc == null) {
+            throw StandardException.newException(SQLState.LANG_OBJECT_DOES_NOT_EXIST, statementToString(),
sequenceName);
+        }
+
+        // Statement is dependent on the SequenceDescriptor
+        getCompilerContext().createDependency(seqDesc);
+    }
+
+    // inherit generate() method from DDLStatementNode
+
+
+    /**
+     * Create the Constant information that will drive the guts of Execution.
+     *
+     * @throws StandardException Thrown on failure
+     */
+    public ConstantAction makeConstantAction() throws StandardException {
+        return getGenericConstantActionFactory().getDropSequenceConstantAction(getSchemaDescriptor(),
getRelativeName());
+	}
+
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropSequenceNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java?rev=810151&r1=810150&r2=810151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
Tue Sep  1 18:06:30 2009
@@ -626,7 +626,13 @@
           case C_NodeTypes.ROW_COUNT_NODE:
             return C_NodeNames.ROW_COUNT_NODE_NAME;
 
-		  // WARNING: WHEN ADDING NODE TYPES HERE, YOU MUST ALSO ADD
+          case C_NodeTypes.CREATE_SEQUENCE_NODE:
+            return C_NodeNames.CREATE_SEQUENCE_NODE_NAME;
+
+          case C_NodeTypes.DROP_SEQUENCE_NODE:
+            return C_NodeNames.DROP_SEQUENCE_NODE_NAME;
+
+          // WARNING: WHEN ADDING NODE TYPES HERE, YOU MUST ALSO ADD
 		  // THEM TO tools/jar/DBMSnodes.properties
 
 		  default:

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=810151&r1=810150&r2=810151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Tue Sep
 1 18:06:30 2009
@@ -2822,7 +2822,8 @@
             statementNode = viewDefinition(beginToken) |
             statementNode = triggerDefinition() |
             statementNode = synonymDefinition() |
-            statementNode = roleDefinition()
+            statementNode = roleDefinition() |
+            statementNode = sequenceDefinition()
         )
         {
         }
@@ -2859,7 +2860,8 @@
             statementNode = dropAliasStatement() |
             statementNode = dropViewStatement() |
             statementNode = dropTriggerStatement() |
-            statementNode = dropRoleStatement()
+            statementNode = dropRoleStatement() |
+            statementNode = dropSequenceStatement()
         )
 	{
 		return statementNode;
@@ -9807,6 +9809,47 @@
 	}
 }
 
+/*
+ * <A NAME="sequenceDefinition">sequenceDefinition</A>
+ */
+StatementNode
+sequenceDefinition() throws StandardException :
+{
+	TableName qualifiedSequenceName = null;
+}
+{
+	<SEQUENCE> qualifiedSequenceName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH)
+	{
+		checkVersion( DataDictionary.DD_VERSION_DERBY_10_6, "SEQUENCES");
+		return (StatementNode) nodeFactory.getNode(
+			C_NodeTypes.CREATE_SEQUENCE_NODE,
+			qualifiedSequenceName,
+			getContextManager());
+	}
+}
+
+/*
+ * <A NAME="dropSequenceStatement">dropSequenceStatement</A>
+ */
+StatementNode
+dropSequenceStatement() throws StandardException :
+{
+	TableName sequenceName;
+}
+{
+	/*
+	 * DROP SEQUENCE <sequencename>
+	 */
+	<SEQUENCE> sequenceName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH)
+	{
+		checkVersion( DataDictionary.DD_VERSION_DERBY_10_6, "SEQUENCES");
+
+		return (StatementNode) nodeFactory.getNode(
+			C_NodeTypes.DROP_SEQUENCE_NODE,
+			sequenceName,
+			getContextManager());
+	}
+}
 
 /*
  * <A NAME="tableDefinition">tableDefinition</A>

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java?rev=810151&r1=810150&r2=810151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
Tue Sep  1 18:06:30 2009
@@ -886,7 +886,10 @@
 		    case RECHECK_PRIVILEGES:
 				return "RECHECK PRIVILEGES";
 
-			default:
+            case DROP_SEQUENCE:
+				return "DROP SEQUENCE";
+
+            default:
 				if (SanityManager.DEBUG)
 				{
 					SanityManager.THROWASSERT("getActionString() passed an invalid value (" + action + ")");

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateSequenceConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateSequenceConstantAction.java?rev=810151&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateSequenceConstantAction.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateSequenceConstantAction.java
Tue Sep  1 18:06:30 2009
@@ -0,0 +1,108 @@
+/*
+
+   Derby - Class org.apache.derby.impl.sql.execute.CreateSequenceConstantAction
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.impl.sql.execute;
+
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.sql.Activation;
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
+import org.apache.derby.iapi.sql.dictionary.SequenceDescriptor;
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;
+import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.iapi.store.access.TransactionController;
+import org.apache.derby.iapi.types.DataTypeDescriptor;
+import org.apache.derby.shared.common.reference.SQLState;
+
+/**
+ * This class performs actions that are ALWAYS performed for a
+ * CREATE SEQUENCE statement at execution time.
+ * These SQL objects are stored in the SYS.SYSSEQUENCES table.
+ */
+class CreateSequenceConstantAction extends DDLConstantAction {
+
+    private String sequenceName;
+    private String schemaName;
+
+    // CONSTRUCTORS
+    /**
+     * Make the ConstantAction for a CREATE SEQUENCE statement.
+     * When executed, will create a sequence by the given name.
+     *
+     * @param sequenceName The name of the sequence being created
+     */
+    public CreateSequenceConstantAction(String schemaName, String sequenceName) {
+        this.schemaName = schemaName;
+        this.sequenceName = sequenceName;
+    }
+
+    // INTERFACE METHODS
+
+    /**
+     * This is the guts of the Execution-time logic for CREATE SEQUENCE.
+     *
+     * @throws org.apache.derby.iapi.error.StandardException
+     *          Thrown on failure
+     * @see org.apache.derby.iapi.sql.execute.ConstantAction#executeConstantAction
+     */
+    public void executeConstantAction(Activation activation)
+            throws StandardException {
+        SchemaDescriptor schemaDescriptor;
+        LanguageConnectionContext lcc =
+                activation.getLanguageConnectionContext();
+        DataDictionary dd = lcc.getDataDictionary();
+        TransactionController tc = lcc.getTransactionExecute();
+        DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
+
+        dd.startWriting(lcc);
+
+        schemaDescriptor = DDLConstantAction.getSchemaDescriptorForCreate(dd, activation,
schemaName);
+
+        //
+        // Check if this sequence already exists. If it does, throw.
+        //
+        SequenceDescriptor seqDef = dd.getSequenceDescriptor(schemaDescriptor, sequenceName);
+
+        if (seqDef != null) {
+            throw StandardException.
+                    newException(SQLState.LANG_OBJECT_ALREADY_EXISTS,
+                            seqDef.getDescriptorType(), sequenceName);
+        }
+
+        seqDef = ddg.newSequenceDescriptor(schemaDescriptor,
+                dd.getUUIDFactory().createUUID(),
+                sequenceName, DataTypeDescriptor.INTEGER_NOT_NULL, 0, 0, Integer.MIN_VALUE,
Integer.MAX_VALUE, 1, false);        // is definition
+
+        dd.addDescriptor(seqDef,
+                null,  // parent
+                DataDictionary.SYSSEQUENCES_CATALOG_NUM,
+                false, // duplicatesAllowed
+                tc);
+    }
+
+    // OBJECT SHADOWS
+
+    public String toString() {
+        // Do not put this under SanityManager.DEBUG - it is needed for
+        // error reporting.
+        return "CREATE SEQUENCE " + sequenceName;
+    }
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateSequenceConstantAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java?rev=810151&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java
Tue Sep  1 18:06:30 2009
@@ -0,0 +1,106 @@
+/*
+
+   Derby - Class org.apache.derby.impl.sql.execute.DropSequenceConstantAction
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.impl.sql.execute;
+
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.sql.Activation;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.iapi.sql.depend.DependencyManager;
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;
+import org.apache.derby.iapi.sql.dictionary.SequenceDescriptor;
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
+import org.apache.derby.iapi.store.access.TransactionController;
+import org.apache.derby.shared.common.reference.SQLState;
+
+/**
+ * This class  describes actions that are ALWAYS performed for a
+ * DROP SEQUENCE Statement at Execution time.
+ */
+
+class DropSequenceConstantAction extends DDLConstantAction {
+
+
+    private final String sequenceName;
+    private final SchemaDescriptor schemaDescriptor;
+
+    // CONSTRUCTORS
+
+    /**
+     * Make the ConstantAction for a DROP SEQUENCE statement.
+     *
+     * @param sequenceName sequence name to be dropped
+     */
+    DropSequenceConstantAction(SchemaDescriptor sd, String sequenceName) {
+        this.sequenceName = sequenceName;
+        this.schemaDescriptor = sd;
+    }
+
+    ///////////////////////////////////////////////
+    //
+    // OBJECT SHADOWS
+    //
+    ///////////////////////////////////////////////
+
+    public String toString() {
+        // Do not put this under SanityManager.DEBUG - it is needed for
+        // error reporting.
+        return "DROP SEQUENCE " + sequenceName;
+    }
+
+    // INTERFACE METHODS
+
+
+    /**
+     * This is the guts of the Execution-time logic for DROP SEQUENCE.
+     *
+     * @see org.apache.derby.iapi.sql.execute.ConstantAction#executeConstantAction
+     */
+    public void executeConstantAction(Activation activation)
+            throws StandardException {
+        LanguageConnectionContext lcc =
+                activation.getLanguageConnectionContext();
+        DataDictionary dd = lcc.getDataDictionary();
+        TransactionController tc = lcc.getTransactionExecute();
+
+        /*
+        ** Inform the data dictionary that we are about to write to it.
+        ** There are several calls to data dictionary "get" methods here
+        ** that might be done in "read" mode in the data dictionary, but
+        ** it seemed safer to do this whole operation in "write" mode.
+        **
+        ** We tell the data dictionary we're done writing at the end of
+        ** the transaction.
+        */
+        dd.startWriting(lcc);
+
+        SequenceDescriptor sequenceDescriptor = dd.getSequenceDescriptor(schemaDescriptor,
sequenceName);
+
+        if (sequenceDescriptor == null) {
+
+            throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND_DURING_EXECUTION,
"SEQUENCE",
+                    (schemaDescriptor.getObjectName() + "." + sequenceName));
+        }
+
+        sequenceDescriptor.drop(lcc);
+
+    }
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropSequenceConstantAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java?rev=810151&r1=810150&r2=810151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
Tue Sep  1 18:06:30 2009
@@ -52,6 +52,7 @@
 import org.apache.derby.catalog.AliasInfo;
 
 import org.apache.derby.iapi.services.io.FormatableBitSet;
+import org.apache.derby.impl.sql.compile.TableName;
 
 import java.util.List;
 import java.util.Properties;
@@ -318,8 +319,17 @@
 		return new SetRoleConstantAction(roleName, type);
 	}
 
+    /**
+	 * Make the ConstantAction for a CREATE SEQUENCE statement.
+	 *
+	 * @param sequenceName	Name of sequence.
+	 */
+	public	ConstantAction	getCreateSequenceConstantAction(TableName sequenceName)
+	{
+        return new CreateSequenceConstantAction(sequenceName.getSchemaName(), sequenceName.getTableName());
+	}
 
-	/**
+    /**
 	 *	Make the ConstantAction for a CREATE TABLE statement.
 	 *
 	 *  @param schemaName	name for the schema that table lives in.
@@ -570,8 +580,20 @@
 		return new DropRoleConstantAction(roleName);
 	}
 
+    /**
+	 *	Make the ConstantAction for a DROP SEQUENCE statement.
+	 *
+     *  @param sd the schema the sequence object belongs to
+	 *	@param	seqName	name of sequence to be dropped
+	 *
+	 */
+	public ConstantAction getDropSequenceConstantAction(SchemaDescriptor sd, String seqName)
+	{
+		return new DropSequenceConstantAction(sd, seqName);
+	}
+
 
-	/**
+    /**
 	 *	Make the ConstantAction for a DROP SCHEMA statement.
 	 *
 	 *	@param	schemaName			Table name.

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java?rev=810151&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceTest.java
Tue Sep  1 18:06:30 2009
@@ -0,0 +1,187 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.SequenceTest
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Test sequences.
+ */
+public class SequenceTest extends BaseJDBCTestCase {
+
+    private static final String TEST_DBO = "TEST_DBO";
+    private static final String ALPHA = "ALPHA";
+    private static final String BETA = "BETA";
+    private static final String[] LEGAL_USERS = {TEST_DBO, ALPHA, BETA};
+
+    public SequenceTest(String name) {
+        super(name);
+        // TODO Auto-generated constructor stub
+    }
+
+    // SETUP
+
+    /**
+     * Construct top level suite in this JUnit test
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite(SequenceTest.class, "Sequence Test");
+        // Need atleast JSR169 to run these tests
+        if (!JDBC.vmSupportsJSR169() && !JDBC.vmSupportsJDBC3()) {
+            return suite;
+        }
+
+        Test cleanTest = new CleanDatabaseTestSetup(suite);
+        Test authenticatedTest = DatabasePropertyTestSetup.builtinAuthentication
+                (cleanTest, LEGAL_USERS, "sequence");
+        Test authorizedTest = TestConfiguration.sqlAuthorizationDecorator(authenticatedTest);
+
+        return authorizedTest;
+    }
+
+    public void testCreateSequence() throws SQLException {
+        Statement s = createStatement();
+        s.executeUpdate("CREATE SEQUENCE mySeq");
+    }
+
+    public void testDropSequence() throws SQLException {
+        Statement s = createStatement();
+        s.executeUpdate("CREATE SEQUENCE mySeq1");
+        s.executeUpdate("DROP SEQUENCE mySeq1");
+    }
+
+    public void testDuplicateCreationFailure() {
+        try {
+            Statement s = createStatement();
+            s.executeUpdate("CREATE SEQUENCE mySeq1");
+            s.executeUpdate("CREATE SEQUENCE mySeq1");
+        } catch (SQLException sqle) {
+            assertSQLState("X0Y68", sqle);
+        }
+    }
+
+    public void testImplicitSchemaCreation() throws SQLException {
+        Connection adminCon = openUserConnection(TEST_DBO);
+
+        Connection alphaCon = openUserConnection(ALPHA);
+        Statement stmt = alphaCon.createStatement();
+
+        // should implicitly create schema ALPHA
+        stmt.executeUpdate("CREATE SEQUENCE alpha_seq");
+        stmt.executeUpdate("DROP SEQUENCE alpha_seq");
+        stmt.close();
+        alphaCon.close();
+        adminCon.close();
+    }
+
+    public void testCreateWithSchemaSpecified() throws SQLException {
+
+        // create DB
+        Connection alphaCon = openUserConnection(ALPHA);
+        Statement stmt = alphaCon.createStatement();
+
+        // should implicitly create schema ALPHA
+        stmt.executeUpdate("CREATE SEQUENCE alpha.alpha_seq");
+        stmt.executeUpdate("DROP SEQUENCE alpha.alpha_seq");
+        stmt.close();
+        alphaCon.close();
+    }
+
+    public void testCreateWithSchemaSpecifiedCreateTrue() throws SQLException {
+        Connection alphaCon = openUserConnection(ALPHA);
+        Statement stmt = alphaCon.createStatement();
+
+        // should implicitly create schema ALPHA
+        stmt.executeUpdate("CREATE SEQUENCE alpha.alpha_seq");
+        stmt.executeUpdate("DROP SEQUENCE alpha.alpha_seq");
+        stmt.close();
+        alphaCon.close();
+    }
+
+    public void testCreateWithSchemaDropWithNoSchema() throws SQLException {
+        Connection alphaCon = openUserConnection(ALPHA);
+        Statement stmt = alphaCon.createStatement();
+
+        // should implicitly create schema ALPHA
+        stmt.executeUpdate("CREATE SEQUENCE alpha.alpha_seq");
+        stmt.executeUpdate("DROP SEQUENCE alpha_seq");
+        stmt.close();
+        alphaCon.close();
+    }
+
+    /**
+     * Test trying to drop a sequence in a schema that doesn't belong to one
+     */
+    public void testDropOtherSchemaSequence() throws SQLException {
+        Connection adminCon = openUserConnection(TEST_DBO);
+
+        Connection alphaCon = openUserConnection(ALPHA);
+        Statement stmtAlpha = alphaCon.createStatement();
+        stmtAlpha.executeUpdate("CREATE SEQUENCE alpha_seq");
+
+        Connection betaCon = openUserConnection(BETA);
+        Statement stmtBeta = betaCon.createStatement();
+
+        // should implicitly create schema ALPHA
+        assertStatementError("42507", stmtBeta, "DROP SEQUENCE alpha.alpha_seq");
+
+        stmtAlpha.close();
+        stmtBeta.close();
+        alphaCon.close();
+        betaCon.close();
+        adminCon.close();
+    }
+
+    /**
+     * Test trying to create a sequence in a schema that doesn't belong to one
+     */
+    public void testCreateOtherSchemaSequence() throws SQLException {
+        // create DB
+        Connection adminCon = openUserConnection(TEST_DBO);
+
+        Connection alphaCon = openUserConnection(ALPHA);
+        Statement stmtAlpha = alphaCon.createStatement();
+
+        Connection betaCon = openUserConnection(BETA);
+        Statement stmtBeta = betaCon.createStatement();
+
+        // should implicitly create schema ALPHA
+        assertStatementError("42507", stmtBeta, "CREATE SEQUENCE alpha.alpha_seq3");
+
+        stmtAlpha.close();
+        stmtBeta.close();
+        alphaCon.close();
+        betaCon.close();
+        adminCon.close();
+    }
+
+}

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=810151&r1=810150&r2=810151&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Tue Sep  1 18:06:30 2009
@@ -197,6 +197,7 @@
         suite.addTest(AlterColumnTest.suite());
         suite.addTest(UserLobTest.suite());
         suite.addTest(OffsetFetchNextTest.suite());
+        suite.addTest(SequenceTest.suite());
 
         return suite;
 	}

Modified: db/derby/code/trunk/tools/jar/DBMSnodes.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/tools/jar/DBMSnodes.properties?rev=810151&r1=810150&r2=810151&view=diff
==============================================================================
--- db/derby/code/trunk/tools/jar/DBMSnodes.properties (original)
+++ db/derby/code/trunk/tools/jar/DBMSnodes.properties Tue Sep  1 18:06:30 2009
@@ -143,6 +143,8 @@
 derby.module.cloudscapenodes.gt=org.apache.derby.impl.sql.compile.RowNumberColumnNode
 derby.module.cloudscapenodes.gu=org.apache.derby.impl.sql.compile.WindowNode
 derby.module.cloudscapenodes.gv=org.apache.derby.impl.sql.compile.RowCountNode
+derby.module.cloudscapenodes.gw=org.apache.derby.impl.sql.compile.CreateSequenceNode
+derby.module.cloudscapenodes.gx=org.apache.derby.impl.sql.compile.DropSequenceNode
 
 # Warning: make sure this file is properly terminated with a newline,
 # else the build can fail silently. Symptom: derby.jar lacks many



Mime
View raw message