Here is patched ConnectionImpl to make jonas 1.5 works
with Sybase ASE.
I am too lazy to use preprocessor, so I comment out
part for jdk1.2 :)
I only add two commit calls, may be only one of them really needed ;)
/*
* The contents of this file are subject to the JOnAS Public License
Version
* 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License on the JOnAS web site.
*
* Software distributed under the License is distributed on an "AS IS"
basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific terms governing rights and
limitations under
* the License.
*
* The Original Code is JOnAS application server code released July
1999.
*
* The Initial Developer of the Original Code is Bull S.A.
* The Original Code and portions created by Bull S.A. are
* Copyright (C) 1999 Bull S.A. All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
*
--------------------------------------------------------------------------
* $Id: ConnectionImpl.jpp,v 1.1.1.1 1999/10/28 14:07:09 bassetre Exp $
*
--------------------------------------------------------------------------
*/
package org.objectweb.jonas.jdbc_xa;
import java.sql.*;
//#ifdef JAVA2
//import java.util.Map;
//#endif
import org.objectweb.jonas.common.Trace;
/**
* This class is a wrapper class on a standard java.sql.Connection
class.
* Its goal is to prevent explicit close of a connection and transaction
* management (should be done via XAResource)
*/
public class ConnectionImpl implements Connection {
private static final int trace = Trace.DB_10;
private Connection actConn = null;
private XAConnectionImpl xac = null;
private boolean autocommit_set = false;
private boolean autocommit_unset = false;
// -----------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------
/**
* Constructor used by XAConnection object
*
* @param actual The actual open connection on database
*/
public ConnectionImpl(XAConnectionImpl xac, Connection actual) {
Trace.outln(trace,
"ConnectionImpl.ConnectionImpl(XAConnectionImpl xac, Connection
actual)");
this.xac = xac;
this.actConn = actual;
}
// -----------------------------------------------------------------
// Accessors
// -----------------------------------------------------------------
/**
* Get the actual connection on database
*/
public Connection getConnection() {
Trace.outln(trace, "ConnectionImpl.getConnection()");
return actConn;
}
// -----------------------------------------------------------------
// Connection implementation
// Most of the methods just forward the call to the actual
connection.
// -----------------------------------------------------------------
public Statement createStatement() throws SQLException {
Trace.outln(trace, "ConnectionImpl.createStatement()");
try {
return actConn.createStatement();
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public PreparedStatement prepareStatement(String sql) throws
SQLException {
Trace.outln(trace, "ConnectionImpl.prepareStatement(String
"+sql+")");
try {
return actConn.prepareStatement(sql);
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public CallableStatement prepareCall(String sql) throws SQLException
{
Trace.outln(trace, "ConnectionImpl.prepareCall(String
"+sql+")");
try {
return actConn.prepareCall(sql);
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public String nativeSQL(String sql) throws SQLException {
Trace.outln(trace, "ConnectionImpl.nativeSQL(String "+sql+")");
try {
return actConn.nativeSQL(sql);
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public boolean isClosed() throws SQLException {
Trace.outln(trace, "ConnectionImpl.isClosed()");
try {
return actConn.isClosed();
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public DatabaseMetaData getMetaData() throws SQLException {
Trace.outln(trace, "ConnectionImpl.getMetaData()");
try {
return actConn.getMetaData();
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public void setReadOnly(boolean readOnly) throws SQLException {
Trace.outln(trace, "ConnectionImpl.setReadOnly(boolean
"+readOnly+")");
try {
actConn.setReadOnly(readOnly);
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public boolean isReadOnly() throws SQLException {
Trace.outln(trace, "ConnectionImpl.isReadOnly()");
try {
return actConn.isReadOnly();
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public void setCatalog(String catalog) throws SQLException {
Trace.outln(trace, "ConnectionImpl.setCatalog(String
"+catalog+")");
try {
actConn.setCatalog(catalog);
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public String getCatalog() throws SQLException {
Trace.outln(trace, "ConnectionImpl.getCatalog()");
try {
return actConn.getCatalog();
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
/**
* Trigger an event to the listener.
*/
public void close() throws SQLException {
Trace.outln(trace, "ConnectionImpl.close()");
xac.notifyClose();
}
public void setTransactionIsolation(int level) throws SQLException {
Trace.outln(trace, "ConnectionImpl.setTransactionIsolation(int
"+level+")");
try {
actConn.setTransactionIsolation(level);
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public int getTransactionIsolation() throws SQLException {
Trace.outln(trace, "ConnectionImpl.getTransactionIsolation()");
try {
return actConn.getTransactionIsolation();
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public SQLWarning getWarnings() throws SQLException {
Trace.outln(trace, "ConnectionImpl.getWarnings()");
try {
return actConn.getWarnings();
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
public void clearWarnings() throws SQLException {
Trace.outln(trace, "ConnectionImpl.clearWarnings()");
try {
actConn.clearWarnings();
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
/**
* In a JDBC-XA driver, Connection.commit is only called if we
* are outside a global transaction.
*/
public void commit() throws SQLException {
Trace.outln(trace, "ConnectionImpl.commit() - local
transaction");
try {
actConn.commit();
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
/**
* In a JDBC-XA driver, Connection.rollback is only called if we
* are outside a global transaction.
*/
public void rollback() throws SQLException {
Trace.outln(trace, "ConnectionImpl.rollback() - local
transaction");
try {
actConn.rollback();
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
/**
* In a JDBC-XA driver, autocommit is false if we are in a global Tx
*/
public void setAutoCommit(boolean autoCommit) throws SQLException {
Trace.outln(trace, "ConnectionImpl.setAutoCommit(boolean
"+autoCommit+")");
try {
if (autoCommit == false) {
if (autocommit_unset == false) { // cache for
optimization
// for Sybase, we must issue setAutoCommit only if
necessary
if (actConn.getAutoCommit() == true)
{
actConn.commit(); //doing commit for Sybase ASE,
because it don't do it if autocommit state changed
actConn.setAutoCommit(false);
}
autocommit_set = false;
autocommit_unset = true;
}
} else {
if (autocommit_set == false) { // cache for optimization
// for Sybase, we must issue setAutoCommit only if
necessary
if (actConn.getAutoCommit() == false)
{
actConn.commit(); //doing commit for Sybase ASE,
because it don't do it if autocommit state changed
actConn.setAutoCommit(true);
}
autocommit_set = true;
autocommit_unset = false;
}
}
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
/**
* In a JDBC-XA driver, autocommit is false if we are in a global Tx
*/
public boolean getAutoCommit() throws SQLException {
try {
return actConn.getAutoCommit();
} catch (SQLException e) {
xac.notifyError(e);
throw(e);
}
}
//#ifdef JAVA2
// public Statement createStatement(int resultSetType, int
resultSetConcurrency) throws SQLException {
// Trace.outln(trace, "ConnectionImp.createStatement(int
"+resultSetType+",int "+resultSetConcurrency+")");
// try {
// return actConn.createStatement(resultSetType,
resultSetConcurrency);
// } catch (SQLException e) {
// xac.notifyError(e);
// throw(e);
// }
// }
//
// public Map getTypeMap() throws SQLException {
// Trace.outln(trace, "ConnectionImp.getTypeMap()");
// try {
// return actConn.getTypeMap();
// } catch (SQLException e) {
// xac.notifyError(e);
// throw(e);
// }
// }
//
// public void setTypeMap(Map map) throws SQLException {
// Trace.outln(trace, "ConnectionImp.setTypeMap(Map "+map+")");
// try {
// setTypeMap(map);
// } catch (SQLException e) {
// xac.notifyError(e);
// throw(e);
// }
// }
// public PreparedStatement prepareStatement(String sql, int
resultSetType, int resultSetConcurrency) throws SQLException {
// Trace.outln(trace, "ConnectionImpl.prepareStatement(String
"+sql+",int "+resultSetType+", int
"+resultSetConcurrency+")");
//
// try {
// return actConn.prepareStatement(sql, resultSetType,
resultSetConcurrency);
// } catch (SQLException e) {
// xac.notifyError(e);
// throw(e);
// }
// }
//
// public CallableStatement prepareCall(String sql, int
resultSetType, int resultSetConcurrency) throws SQLException {
// Trace.outln(trace, "ConnectionImpl.prepareCall(String "+sql+",
int "+resultSetType+", int "+resultSetConcurrency+")");
//
// try {
// return actConn.prepareCall(sql, resultSetType,
resultSetConcurrency);
// } catch (SQLException e) {
// xac.notifyError(e);
// throw(e);
// }
// }
//#endif
Dmitry Melekhov
http://www.aspec.ru/~dm
2:5050/11.23@fidonet