KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.LockTableConstantAction
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.services.sanity.SanityManager;
25
26 import org.apache.derby.iapi.sql.execute.ConstantAction;
27
28 import org.apache.derby.iapi.reference.SQLState;
29
30 import org.apache.derby.iapi.sql.Activation;
31
32 import org.apache.derby.iapi.error.StandardException;
33
34 import org.apache.derby.iapi.store.access.ConglomerateController;
35 import org.apache.derby.iapi.store.access.TransactionController;
36
37 import org.apache.derby.catalog.UUID;
38
39
40 /**
41  * This class describes actions that are ALWAYS performed for a
42  * LOCK TABLE Statement at Execution time.
43  *
44  * @author jamie
45  */

46
47 class LockTableConstantAction extends GenericConstantAction
48 {
49
50     private final String JavaDoc fullTableName;
51     private final long conglomerateNumber;
52     private final boolean exclusiveMode;
53     
54     // CONSTRUCTORS
55

56     /**
57      * Make the ConstantAction for a LOCK TABLE statement.
58      *
59      * @param fullTableName Full name of the table.
60      * @param conglomerateNumber Conglomerate number for the heap
61      * @param exclusiveMode Whether or not to get an exclusive lock.
62      */

63     LockTableConstantAction(String JavaDoc fullTableName,
64                                     long conglomerateNumber, boolean exclusiveMode)
65     {
66         this.fullTableName = fullTableName;
67         this.conglomerateNumber = conglomerateNumber;
68         this.exclusiveMode = exclusiveMode;
69     }
70
71     // OBJECT METHODS
72

73     public String JavaDoc toString()
74     {
75         // Do not put this under SanityManager.DEBUG - it is needed for
76
// error reporting.
77
return "LOCK TABLE " + fullTableName;
78     }
79
80     // INTERFACE METHODS
81

82
83     /**
84      * This is the guts of the Execution-time logic for LOCK TABLE.
85      *
86      * @see ConstantAction#executeConstantAction
87      *
88      * @exception StandardException Thrown on failure
89      */

90     public void executeConstantAction( Activation activation )
91                         throws StandardException
92     {
93         ConglomerateController cc;
94         TransactionController tc;
95
96         /* Get a ConglomerateController for the base conglomerate */
97         tc = activation.getTransactionController();
98
99         try
100         {
101             cc = tc.openConglomerate(
102                     conglomerateNumber,
103                     false,
104                     (exclusiveMode) ?
105                         (TransactionController.OPENMODE_FORUPDATE |
106                             TransactionController.OPENMODE_FOR_LOCK_ONLY) :
107                         TransactionController.OPENMODE_FOR_LOCK_ONLY,
108                     TransactionController.MODE_TABLE,
109                     TransactionController.ISOLATION_SERIALIZABLE);
110             cc.close();
111         }
112         catch (StandardException se)
113         {
114             String JavaDoc msgId = se.getMessageId();
115             if (msgId.equals(SQLState.DEADLOCK) || msgId.equals(SQLState.LOCK_TIMEOUT) || msgId.equals(SQLState.LOCK_TIMEOUT_LOG)) {
116                 String JavaDoc mode = (exclusiveMode) ? "EXCLUSIVE" : "SHARE";
117                 se = StandardException.newException(SQLState.LANG_CANT_LOCK_TABLE, se, fullTableName, mode);
118             }
119
120             throw se;
121         }
122     }
123 }
124
Popular Tags