001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb.jdbc;
032:
033: import java.sql.SQLException;
034: import java.sql.Savepoint;
035:
036: import org.hsqldb.Trace;
037:
038: /**
039: * The representation of a savepoint, which is a point within
040: * the current transaction that can be referenced from the
041: * <code>Connection.rollback</code> method. When a transaction
042: * is rolled back to a savepoint all changes made after that
043: * savepoint are undone.
044: * <p>
045: * Savepoints can be either named or unnamed. Unnamed
046: * savepoints
047: * are identified by an ID generated by the underlying
048: * data source.
049: *
050: *
051: * <!-- start Release-specific documentation -->
052: * <div class="ReleaseSpecificDocumentation">
053: * <h3>HSQLDB-Specific Information:</h3> <p>
054: *
055: * As the SQL 2003 standard does not provide for unnamed savepoints,
056: * this feature is not supported.<p>
057: *
058: * If the connection is autoCommit, setting savepoints has no effect as any
059: * such savepoint is cleared upon the execution of the first transactional
060: * statement. <p>
061:
062: * </div>
063: * <!-- end release-specific documentation -->
064: *
065: *
066: * @author boucherb@users
067: * @since JDK 1.4, HSQLDB 1.7.2
068: */
069: public class jdbcSavepoint implements Savepoint {
070:
071: String name;
072: jdbcConnection connection;
073:
074: jdbcSavepoint(String name, jdbcConnection conn) throws SQLException {
075:
076: if (name == null) {
077: throw Util.sqlException(Trace.INVALID_JDBC_ARGUMENT,
078: "name is null");
079: }
080:
081: this .name = name;
082: connection = conn;
083: }
084:
085: /**
086: * Retrieves the generated ID for the savepoint
087: * that this <code>Savepoint</code> object represents.
088: * @return the numeric ID of this savepoint
089: * @exception SQLException if this is a named
090: * savepoint
091: * @since 1.4
092: */
093: public int getSavepointId() throws SQLException {
094: throw Util.notSupported();
095: }
096:
097: /**
098: * Retrieves the name of the savepoint that this
099: * <code>Savepoint</code> object represents. <p>
100: *
101: * @return the name of this savepoint
102: * @exception SQLException if this is an un-named
103: * savepoint
104: * @since 1.4
105: */
106: public String getSavepointName() throws SQLException {
107: return name;
108: }
109:
110: public String toString() {
111: return super .toString() + "[name=" + name + "]";
112: }
113: }
|