KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > TxEntityMap


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb;
23
24 import java.util.HashMap JavaDoc;
25 import javax.transaction.Transaction JavaDoc;
26 import javax.transaction.RollbackException JavaDoc;
27 import javax.transaction.SystemException JavaDoc;
28
29 import org.jboss.tm.TransactionLocal;
30
31
32 /**
33  * @deprecated this class was useful only for Instance Per Transaction containers and was used to check whether
34  * the instance is associated with the tx. There is org.jboss.ejb.plugins.PerTxEntityInstanceCache which is
35  * a per tx implementation of org.jboss.ejb.EntityCache which should be used with IPT containers.
36  * (alex@jboss.org)
37  *
38  * This class provides a way to find out what entities of a certain type that are contained in
39  * within a transaction. It is attached to a specific instance of a container.
40  *<no longer - global only holds possibly dirty> This class interfaces with the static GlobalTxEntityMap. EntitySynchronizationInterceptor
41  * registers tx/entity pairs through this class.
42  * Used in EntitySynchronizationInterceptor.
43  *
44  * @author <a HREF="bill@burkecentral.com">Bill Burke</a>
45  * @version $Revision: 37459 $
46  *
47  * Revisions:
48  *
49  * <p><b>Revisions:</b><br>
50  * <p><b>2001/08/06: billb</b>
51  * <ol>
52  * <li>Got rid of disassociate and added a javax.transaction.Synchronization. The sync will clean up the map now.
53  * <li>This class now interacts with GlobalTxEntityMap available.
54  * </ol>
55  */

56 public class TxEntityMap
57 {
58    protected TransactionLocal m_map = new TransactionLocal();
59
60    /**
61     * associate entity with transaction
62     */

63    public void associate(Transaction JavaDoc tx, EntityEnterpriseContext entity)
64       throws RollbackException JavaDoc, SystemException JavaDoc
65    {
66       HashMap JavaDoc entityMap = (HashMap JavaDoc) m_map.get(tx);
67       if(entityMap == null)
68       {
69          entityMap = new HashMap JavaDoc();
70          m_map.set(tx, entityMap);
71       }
72       //EntityContainer.getGlobalTxEntityMap().associate(tx, entity);
73
entityMap.put(entity.getCacheKey(), entity);
74    }
75
76    public EntityEnterpriseContext getCtx(Transaction JavaDoc tx, Object JavaDoc key)
77    {
78       HashMap JavaDoc entityMap = (HashMap JavaDoc) m_map.get(tx);
79       if(entityMap == null) return null;
80       return (EntityEnterpriseContext) entityMap.get(key);
81    }
82
83    public EntityEnterpriseContext getCtx(Object JavaDoc key)
84    {
85       HashMap JavaDoc entityMap = (HashMap JavaDoc) m_map.get();
86       if(entityMap == null) return null;
87       return (EntityEnterpriseContext) entityMap.get(key);
88    }
89 }
90
Popular Tags