1 21 package oracle.toplink.essentials.internal.ejb.cmp3.base; 23 24 import java.util.Map ; 25 import oracle.toplink.essentials.threetier.ServerSession; 26 import oracle.toplink.essentials.internal.localization.ExceptionLocalization; 27 import oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl; 28 29 41 42 45 46 public abstract class EntityManagerFactoryImpl { 47 protected ServerSession serverSession; 49 protected EntityManagerSetupImpl setupImpl; 50 protected boolean isOpen = true; 51 protected Map properties; 52 53 protected abstract EntityManagerImpl createEntityManagerImplInternal(Map properties, boolean extended); 54 55 59 public EntityManagerFactoryImpl(ServerSession serverSession){ 60 this.serverSession = serverSession; 61 } 62 63 public EntityManagerFactoryImpl(EntityManagerSetupImpl setupImpl, Map properties){ 64 this.setupImpl = setupImpl; 65 this.properties = properties; 66 } 67 68 74 public synchronized ServerSession getServerSession(){ 75 if (serverSession == null){ 76 ClassLoader realLoader = setupImpl.getPersistenceUnitInfo().getClassLoader(); 77 serverSession = setupImpl.deploy(realLoader, properties); 79 } 80 return this.serverSession; 81 } 82 83 89 public synchronized void close(){ 90 verifyOpen(); 91 isOpen = false; 92 if(serverSession != null) { 93 setupImpl.undeploy(); 94 } 95 } 96 97 98 102 public boolean isOpen(){ 103 return isOpen; 104 } 105 106 protected EntityManagerImpl createEntityManagerImpl(boolean extended) { 107 return createEntityManagerImpl(null, extended); 108 } 109 110 protected synchronized EntityManagerImpl createEntityManagerImpl(Map properties, boolean extended) { 111 verifyOpen(); 112 113 if (!getServerSession().isConnected()) { 114 getServerSession().login(); 115 } 116 return createEntityManagerImplInternal(properties, extended); 117 } 118 119 protected void verifyOpen(){ 120 if (!isOpen){ 121 throw new IllegalStateException (ExceptionLocalization.buildMessage("operation_on_closed_entity_manager_factory")); 122 } 123 } 124 125 protected void finalize() throws Throwable { 126 if(isOpen()) { 127 close(); 128 } 129 } 130 } 131 | Popular Tags |