1 17 18 package org.apache.geronimo.persistence; 19 20 import java.util.Map ; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 24 import javax.transaction.Transaction ; 25 26 29 public class EntityManagerExtendedRegistry { 30 31 private static final ThreadLocal <Map <String , InternalCMPEntityManagerExtended>> entityManagerMaps = new ThreadLocal <Map <String , InternalCMPEntityManagerExtended>>() { 32 protected Map <String , InternalCMPEntityManagerExtended> initialValue() { 33 return new HashMap <String , InternalCMPEntityManagerExtended>(); 34 } 35 }; 36 37 public static InternalCMPEntityManagerExtended getEntityManager(String persistenceUnit) { 38 Map <String , InternalCMPEntityManagerExtended> entityManagerMap = entityManagerMaps.get(); 39 return entityManagerMap.get(persistenceUnit); 40 } 41 42 public static void putEntityManager(String persistenceUnit, InternalCMPEntityManagerExtended entityManager) { 43 Map <String , InternalCMPEntityManagerExtended> entityManagerMap = entityManagerMaps.get(); 44 InternalCMPEntityManagerExtended oldEntityManager = entityManagerMap.put(persistenceUnit, entityManager); 45 if (oldEntityManager != null) { 46 throw new IllegalStateException ("There was already an EntityManager registered for persistenceUnit " + persistenceUnit); 47 } 48 } 49 50 public static void clearEntityManager(String persistenceUnit) { 51 Map <String , InternalCMPEntityManagerExtended> entityManagerMap = entityManagerMaps.get(); 52 entityManagerMap.remove(persistenceUnit); 53 } 54 55 public static void threadAssociated(Transaction transaction) { 56 Map <String , InternalCMPEntityManagerExtended> entityManagerMap = entityManagerMaps.get(); 57 for (Iterator i = entityManagerMap.values().iterator(); i.hasNext(); ) { 58 InternalCMPEntityManagerExtended entityManager = (InternalCMPEntityManagerExtended) i.next(); 59 entityManager.joinTransaction(); 60 } 61 } 62 63 public static void threadUnassociated(Transaction transaction) { 64 } 66 } 67 | Popular Tags |