KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.SavepointConstantAction
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.sql.conn.LanguageConnectionContext;
27
28 import org.apache.derby.iapi.sql.Activation;
29
30 import org.apache.derby.iapi.error.StandardException;
31
32 import org.apache.derby.iapi.sql.conn.StatementContext;
33 import org.apache.derby.iapi.reference.SQLState;
34
35 /**
36  * This class describes actions that are ALWAYS performed for a
37  * Savepoint (rollback, release and set savepoint) Statement at Execution time.
38  */

39
40 class SavepointConstantAction extends DDLConstantAction
41 {
42
43     private final String JavaDoc savepointName; //name of the savepoint
44
private final int savepointStatementType; //Type of savepoint statement ie rollback, release or set savepoint
45

46     /**
47      * Make the ConstantAction for a set savepoint, rollback or release statement.
48      *
49      * @param savepointName Name of the savepoint.
50      * @param savepointStatementType set savepoint, rollback savepoint or release savepoint
51      */

52     SavepointConstantAction(
53                                 String JavaDoc savepointName,
54                                 int savepointStatementType)
55     {
56         this.savepointName = savepointName;
57         this.savepointStatementType = savepointStatementType;
58     }
59
60     // OBJECT METHODS
61
public String JavaDoc toString()
62     {
63         if (savepointStatementType == 1)
64             return constructToString("SAVEPOINT ", savepointName + " ON ROLLBACK RETAIN CURSORS ON ROLLBACK RETAIN LOCKS");
65         else if (savepointStatementType == 2)
66             return constructToString("ROLLBACK WORK TO SAVEPOINT ", savepointName);
67         else
68             return constructToString("RELEASE TO SAVEPOINT ", savepointName);
69     }
70
71     // INTERFACE METHODS
72

73
74     /**
75      * This is the guts of the Execution-time logic for CREATE TABLE.
76      *
77      * @see ConstantAction#executeConstantAction
78      *
79      * @exception StandardException Thrown on failure
80      */

81     public void executeConstantAction( Activation activation )
82         throws StandardException
83     {
84         LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
85
86             //Bug 4507 - savepoint not allowed inside trigger
87
StatementContext stmtCtxt = lcc.getStatementContext();
88             if (stmtCtxt!= null && stmtCtxt.inTrigger())
89                 throw StandardException.newException(SQLState.NO_SAVEPOINT_IN_TRIGGER);
90
91         if (savepointStatementType == 1) { //this is set savepoint
92
if (savepointName.startsWith("SYS")) //to enforce DB2 restriction which is savepoint name can't start with SYS
93
throw StandardException.newException(SQLState.INVALID_SCHEMA_SYS, "SYS");
94             lcc.languageSetSavePoint(savepointName, savepointName);
95         } else if (savepointStatementType == 2) { //this is rollback savepoint
96
lcc.internalRollbackToSavepoint(savepointName,true, savepointName);
97         } else { //this is release savepoint
98
lcc.releaseSavePoint(savepointName, savepointName);
99         }
100     }
101
102 }
103
Popular Tags