KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > SavepointNode


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.SavepointNode
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.compile;
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.error.StandardException;
29
30 /**
31  * A SavepointNode is the root of a QueryTree that represents a Savepoint (ROLLBACK savepoint, RELASE savepoint and SAVEPOINT)
32  * statement.
33  */

34
35 public class SavepointNode extends DDLStatementNode
36 {
37     private String JavaDoc savepointName; //name of the savepoint
38
private int savepointStatementType; //Type of savepoint statement ie rollback, release or set savepoint
39

40     /**
41      * Initializer for a SavepointNode
42      *
43      * @param objectName The name of the savepoint
44      * @param savepointStatementType Type of savepoint statement ie rollback, release or set savepoint
45      *
46      * @exception StandardException Thrown on error
47      */

48
49     public void init(
50             Object JavaDoc objectName,
51             Object JavaDoc savepointStatementType)
52         throws StandardException
53     {
54         initAndCheck(null);
55         this.savepointName = (String JavaDoc) objectName;
56         this.savepointStatementType = ((Integer JavaDoc) savepointStatementType).intValue();
57
58         if (SanityManager.DEBUG)
59         {
60             if (this.savepointStatementType > 3 || this.savepointStatementType < 1)
61             {
62                 SanityManager.THROWASSERT(
63                 "Unexpected value for savepointStatementType = " + this.savepointStatementType + ". Expected value between 1-3");
64             }
65         }
66     }
67
68     /**
69      * Convert this object to a String. See comments in QueryTreeNode.java
70      * for how this should be done for tree printing.
71      *
72      * @return This object as a String
73      */

74
75     public String JavaDoc toString()
76     {
77         if (SanityManager.DEBUG)
78         {
79             String JavaDoc tempString = "savepointName: " + "\n" + savepointName + "\n";
80             tempString = tempString + "savepointStatementType: " + "\n" + savepointStatementType + "\n";
81             return super.toString() + tempString;
82         }
83         else
84         {
85             return "";
86         }
87     }
88
89     public String JavaDoc statementToString()
90     {
91         if (savepointStatementType == 1)
92             return "SAVEPOINT";
93         else if (savepointStatementType == 2)
94             return "ROLLBACK WORK TO SAVEPOINT";
95         else
96             return "RELEASE TO SAVEPOINT";
97     }
98
99     /**
100      * Returns whether or not this Statement requires a set/clear savepoint
101      * around its execution. The following statement "types" do not require them:
102      * Cursor - unnecessary and won't work in a read only environment
103      * Xact - savepoint will get blown away underneath us during commit/rollback
104      *
105      * @return boolean Whether or not this Statement requires a set/clear savepoint
106      */

107     public boolean needsSavepoint()
108     {
109         return false;
110     }
111
112     // We inherit the generate() method from DDLStatementNode.
113

114     /**
115      * Create the Constant information that will drive the guts of Execution.
116      *
117      * @exception StandardException Thrown on failure
118      */

119     public ConstantAction makeConstantAction() throws StandardException
120     {
121         return(
122             getGenericConstantActionFactory().getSavepointConstantAction(
123                 savepointName,
124                 savepointStatementType));
125     }
126 }
127
Popular Tags