1 24 package org.objectweb.jalisto.se.impl.factory; 25 26 import org.objectweb.jalisto.se.api.JalistoProperties; 27 import org.objectweb.jalisto.se.api.Session; 28 import org.objectweb.jalisto.se.api.internal.*; 29 import org.objectweb.jalisto.se.api.internal.InternalPhysicalFileAccess; 30 import org.objectweb.jalisto.se.exception.JalistoException; 31 import org.objectweb.jalisto.se.impl.server.InternalPhysicalFileAccessImpl; 32 import org.objectweb.jalisto.se.impl.mono.OidTableMonoImpl; 33 import org.objectweb.jalisto.se.impl.mono.SessionMonoImpl; 34 35 import java.util.Hashtable ; 36 import java.util.Iterator ; 37 import java.util.Map ; 38 39 public class InternalMonoFactory extends InternalFactoryImpl { 40 41 protected Map sessions; 42 43 public static InternalFactory getInstance() { 44 if (instance == null) { 45 instance = new InternalMonoFactory(); 46 instance.init(); 47 } 48 return instance; 49 } 50 51 public void init() { 52 super.init(); 53 sessions = new Hashtable (); 54 } 55 56 public synchronized Session getSession(JalistoProperties properties) { 57 Session session; 58 if (properties.isMonoImplementation()) { 59 String name = properties.getName(); 60 if (!sessions.containsKey(name)) { 61 session = new SessionMonoImpl(properties); 62 sessions.put(name, session); 63 } else { 64 session = (Session) sessions.get(name); 65 } 66 if (session.currentTransaction().isActive()) { 67 System.out.println("WARNING : get the mono session already active"); 68 } 69 } else { 70 throw new JalistoException("try to get no mono object implementation with mono factory"); 71 } 72 return session; 73 } 74 75 public synchronized OidTable getOidTable(JalistoProperties properties) { 76 String path = properties.getDbFileFullName(); 77 if (!oidTables.containsKey(path)) { 78 OidTable oidTable; 79 InternalPhysicalFileAccess physicalAccess = getInternalPhysicalAccess(properties); 80 if (properties.isMonoImplementation()) { 81 oidTable = OidTableMonoImpl.getAnOidTable(physicalAccess, properties); 82 } else { 83 throw new JalistoException("try to get no mono object implementation with mono factory"); 84 } 85 oidTables.put(path, oidTable); 86 } 87 return (OidTable) oidTables.get(path); 88 } 89 90 public synchronized InternalPhysicalFileAccess getInternalPhysicalAccess(JalistoProperties properties) { 91 String path = properties.getDbFileFullName(); 92 if (!physicals.containsKey(path)) { 93 physicals.put(path, new InternalPhysicalFileAccessImpl(properties)); 94 } 95 return (InternalPhysicalFileAccess) physicals.get(path); 96 } 97 98 public Object getSessionById(Object sessionId) { 99 return sessions.get(sessionId); 100 } 101 102 public void cleanFactory() { 103 Iterator sessionsIt = sessions.values().iterator(); 104 while (sessionsIt.hasNext()) { 105 SessionInternal session = (SessionInternal) sessionsIt.next(); 106 if (session.currentTransaction().isActive()) { 107 throw new JalistoException("cannot clean factory : session " + session.getSessionId() + " is active"); 108 } 109 if (session.isOpen()) { 110 throw new JalistoException("cannot clean factory : session " + session.getSessionId() + " is open"); 111 } 112 } 113 sessions.clear(); 114 super.cleanFactory(); 115 } 116 117 } 118 | Popular Tags |