KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > containers > PMTransactionImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.ejb.containers;
25
26 import java.util.*;
27 import javax.transaction.*;
28 import javax.transaction.xa.*;
29 import com.sun.enterprise.*;
30
31
32 /**
33  * A "wrapper" implementation of javax.transaction.Transaction
34  * used by the container to communicate with the PersistenceManager.
35  * The PM can only call getStatus, registerSynchronization, setRollbackOnly
36  * methods. The Synchronization objects registered by the PM must be
37  * called AFTER the Synchronization objects registered by the container,
38  * to ensure that all ejbStores are called before the PM flushes state to
39  * the database.
40  *
41  */

42
43 public class PMTransactionImpl implements Transaction {
44
45     private Transaction tx;
46
47     PMTransactionImpl(Transaction tx)
48     {
49     this.tx = tx;
50     }
51     
52     public int getStatus() throws SystemException {
53     return tx.getStatus();
54     }
55
56    
57     public void registerSynchronization(Synchronization pmsync)
58         throws RollbackException, IllegalStateException JavaDoc,
59         SystemException {
60
61     // to make sure ejbStores are called before pmsync.beforeCompletion
62
Switch theSwitch = Switch.getSwitch();
63     ContainerFactoryImpl cf = (ContainerFactoryImpl)theSwitch.getContainerFactory();
64     cf.getContainerSync(tx).addPMSynchronization(pmsync);
65     }
66
67
68     public void setRollbackOnly()
69         throws IllegalStateException JavaDoc, SystemException {
70
71     tx.setRollbackOnly();
72     }
73
74     public boolean equals(Object JavaDoc object) {
75         if (object == this)
76             return true;
77         else if ( !(object instanceof PMTransactionImpl) )
78             return false;
79         else
80             return tx.equals(((PMTransactionImpl)object).tx);
81     }
82
83     public int hashCode() {
84         return tx.hashCode();
85     }
86  
87
88     public void commit() throws RollbackException,
89     HeuristicMixedException, HeuristicRollbackException,
90         SecurityException JavaDoc, SystemException
91     {
92         throw new IllegalStateException JavaDoc("Operation not allowed");
93     }
94
95
96     public void rollback()
97         throws IllegalStateException JavaDoc, SystemException {
98         
99         throw new IllegalStateException JavaDoc("Operation not allowed");
100     }
101
102     public boolean enlistResource(XAResource res)
103         throws RollbackException, IllegalStateException JavaDoc,
104             SystemException {
105
106         throw new IllegalStateException JavaDoc("Operation not allowed");
107     }
108
109     public boolean delistResource(XAResource res, int flags)
110         throws IllegalStateException JavaDoc, SystemException {
111
112         throw new IllegalStateException JavaDoc("Operation not allowed");
113     }
114
115
116 }
117
Popular Tags