1 21 22 package org.opensubsystems.core.persist.db; 23 24 import java.util.Map ; 25 import java.util.HashMap ; 26 import java.util.logging.Logger ; 27 28 import org.opensubsystems.core.error.OSSException; 29 import org.opensubsystems.core.util.ClassFactory; 30 import org.opensubsystems.core.util.GlobalConstants; 31 import org.opensubsystems.core.util.Log; 32 33 45 public class DatabaseSchemaManager 46 { 47 49 52 private static final String IMPL_LOCK = "IMPL_LOCK"; 53 54 56 59 protected ClassFactory m_schemaClassFactory; 60 61 65 private Map m_mpSchemaCache; 66 67 69 72 private static Logger s_logger = Log.getInstance(DatabaseSchemaManager.class); 73 74 77 private static DatabaseSchemaManager s_defaultInstance; 78 79 81 84 public DatabaseSchemaManager( 85 ) 86 { 87 m_schemaClassFactory = new DatabaseSchemaClassFactory(); 88 m_mpSchemaCache = new HashMap (); 89 } 90 91 101 public static DatabaseSchema getInstance( 102 Class databaseSchema 103 ) throws OSSException 104 { 105 return getManagerInstance().getSchemaInstance(databaseSchema); 106 } 107 108 118 public static DatabaseSchema getInstance( 119 String databaseSchema 120 ) throws OSSException 121 { 122 return getManagerInstance().getSchemaInstance(databaseSchema); 123 } 124 125 133 public static DatabaseSchemaManager getManagerInstance( 134 ) throws OSSException 135 { 136 if (s_defaultInstance == null) 137 { 138 synchronized (IMPL_LOCK) 141 { 142 setManagerInstance((DatabaseSchemaManager) 143 ClassFactory.getInstance().createInstance( 144 DatabaseSchemaManager.class, DatabaseSchemaManager.class)); 145 } 146 } 147 148 return s_defaultInstance; 149 } 150 151 158 public static void setManagerInstance( 159 DatabaseSchemaManager defaultInstance 160 ) 161 { 162 if (GlobalConstants.ERROR_CHECKING) 163 { 164 assert defaultInstance != null : "Default instance cannot be null"; 165 } 166 167 synchronized (IMPL_LOCK) 168 { 169 s_defaultInstance = defaultInstance; 170 s_logger.fine("Default database schema manager is " 171 + s_defaultInstance.getClass().getName()); 172 } 173 } 174 175 187 public DatabaseSchema getSchemaInstance( 188 Class databaseSchema 189 ) throws OSSException 190 { 191 Object schema; 192 193 schema = m_mpSchemaCache.get(databaseSchema.getName()); 194 if (schema == null) 195 { 196 synchronized (m_mpSchemaCache) 197 { 198 schema = m_schemaClassFactory.createInstance(databaseSchema); 199 m_mpSchemaCache.put(databaseSchema.getName(), schema); 200 } 201 } 202 203 return (DatabaseSchema)schema; 204 } 205 206 218 public DatabaseSchema getSchemaInstance( 219 String databaseSchema 220 ) throws OSSException 221 { 222 Object schema; 223 224 schema = m_mpSchemaCache.get(databaseSchema); 225 if (schema == null) 226 { 227 synchronized (m_mpSchemaCache) 228 { 229 schema = m_schemaClassFactory.createInstance(databaseSchema); 230 m_mpSchemaCache.put(databaseSchema, schema); 231 } 232 } 233 234 return (DatabaseSchema)schema; 235 } 236 } 237 | Popular Tags |