001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.SavepointNode
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.compile;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025:
026: import org.apache.derby.iapi.sql.execute.ConstantAction;
027:
028: import org.apache.derby.iapi.error.StandardException;
029:
030: /**
031: * A SavepointNode is the root of a QueryTree that represents a Savepoint (ROLLBACK savepoint, RELASE savepoint and SAVEPOINT)
032: * statement.
033: */
034:
035: public class SavepointNode extends DDLStatementNode {
036: private String savepointName; //name of the savepoint
037: private int savepointStatementType; //Type of savepoint statement ie rollback, release or set savepoint
038:
039: /**
040: * Initializer for a SavepointNode
041: *
042: * @param objectName The name of the savepoint
043: * @param savepointStatementType Type of savepoint statement ie rollback, release or set savepoint
044: *
045: * @exception StandardException Thrown on error
046: */
047:
048: public void init(Object objectName, Object savepointStatementType)
049: throws StandardException {
050: initAndCheck(null);
051: this .savepointName = (String) objectName;
052: this .savepointStatementType = ((Integer) savepointStatementType)
053: .intValue();
054:
055: if (SanityManager.DEBUG) {
056: if (this .savepointStatementType > 3
057: || this .savepointStatementType < 1) {
058: SanityManager
059: .THROWASSERT("Unexpected value for savepointStatementType = "
060: + this .savepointStatementType
061: + ". Expected value between 1-3");
062: }
063: }
064: }
065:
066: /**
067: * Convert this object to a String. See comments in QueryTreeNode.java
068: * for how this should be done for tree printing.
069: *
070: * @return This object as a String
071: */
072:
073: public String toString() {
074: if (SanityManager.DEBUG) {
075: String tempString = "savepointName: " + "\n"
076: + savepointName + "\n";
077: tempString = tempString + "savepointStatementType: " + "\n"
078: + savepointStatementType + "\n";
079: return super .toString() + tempString;
080: } else {
081: return "";
082: }
083: }
084:
085: public String statementToString() {
086: if (savepointStatementType == 1)
087: return "SAVEPOINT";
088: else if (savepointStatementType == 2)
089: return "ROLLBACK WORK TO SAVEPOINT";
090: else
091: return "RELEASE TO SAVEPOINT";
092: }
093:
094: /**
095: * Returns whether or not this Statement requires a set/clear savepoint
096: * around its execution. The following statement "types" do not require them:
097: * Cursor - unnecessary and won't work in a read only environment
098: * Xact - savepoint will get blown away underneath us during commit/rollback
099: *
100: * @return boolean Whether or not this Statement requires a set/clear savepoint
101: */
102: public boolean needsSavepoint() {
103: return false;
104: }
105:
106: // We inherit the generate() method from DDLStatementNode.
107:
108: /**
109: * Create the Constant information that will drive the guts of Execution.
110: *
111: * @exception StandardException Thrown on failure
112: */
113: public ConstantAction makeConstantAction() throws StandardException {
114: return (getGenericConstantActionFactory()
115: .getSavepointConstantAction(savepointName,
116: savepointStatementType));
117: }
118: }
|