01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.enterprise.spi.j2eeimpl;
16:
17: import javax.naming.InitialContext;
18: import javax.transaction.SystemException;
19: import javax.transaction.TransactionManager;
20: import javax.transaction.UserTransaction;
21:
22: import com.metaboss.enterprise.spi.JTAImplementationProvider;
23: import com.metaboss.enterprise.transaction.ExtendedTransactionStatus;
24:
25: /** Interface to the JDBC connection provider */
26: public class JTAImplementationProviderImpl implements
27: JTAImplementationProvider {
28: /** Method used to obtain JTA's user transaction */
29: public UserTransaction getUserTransaction() throws SystemException {
30: try {
31: InitialContext lContext = new InitialContext();
32: return (javax.transaction.UserTransaction) lContext
33: .lookup("UserTransaction");
34: } catch (javax.naming.NamingException e) {
35: throw new javax.transaction.SystemException(
36: "Unable to locate UserTransaction");
37: }
38: }
39:
40: /** Method used to obtain JTA's transaction manager */
41: public TransactionManager getTransactionManager()
42: throws SystemException {
43: try {
44: InitialContext lContext = new InitialContext();
45: return (TransactionManager) lContext
46: .lookup("java:/TransactionManager");
47: } catch (javax.naming.NamingException e) {
48: throw new javax.transaction.SystemException(
49: "Unable to locate TransactionManager");
50: }
51: }
52:
53: /** Returns ExtendedTransactionStatus associated with current transaction */
54: public ExtendedTransactionStatus getExtendedTransactionStatus()
55: throws SystemException {
56: return new ExtendedTransactionStatus() {
57: // Saves rollback cause. Can only be called once after transaction status is already set to rollback only.
58: public void setRollbackCause(Throwable pCause)
59: throws javax.transaction.SystemException,
60: javax.transaction.NotSupportedException,
61: java.lang.IllegalStateException {
62: throw new javax.transaction.NotSupportedException(
63: "TODO: Implement support the rollback cause on J2EE");
64: }
65:
66: // Retrieves rollback cause. Can be called at any time, but may return null meaning that
67: // cause has not been stored. The reasons may be that transaction has not been rolled back,
68: // no one has actually stored the cause etc..
69: public Throwable getRollbackCause()
70: throws javax.transaction.SystemException,
71: javax.transaction.NotSupportedException,
72: java.lang.IllegalStateException {
73: throw new javax.transaction.NotSupportedException(
74: "TODO: Implement support the rollback cause on J2EE");
75: }
76: };
77: }
78: }
|