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.multi.LockTable; 30 import org.objectweb.jalisto.se.api.internal.InternalPhysicalFileAccess; 31 import org.objectweb.jalisto.se.api.physical.PluggablePhysicalFileAccess; 32 import org.objectweb.jalisto.se.exception.JalistoException; 33 import org.objectweb.jalisto.se.impl.server.LogicalPageAccessImpl; 34 import org.objectweb.jalisto.se.impl.server.InternalPhysicalFileAccessImpl; 35 import org.objectweb.jalisto.se.impl.server.*; 36 import org.objectweb.jalisto.se.impl.lock.AccessController; 37 import org.objectweb.jalisto.se.impl.lock.LockTableImpl; 38 import org.objectweb.jalisto.se.impl.mono.OidTableMonoImpl; 39 import org.objectweb.jalisto.se.impl.mono.SessionMonoImpl; 40 import org.objectweb.jalisto.se.impl.multi.InTransactionBaseImageMultiImpl; 41 import org.objectweb.jalisto.se.impl.multi.OidTableMultiImpl; 42 import org.objectweb.jalisto.se.impl.multi.SessionMultiImpl; 43 import org.objectweb.jalisto.se.impl.readonly.*; 44 45 import java.util.Hashtable ; 46 import java.util.Iterator ; 47 import java.util.Map ; 48 49 public class InternalGeneralFactory extends InternalFactoryImpl { 50 51 protected Map accessController; 52 protected Map lockManagers; 53 protected Map sessions; 54 55 public static InternalFactory getInstance() { 56 if (instance == null) { 57 instance = new InternalGeneralFactory(); 58 instance.init(); 59 } 60 return instance; 61 } 62 63 66 67 public void init() { 68 super.init(); 69 accessController = new Hashtable (); 70 lockManagers = new Hashtable (); 71 sessions = new Hashtable (); 72 } 73 74 public synchronized AccessController getAccessController(JalistoProperties properties) { 75 String path = properties.getDbFileFullName(); 76 if (!accessController.containsKey(path)) { 77 AccessController controller = new AccessController(); 78 accessController.put(path, controller); 79 } 80 return (AccessController) accessController.get(path); 81 } 82 83 public synchronized Session getSession(JalistoProperties properties) { 84 Session session; 85 if (properties.isMonoImplementation()) { 86 String name = properties.getName(); 87 if (!sessions.containsKey(name)) { 88 session = new SessionMonoImpl(properties); 89 sessions.put(name, session); 90 } else { 91 session = (Session) sessions.get(name); 92 } 93 if (session.currentTransaction().isActive()) { 94 System.out.println("WARNING : get the mono session already active"); 95 } 96 } else if (properties.isReadOnlyImplementation()) { 97 session = new SessionReadOnlyImpl(properties); 98 } else { 99 session = new SessionMultiImpl(properties); 100 sessions.put(session.getInternalSession().getSessionId(), session); 101 } 102 return session; 103 } 104 105 public synchronized OidTable getOidTable(JalistoProperties properties) { 106 String path = properties.getDbFileFullName(); 107 if (!oidTables.containsKey(path)) { 108 OidTable oidTable; 109 InternalPhysicalFileAccess physicalAccess = getInternalPhysicalAccess(properties); 110 if (properties.isMonoImplementation()) { 111 oidTable = OidTableMonoImpl.getAnOidTable(physicalAccess, properties); 112 } else if (properties.isReadOnlyImplementation()) { 113 oidTable = OidTableReadOnlyImpl.getAnOidTable(physicalAccess, properties); 114 } else { 115 oidTable = OidTableMultiImpl.getAnOidTable(physicalAccess, properties); 116 } 117 oidTables.put(path, oidTable); 118 } 119 return (OidTable) oidTables.get(path); 120 } 121 122 public synchronized InTransactionBaseImage getAInTransactionBaseImage( 123 PluggablePhysicalFileAccess physicalAccess, JalistoProperties properties) { 124 if (properties.isMonoImplementation() || properties.isReadOnlyImplementation()) { 125 return InTransactionBaseImageImpl.getInTransactionBaseImageInstance(physicalAccess, properties); 126 } else { 127 return InTransactionBaseImageMultiImpl.getInTransactionBaseImageInstance(physicalAccess, properties); 128 } 129 } 130 131 public synchronized LogicalSystemPageAccess getLogicalAccess(JalistoProperties properties) { 132 String path = properties.getDbFileFullName(); 133 if (!logicals.containsKey(path)) { 134 LogicalSystemPageAccess logical; 135 if (properties.isReadOnlyImplementation()) { 136 logical = new LogicalPageAccessReadOnlyImpl(properties); 137 } else { 138 logical = new LogicalPageAccessImpl(properties); 139 } 140 logicals.put(path, logical); 141 } 142 return (LogicalSystemPageAccess) logicals.get(path); 143 } 144 145 public synchronized InternalPhysicalFileAccess getInternalPhysicalAccess(JalistoProperties properties) { 146 String path = properties.getDbFileFullName(); 147 if (!physicals.containsKey(path)) { 148 InternalPhysicalFileAccess physical; 149 if (properties.isReadOnlyImplementation()) { 150 physical = new InternalPhysicalFileAccessReadOnlyImpl(properties); 151 } else { 152 physical = new InternalPhysicalFileAccessImpl(properties); 153 } 154 physicals.put(path, physical); 155 } 156 return (InternalPhysicalFileAccess) physicals.get(path); 157 } 158 159 160 public synchronized LockTable getLockTable(JalistoProperties properties) { 161 String path = properties.getDbFileFullName(); 162 if (!lockManagers.containsKey(path)) { 163 lockManagers.put(path, new LockTableImpl()); 164 } 165 return (LockTable) lockManagers.get(path); 166 } 167 168 public Object getSessionById(Object sessionId) { 169 return sessions.get(sessionId); 170 } 171 172 public void cleanFactory() { 173 Iterator sessionsIt = sessions.values().iterator(); 174 while (sessionsIt.hasNext()) { 175 SessionInternal session = (SessionInternal) sessionsIt.next(); 176 if (session.currentTransaction().isActive()) { 177 throw new JalistoException("cannot clean factory : session " + session.getSessionId() + " is active"); 178 } 179 if (session.isOpen()) { 180 throw new JalistoException("cannot clean factory : session " + session.getSessionId() + " is open"); 181 } 182 } 183 184 accessController.clear(); 185 lockManagers.clear(); 186 sessions.clear(); 187 super.cleanFactory(); 188 } 189 190 } 191 | Popular Tags |