001: /*
002: * XAPool: Open Source XA JDBC Pool
003: * Copyright (C) 2003 Objectweb.org
004: * Initial Developer: Lutris Technologies Inc.
005: * Contact: xapool-public@lists.debian-sf.objectweb.org
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or any later version.
011: *
012: * This library 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 library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
020: * USA
021: */
022: package org.enhydra.jdbc.standard;
023:
024: import java.sql.SQLException;
025: import java.sql.CallableStatement;
026: import org.enhydra.jdbc.core.CoreCallableStatement;
027: import javax.transaction.Transaction;
028: import javax.transaction.SystemException;
029: import javax.transaction.RollbackException;
030:
031: public class StandardXACallableStatement extends CoreCallableStatement {
032:
033: private StandardXAConnectionHandle con;
034: // the StandardConnectionHandle that created this object
035: private boolean closed; // true when the Statement has been closed
036: private String sql;
037: private int resultSetType;
038: private int resultSetConcurrency;
039: private int resultSetHoldability;
040:
041: /**
042: * Constructor.
043: */
044: StandardXACallableStatement(StandardXAConnectionHandle con,
045: String sql, int resultSetType, int resultSetConcurrency,
046: int resultSetHoldability) throws SQLException {
047: this .con = con;
048: this .sql = sql;
049: this .resultSetType = resultSetType;
050: this .resultSetConcurrency = resultSetConcurrency;
051: this .resultSetHoldability = resultSetHoldability;
052: log = con.log;
053: //cs = newStatement();
054: }
055:
056: private CallableStatement newStatement() throws SQLException {
057: if (resultSetType == 0 && resultSetConcurrency == 0
058: && resultSetHoldability == 0) {
059: return con.con.prepareCall(sql);
060: } else if (resultSetHoldability == 0) {
061: return con.con.prepareCall(sql, resultSetType,
062: resultSetConcurrency);
063: } else
064: return con.con.prepareCall(sql, resultSetType,
065: resultSetConcurrency, resultSetHoldability);
066:
067: }
068:
069: /**
070: * Close this statement.
071: */
072: public synchronized void close() throws SQLException {
073: super .close(); // we do not reuse the Statement, we have to close it
074: closed = true;
075: }
076:
077: /**
078: * Pre-invokation of the delegation, in case of the Statement is
079: * closed, we throw an exception
080: */
081: public synchronized void preInvoke() throws SQLException {
082: if (closed)
083: throw new SQLException("Prepare Statement is closed");
084:
085: Transaction ntx = null;
086: if (con.tx == null) {
087: try {
088: try {
089: ntx = (con.transactionManager != null) ? con.transactionManager
090: .getTransaction()
091: : null;
092: if (ntx != null) {
093: con.tx = ntx;
094: con.xacon.this AutoCommit = con.getAutoCommit();
095: con.setAutoCommit(false);
096: try {
097: con.tx.enlistResource(con.xacon
098: .getXAResource());
099: // enlist the xaResource in the transaction
100: if (cs != null) {
101: cs.close();
102: cs = null;
103: }
104: } catch (RollbackException n) {
105: throw new SQLException(
106: "StandardXAStatement:preInvoke enlistResource exception: "
107: + n.toString());
108: }
109: }
110: //else con.setAutoCommit(true);
111:
112: } catch (SystemException n) {
113: throw new SQLException(
114: "StandardXAStatement:preInvoke getTransaction exception: "
115: + n.toString());
116: }
117: } catch (NullPointerException n) {
118: // current is null: we are not in EJBServer.
119: throw new SQLException(
120: "StandardXAStatement:preInvoke should not be used outside an EJBServer: "
121: + n.toString());
122: }
123: }
124: if (cs == null) {
125: cs = newStatement();
126: }
127:
128: }
129:
130: /**
131: * Exception management : catch or throw the exception
132: */
133: public void catchInvoke(SQLException sqlException)
134: throws SQLException {
135: //ConnectionEvent event = new ConnectionEvent (con.pooledCon);
136: //con.pooledCon.connectionErrorOccurred(event);
137: throw (sqlException);
138: }
139:
140: }
|