KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > gjc > spi > LocalTransaction


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.gjc.spi;
25
26 import com.sun.gjc.spi.ManagedConnection;
27 import javax.resource.ResourceException JavaDoc;
28 import javax.resource.spi.LocalTransactionException JavaDoc;
29
30 /**
31  * <code>LocalTransaction</code> implementation for Generic JDBC Connector.
32  *
33  * @version 1.0, 02/08/03
34  * @author Evani Sai Surya Kiran
35  */

36 public class LocalTransaction implements javax.resource.spi.LocalTransaction JavaDoc {
37     
38     private ManagedConnection mc;
39     
40     /**
41      * Constructor for <code>LocalTransaction</code>.
42      * @param mc <code>ManagedConnection</code> that returns
43      * this <code>LocalTransaction</code> object as
44      * a result of <code>getLocalTransaction</code>
45      */

46     public LocalTransaction(ManagedConnection mc) {
47         this.mc = mc;
48     }
49     
50     /**
51      * Begin a local transaction.
52      *
53      * @throws LocalTransactionException if there is an error in changing
54      * the autocommit mode of the physical
55      * connection
56      */

57     public void begin() throws ResourceException JavaDoc {
58         //GJCINT
59
mc.transactionStarted();
60         try {
61             mc.getActualConnection().setAutoCommit(false);
62         } catch(java.sql.SQLException JavaDoc sqle) {
63             throw new LocalTransactionException JavaDoc(sqle.getMessage());
64         }
65     }
66     
67     /**
68      * Commit a local transaction.
69      * @throws LocalTransactionException if there is an error in changing
70      * the autocommit mode of the physical
71      * connection or committing the transaction
72      */

73     public void commit() throws ResourceException JavaDoc {
74         Exception JavaDoc e = null;
75         try {
76             mc.getActualConnection().commit();
77             mc.getActualConnection().setAutoCommit(true);
78         } catch(java.sql.SQLException JavaDoc sqle) {
79             throw new LocalTransactionException JavaDoc(sqle.getMessage());
80         }
81         //GJCINT
82
mc.transactionCompleted();
83     }
84     
85     /**
86      * Rollback a local transaction.
87      *
88      * @throws LocalTransactionException if there is an error in changing
89      * the autocommit mode of the physical
90      * connection or rolling back the transaction
91      */

92     public void rollback() throws ResourceException JavaDoc {
93         try {
94             mc.getActualConnection().rollback();
95             mc.getActualConnection().setAutoCommit(true);
96         } catch(java.sql.SQLException JavaDoc sqle) {
97             throw new LocalTransactionException JavaDoc(sqle.getMessage());
98         }
99         //GJCINT
100
mc.transactionCompleted();
101     }
102     
103 }
104
Popular Tags