001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.resource.adapter.jdbc.local;
023:
024: import java.sql.Connection;
025: import java.sql.SQLException;
026: import java.util.Properties;
027:
028: import javax.resource.ResourceException;
029: import javax.resource.spi.LocalTransaction;
030: import javax.transaction.xa.XAResource;
031:
032: import org.jboss.resource.JBossResourceException;
033: import org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection;
034:
035: /**
036: * LocalManagedConnection
037: *
038: * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
039: * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
040: * @version $Revision: 57189 $
041: */
042: public class LocalManagedConnection extends
043: BaseWrapperManagedConnection implements LocalTransaction {
044: public LocalManagedConnection(
045: final LocalManagedConnectionFactory mcf,
046: final Connection con, final Properties props,
047: final int transactionIsolation, final int psCacheSize)
048: throws SQLException {
049: super (mcf, con, props, transactionIsolation, psCacheSize);
050: }
051:
052: public LocalTransaction getLocalTransaction()
053: throws ResourceException {
054: return this ;
055: }
056:
057: public XAResource getXAResource() throws ResourceException {
058: throw new JBossResourceException("Local tx only!");
059: }
060:
061: public void commit() throws ResourceException {
062: synchronized (stateLock) {
063: if (inManagedTransaction)
064: inManagedTransaction = false;
065: }
066: try {
067: con.commit();
068: } catch (SQLException e) {
069: checkException(e);
070: }
071: }
072:
073: public void rollback() throws ResourceException {
074: synchronized (stateLock) {
075: if (inManagedTransaction)
076: inManagedTransaction = false;
077: }
078: try {
079: con.rollback();
080: } catch (SQLException e) {
081: try {
082: checkException(e);
083: } catch (Exception e2) {
084: }
085: }
086: }
087:
088: public void begin() throws ResourceException {
089: synchronized (stateLock) {
090: if (inManagedTransaction == false) {
091: try {
092: if (underlyingAutoCommit) {
093: underlyingAutoCommit = false;
094: con.setAutoCommit(false);
095: }
096: checkState();
097: inManagedTransaction = true;
098: } catch (SQLException e) {
099: checkException(e);
100: }
101: } else
102: throw new JBossResourceException(
103: "Trying to begin a nested local tx");
104: }
105: }
106:
107: Properties getProps() {
108: return props;
109: }
110: }
|