01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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;
25: import javax.transaction.Transaction;
26: import javax.transaction.RollbackException;
27: import javax.transaction.SystemException;
28:
29: import org.jboss.tm.TransactionLocal;
30:
31: /**
32: * @deprecated this class was useful only for Instance Per Transaction containers and was used to check whether
33: * the instance is associated with the tx. There is org.jboss.ejb.plugins.PerTxEntityInstanceCache which is
34: * a per tx implementation of org.jboss.ejb.EntityCache which should be used with IPT containers.
35: * (alex@jboss.org)
36: *
37: * This class provides a way to find out what entities of a certain type that are contained in
38: * within a transaction. It is attached to a specific instance of a container.
39: *<no longer - global only holds possibly dirty> This class interfaces with the static GlobalTxEntityMap. EntitySynchronizationInterceptor
40: * registers tx/entity pairs through this class.
41: * Used in EntitySynchronizationInterceptor.
42: *
43: * @author <a href="bill@burkecentral.com">Bill Burke</a>
44: * @version $Revision: 57209 $
45: *
46: * Revisions:
47: *
48: * <p><b>Revisions:</b><br>
49: * <p><b>2001/08/06: billb</b>
50: * <ol>
51: * <li>Got rid of disassociate and added a javax.transaction.Synchronization. The sync will clean up the map now.
52: * <li>This class now interacts with GlobalTxEntityMap available.
53: * </ol>
54: */
55: public class TxEntityMap {
56: protected TransactionLocal m_map = new TransactionLocal();
57:
58: /**
59: * associate entity with transaction
60: */
61: public void associate(Transaction tx, EntityEnterpriseContext entity)
62: throws RollbackException, SystemException {
63: HashMap entityMap = (HashMap) m_map.get(tx);
64: if (entityMap == null) {
65: entityMap = new HashMap();
66: m_map.set(tx, entityMap);
67: }
68: //EntityContainer.getGlobalTxEntityMap().associate(tx, entity);
69: entityMap.put(entity.getCacheKey(), entity);
70: }
71:
72: public EntityEnterpriseContext getCtx(Transaction tx, Object key) {
73: HashMap entityMap = (HashMap) m_map.get(tx);
74: if (entityMap == null)
75: return null;
76: return (EntityEnterpriseContext) entityMap.get(key);
77: }
78:
79: public EntityEnterpriseContext getCtx(Object key) {
80: HashMap entityMap = (HashMap) m_map.get();
81: if (entityMap == null)
82: return null;
83: return (EntityEnterpriseContext) entityMap.get(key);
84: }
85: }
|