KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > jdbc > EmbedSavepoint30


1 /*
2
3    Derby - Class org.apache.derby.impl.jdbc.EmbedSavepoint30
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.jdbc;
23
24 import org.apache.derby.impl.jdbc.EmbedConnection;
25 import org.apache.derby.impl.jdbc.ConnectionChild;
26 import org.apache.derby.impl.jdbc.Util;
27
28 import org.apache.derby.iapi.reference.SQLState;
29
30 import org.apache.derby.iapi.error.StandardException;
31
32 import java.sql.Savepoint JavaDoc;
33 import java.sql.SQLException JavaDoc;
34
35 /**
36  * This class implements the Savepoint interface from JDBC3.0
37  * This allows to set, release, or rollback a transaction to
38  * designated Savepoints. Savepoints provide finer-grained
39  * control of transactions by marking intermediate points within
40  * a transaction. Once a savepoint has been set, the transaction
41  * can be rolled back to that savepoint without affecting preceding work.
42    <P><B>Supports</B>
43    <UL>
44    <LI> JSR169 - no subsetting for java.sql.Savepoint
45    <LI> JDBC 3.0 - class introduced in JDBC 3.0
46    </UL>
47  *
48  * @see java.sql.Savepoint
49  *
50  */

51 final class EmbedSavepoint30 extends ConnectionChild
52     implements Savepoint JavaDoc {
53
54     //In order to avoid name conflict, the external names are prepanded
55
//with "e." and internal names always start with "i." This is for bug 4467
56
private final String JavaDoc savepointName;
57     private final int savepointID;
58
59     //////////////////////////////////////////////////////////////
60
//
61
// CONSTRUCTORS
62
//
63
//////////////////////////////////////////////////////////////
64
/*
65         Constructor assumes caller will setup context stack
66         and restore it.
67         @exception SQLException on error
68      */

69     EmbedSavepoint30(EmbedConnection conn, String JavaDoc name)
70     throws StandardException {
71         super(conn);
72         if (name == null) //this is an unnamed savepoint
73
{
74                 //Generating a unique internal name for unnamed savepoints
75
savepointName = "i." + conn.getLanguageConnection().getUniqueSavepointName();
76                 savepointID = conn.getLanguageConnection().getUniqueSavepointID();
77         } else
78         {
79                 savepointName = "e." + name;
80                 savepointID = -1;
81         }
82         conn.getLanguageConnection().languageSetSavePoint(savepointName, this);
83     }
84
85     /**
86     *
87     * Retrieves the generated ID for the savepoint that this Savepoint object
88     * represents.
89     *
90     * @return the numeric ID of this savepoint
91     * @exception SQLException if this is a named savepoint
92     */

93     public int getSavepointId() throws SQLException JavaDoc {
94         if (savepointID == -1)
95             throw newSQLException(SQLState.NO_ID_FOR_NAMED_SAVEPOINT);
96         return savepointID;
97     }
98
99     /**
100     *
101     * Retrieves the name of the savepoint that this Savepoint object
102     * represents.
103     *
104     * @return the name of this savepoint
105     * @exception SQLException if this is an un-named savepoint
106     */

107     public String JavaDoc getSavepointName() throws SQLException JavaDoc {
108         if (savepointID != -1)
109             throw newSQLException(SQLState.NO_NAME_FOR_UNNAMED_SAVEPOINT);
110         return savepointName.substring(2);
111     }
112
113     //Cloudscape internally keeps name for both named and unnamed savepoints
114
String JavaDoc getInternalName() {
115         return savepointName;
116     }
117
118
119     //bug 4468 - verify that savepoint rollback/release is for a savepoint from
120
//the current connection
121
boolean sameConnection(EmbedConnection con) {
122         return (getEmbedConnection().getLanguageConnection() == con.getLanguageConnection());
123     }
124 }
125
126
Popular Tags