001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.SavepointConstantAction
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.execute;
023:
024: import org.apache.derby.iapi.sql.execute.ConstantAction;
025:
026: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
027:
028: import org.apache.derby.iapi.sql.Activation;
029:
030: import org.apache.derby.iapi.error.StandardException;
031:
032: import org.apache.derby.iapi.sql.conn.StatementContext;
033: import org.apache.derby.iapi.reference.SQLState;
034:
035: /**
036: * This class describes actions that are ALWAYS performed for a
037: * Savepoint (rollback, release and set savepoint) Statement at Execution time.
038: */
039:
040: class SavepointConstantAction extends DDLConstantAction {
041:
042: private final String savepointName; //name of the savepoint
043: private final int savepointStatementType; //Type of savepoint statement ie rollback, release or set savepoint
044:
045: /**
046: * Make the ConstantAction for a set savepoint, rollback or release statement.
047: *
048: * @param savepointName Name of the savepoint.
049: * @param savepointStatementType set savepoint, rollback savepoint or release savepoint
050: */
051: SavepointConstantAction(String savepointName,
052: int savepointStatementType) {
053: this .savepointName = savepointName;
054: this .savepointStatementType = savepointStatementType;
055: }
056:
057: // OBJECT METHODS
058: public String toString() {
059: if (savepointStatementType == 1)
060: return constructToString(
061: "SAVEPOINT ",
062: savepointName
063: + " ON ROLLBACK RETAIN CURSORS ON ROLLBACK RETAIN LOCKS");
064: else if (savepointStatementType == 2)
065: return constructToString("ROLLBACK WORK TO SAVEPOINT ",
066: savepointName);
067: else
068: return constructToString("RELEASE TO SAVEPOINT ",
069: savepointName);
070: }
071:
072: // INTERFACE METHODS
073:
074: /**
075: * This is the guts of the Execution-time logic for CREATE TABLE.
076: *
077: * @see ConstantAction#executeConstantAction
078: *
079: * @exception StandardException Thrown on failure
080: */
081: public void executeConstantAction(Activation activation)
082: throws StandardException {
083: LanguageConnectionContext lcc = activation
084: .getLanguageConnectionContext();
085:
086: //Bug 4507 - savepoint not allowed inside trigger
087: StatementContext stmtCtxt = lcc.getStatementContext();
088: if (stmtCtxt != null && stmtCtxt.inTrigger())
089: throw StandardException
090: .newException(SQLState.NO_SAVEPOINT_IN_TRIGGER);
091:
092: if (savepointStatementType == 1) { //this is set savepoint
093: if (savepointName.startsWith("SYS")) //to enforce DB2 restriction which is savepoint name can't start with SYS
094: throw StandardException.newException(
095: SQLState.INVALID_SCHEMA_SYS, "SYS");
096: lcc.languageSetSavePoint(savepointName, savepointName);
097: } else if (savepointStatementType == 2) { //this is rollback savepoint
098: lcc.internalRollbackToSavepoint(savepointName, true,
099: savepointName);
100: } else { //this is release savepoint
101: lcc.releaseSavePoint(savepointName, savepointName);
102: }
103: }
104:
105: }
|