KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > CreateSchemaConstantAction


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.CreateSchemaConstantAction
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.execute;
23
24 import org.apache.derby.iapi.sql.execute.ConstantAction;
25
26 import org.apache.derby.iapi.store.access.TransactionController;
27
28 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
29 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
30 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
31 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
32
33 import org.apache.derby.iapi.reference.SQLState;
34
35 import org.apache.derby.iapi.sql.Activation;
36
37 import org.apache.derby.iapi.error.StandardException;
38
39 import org.apache.derby.iapi.services.sanity.SanityManager;
40
41 import org.apache.derby.catalog.UUID;
42
43 /**
44  * This class describes actions that are ALWAYS performed for a
45  * CREATE SCHEMA Statement at Execution time.
46  *
47  * @author jamie
48  */

49
50 class CreateSchemaConstantAction extends DDLConstantAction
51 {
52
53     private final String JavaDoc aid; // authorization id
54
private final String JavaDoc schemaName;
55     
56
57     // CONSTRUCTORS
58

59     /**
60      * Make the ConstantAction for a CREATE SCHEMA statement.
61      * When executed, will set the default schema to the
62      * new schema if the setToDefault parameter is set to
63      * true.
64      *
65      * @param schemaName Name of table.
66      * @param aid Authorizaton id
67      */

68     CreateSchemaConstantAction(
69                                 String JavaDoc schemaName,
70                                 String JavaDoc aid)
71     {
72         this.schemaName = schemaName;
73         this.aid = aid;
74     }
75
76     ///////////////////////////////////////////////
77
//
78
// OBJECT SHADOWS
79
//
80
///////////////////////////////////////////////
81

82     public String JavaDoc toString()
83     {
84         // Do not put this under SanityManager.DEBUG - it is needed for
85
// error reporting.
86
return "CREATE SCHEMA " + schemaName;
87     }
88
89     // INTERFACE METHODS
90

91
92     /**
93      * This is the guts of the Execution-time logic for CREATE SCHEMA.
94      *
95      * @see ConstantAction#executeConstantAction
96      *
97      * @exception StandardException Thrown on failure
98      */

99     public void executeConstantAction( Activation activation )
100                         throws StandardException
101     {
102         LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
103         DataDictionary dd = lcc.getDataDictionary();
104         TransactionController tc = lcc.getTransactionExecute();
105         DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
106
107         SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, lcc.getTransactionExecute(), false);
108
109         //if the schema descriptor is an in-memory schema, we donot throw schema already exists exception for it.
110
//This is to handle in-memory SESSION schema for temp tables
111
if ((sd != null) && (sd.getUUID() != null))
112         {
113             throw StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS, "Schema" , schemaName);
114         }
115
116         UUID tmpSchemaId = dd.getUUIDFactory().createUUID();
117
118         /*
119         ** AID defaults to connection authorization if not
120         ** specified in CREATE SCHEMA (if we had module
121         ** authorizations, that would be the first check
122         ** for default, then session aid).
123         */

124         String JavaDoc thisAid = aid;
125         if (thisAid == null)
126         {
127             thisAid = lcc.getAuthorizationId();
128         }
129
130         /*
131         ** Inform the data dictionary that we are about to write to it.
132         ** There are several calls to data dictionary "get" methods here
133         ** that might be done in "read" mode in the data dictionary, but
134         ** it seemed safer to do this whole operation in "write" mode.
135         **
136         ** We tell the data dictionary we're done writing at the end of
137         ** the transaction.
138         */

139         dd.startWriting(lcc);
140
141         sd = ddg.newSchemaDescriptor(schemaName,
142                                     thisAid,
143                                     tmpSchemaId);
144
145         dd.addDescriptor(sd, null, DataDictionary.SYSSCHEMAS_CATALOG_NUM, false, tc);
146     }
147 }
148
Popular Tags