All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bitronix.tm.resource.jdbc.lrc.LrcConnectionHandle Maven / Gradle / Ivy

There is a newer version: 2.1.4
Show newest version
package bitronix.tm.resource.jdbc.lrc;

import java.sql.*;

import bitronix.tm.resource.jdbc.BaseProxyHandlerClass;

/**
 * Connection handle implementation for a non-XA JDBC resource emulating XA with Last Resource Commit.
 * 

© Bitronix Software

* * @author lorban, brettw */ public class LrcConnectionHandle extends BaseProxyHandlerClass { // implements Connection private Connection delegate; private LrcXAResource xaResource; public LrcConnectionHandle(LrcXAResource xaResource, Connection delegate) { this.delegate = delegate; this.xaResource = xaResource; } public Connection getConnection() { return delegate; } private Connection getDelegate() throws SQLException { if (delegate == null) throw new SQLException("connection is closed"); return delegate; } /* wrapped Connection methods that have special XA semantics */ public void close() throws SQLException { delegate = null; } public boolean isClosed() throws SQLException { return delegate == null; } public void setAutoCommit(boolean autoCommit) throws SQLException { if (xaResource.getState() != LrcXAResource.NO_TX && autoCommit) throw new SQLException("XA transaction started, cannot enable autocommit mode"); getDelegate().setAutoCommit(autoCommit); } public void commit() throws SQLException { if (xaResource.getState() != LrcXAResource.NO_TX) throw new SQLException("XA transaction started, cannot call commit directly on connection"); getDelegate().commit(); } public void rollback() throws SQLException { if (xaResource.getState() != LrcXAResource.NO_TX) throw new SQLException("XA transaction started, cannot call rollback directly on connection"); getDelegate().rollback(); } public void rollback(Savepoint savepoint) throws SQLException { if (xaResource.getState() != LrcXAResource.NO_TX) throw new SQLException("XA transaction started, cannot call rollback directly on connection"); getDelegate().rollback(savepoint); } public String toString() { return "a JDBC LrcConnectionHandle on " + xaResource; } public Object getProxiedDelegate() throws Exception { return getDelegate(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy