KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > jdbc > local > LocalManagedConnection


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.resource.adapter.jdbc.local;
23
24 import java.sql.Connection JavaDoc;
25 import java.sql.SQLException JavaDoc;
26 import java.util.Properties JavaDoc;
27
28 import javax.resource.ResourceException JavaDoc;
29 import javax.resource.spi.LocalTransaction JavaDoc;
30 import javax.transaction.xa.XAResource JavaDoc;
31
32 import org.jboss.resource.JBossResourceException;
33 import org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection;
34
35 /**
36  * LocalManagedConnection
37  *
38  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
39  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
40  * @version $Revision: 46534 $
41  */

42 public class LocalManagedConnection extends BaseWrapperManagedConnection implements LocalTransaction JavaDoc
43 {
44    public LocalManagedConnection(final LocalManagedConnectionFactory mcf, final Connection JavaDoc con, final Properties JavaDoc props,
45          final int transactionIsolation, final int psCacheSize) throws SQLException JavaDoc
46    {
47       super(mcf, con, props, transactionIsolation, psCacheSize);
48    }
49
50    public LocalTransaction JavaDoc getLocalTransaction() throws ResourceException JavaDoc
51    {
52       return this;
53    }
54
55    public XAResource JavaDoc getXAResource() throws ResourceException JavaDoc
56    {
57       throw new JBossResourceException("Local tx only!");
58    }
59
60    public void commit() throws ResourceException JavaDoc
61    {
62       synchronized (stateLock)
63       {
64          if (inManagedTransaction)
65             inManagedTransaction = false;
66       }
67       try
68       {
69          con.commit();
70       }
71       catch (SQLException JavaDoc e)
72       {
73          checkException(e);
74       }
75    }
76
77    public void rollback() throws ResourceException JavaDoc
78    {
79       synchronized (stateLock)
80       {
81          if (inManagedTransaction)
82             inManagedTransaction = false;
83       }
84       try
85       {
86          con.rollback();
87       }
88       catch (SQLException JavaDoc e)
89       {
90          try
91          {
92             checkException(e);
93          }
94          catch (Exception JavaDoc e2)
95          {
96          }
97       }
98    }
99
100    public void begin() throws ResourceException JavaDoc
101    {
102       synchronized (stateLock)
103       {
104          if (inManagedTransaction == false)
105          {
106             try
107             {
108                if (underlyingAutoCommit)
109                {
110                   underlyingAutoCommit = false;
111                   con.setAutoCommit(false);
112                }
113                checkState();
114                inManagedTransaction = true;
115             }
116             catch (SQLException JavaDoc e)
117             {
118                checkException(e);
119             }
120          }
121          else
122             throw new JBossResourceException("Trying to begin a nested local tx");
123       }
124    }
125
126
127 }
128
Popular Tags