1 package org.apache.ojb.jdori.sql; 2 16 17 import java.util.HashMap ; 18 import java.util.Properties ; 19 20 import javax.jdo.JDOException; 21 import javax.jdo.PersistenceManager; 22 import javax.jdo.spi.PersistenceCapable; 23 24 import org.apache.ojb.broker.Identity; 25 26 import com.sun.jdori.StoreManager; 27 import com.sun.jdori.TranscriberFactory; 28 import com.sun.jdori.common.PersistenceManagerFactoryImpl; 29 import com.sun.jdori.common.PersistenceManagerImpl; 30 31 36 public class OjbStorePMF extends PersistenceManagerFactoryImpl 37 { 38 private final HashMap storeManagers = new HashMap (); 39 40 private static HashMap trackedClassesMap = getTrackedClasses(); 41 42 private static final OjbStorePMF INSTANCE = new OjbStorePMF(); 43 44 public static OjbStorePMF getInstance() 45 { 46 return INSTANCE; 47 } 48 49 52 public OjbStorePMF() 53 { 54 super(); 55 } 56 57 64 public OjbStorePMF(String URL, String userName, String password, String driverName) 65 { 66 super(URL, userName, password, driverName); 67 } 68 69 private static HashMap getTrackedClasses() 70 { 71 HashMap classMap = new HashMap (); 72 classMap.put(java.util.Date .class, com.sun.jdori.common.sco.Date.class); 74 classMap.put(com.sun.jdori.common.sco.Date.class, com.sun.jdori.common.sco.Date.class); 75 classMap.put(java.sql.Date .class, com.sun.jdori.common.sco.SqlDate.class); 76 classMap.put( 77 com.sun.jdori.common.sco.SqlDate.class, 78 com.sun.jdori.common.sco.SqlDate.class); 79 classMap.put(java.sql.Time .class, com.sun.jdori.common.sco.SqlTime.class); 80 classMap.put( 81 com.sun.jdori.common.sco.SqlTime.class, 82 com.sun.jdori.common.sco.SqlTime.class); 83 classMap.put(java.sql.Timestamp .class, com.sun.jdori.common.sco.SqlTimestamp.class); 84 classMap.put( 85 com.sun.jdori.common.sco.SqlTimestamp.class, 86 com.sun.jdori.common.sco.SqlTimestamp.class); 87 88 classMap.put(java.util.HashSet .class, com.sun.jdori.common.sco.HashSet.class); 90 classMap.put(java.util.AbstractSet .class, com.sun.jdori.common.sco.HashSet.class); 91 classMap.put(java.util.Set .class, com.sun.jdori.common.sco.HashSet.class); 92 classMap.put( 93 com.sun.jdori.common.sco.HashSet.class, 94 com.sun.jdori.common.sco.HashSet.class); 95 96 classMap.put(java.util.ArrayList .class, com.sun.jdori.common.sco.ArrayList.class); 98 classMap.put(java.util.AbstractList .class, com.sun.jdori.common.sco.ArrayList.class); 99 classMap.put(java.util.List .class, com.sun.jdori.common.sco.ArrayList.class); 100 classMap.put(java.util.AbstractCollection .class, com.sun.jdori.common.sco.ArrayList.class); 101 classMap.put(java.util.Collection .class, com.sun.jdori.common.sco.ArrayList.class); 102 classMap.put( 103 com.sun.jdori.common.sco.ArrayList.class, 104 com.sun.jdori.common.sco.ArrayList.class); 105 106 classMap.put(java.util.Vector .class, com.sun.jdori.common.sco.Vector.class); 108 classMap.put(com.sun.jdori.common.sco.Vector.class, com.sun.jdori.common.sco.Vector.class); 109 110 classMap.put(java.util.TreeSet .class, com.sun.jdori.common.sco.TreeSet.class); 112 classMap.put(java.util.SortedSet .class, com.sun.jdori.common.sco.TreeSet.class); 113 classMap.put( 114 com.sun.jdori.common.sco.TreeSet.class, 115 com.sun.jdori.common.sco.TreeSet.class); 116 117 classMap.put(java.util.LinkedList .class, com.sun.jdori.common.sco.LinkedList.class); 119 classMap.put( 120 java.util.AbstractSequentialList .class, 121 com.sun.jdori.common.sco.LinkedList.class); 122 classMap.put( 123 com.sun.jdori.common.sco.LinkedList.class, 124 com.sun.jdori.common.sco.LinkedList.class); 125 126 classMap.put(java.util.Map .class, com.sun.jdori.common.sco.HashMap.class); 128 classMap.put(java.util.AbstractMap .class, com.sun.jdori.common.sco.HashMap.class); 129 classMap.put(java.util.HashMap .class, com.sun.jdori.common.sco.HashMap.class); 130 classMap.put( 131 com.sun.jdori.common.sco.HashMap.class, 132 com.sun.jdori.common.sco.HashMap.class); 133 134 classMap.put(java.util.Hashtable .class, com.sun.jdori.common.sco.Hashtable.class); 136 classMap.put( 137 com.sun.jdori.common.sco.Hashtable.class, 138 com.sun.jdori.common.sco.Hashtable.class); 139 140 classMap.put(java.util.SortedMap .class, com.sun.jdori.common.sco.TreeMap.class); 142 classMap.put(java.util.TreeMap .class, com.sun.jdori.common.sco.TreeMap.class); 143 classMap.put( 144 com.sun.jdori.common.sco.TreeMap.class, 145 com.sun.jdori.common.sco.TreeMap.class); 146 147 return classMap; 148 } 149 150 153 protected String [] getOptionArray() 154 { 155 String [] optionsA = {""}; 156 return optionsA; 157 } 158 159 162 protected PersistenceManager createPersistenceManager(String aUserid, String aPassword) 163 { 164 165 PersistenceManager result = null; 166 try 167 { 168 result = new PersistenceManagerImpl(this, aUserid, aPassword); 169 } 170 catch (JDOException ex) 171 { 172 throw ex; 173 } 174 catch (Exception ex) 175 { 176 throw new OjbStoreFatalInternalException( 177 getClass(), 178 "createPersistenceManager(userid, password)", 179 ex); 180 } 181 return result; 182 } 183 184 187 protected void setPMFClassProperty(Properties props) 188 { 189 props.setProperty("javax.jdo.PersistenceManagerFactoryClass", this.getClass().getName()); 190 } 191 192 195 protected String encrypt(String s) 196 { 197 return s; 198 } 199 200 203 protected String decrypt(String s) 204 { 205 return s; 206 } 207 208 211 protected void setCFProperties(Properties p) 212 { 213 } 214 215 218 protected void getCFFromProperties(Properties p) 219 { 220 } 221 222 225 protected boolean isConnectionFactoryConfigured() 226 { 227 return true; 228 } 229 230 233 public TranscriberFactory getTranscriberFactory() 234 { 235 return null; 236 } 237 238 241 public Class getObjectIdClass(Class cls) 242 { 243 Class result = null; 244 if (null != cls && PersistenceCapable.class.isAssignableFrom(cls)) 245 { 246 result = Identity.class; 247 } 248 return result; 249 } 250 251 254 public StoreManager getStoreManager(PersistenceManager pm) 255 { 256 OjbStoreManager result = null; 257 try 258 { 259 result = (OjbStoreManager) storeManagers.get(pm); 260 if (null == result) 261 { 262 result = new OjbStoreManager(this); 263 storeManagers.put(pm, result); 264 } 265 } 266 catch (JDOException ex) 267 { 268 throw ex; 269 } 270 catch (Exception ex) 271 { 272 throw new OjbStoreFatalInternalException(getClass(), "getStoreManager", ex); 273 } 274 return result; 275 } 276 277 280 public void releaseStoreManager(PersistenceManager pm) 281 { 282 try 283 { 284 storeManagers.remove(pm); 285 } 286 catch (JDOException ex) 287 { 288 throw ex; 289 } 290 catch (Exception ex) 291 { 292 throw new OjbStoreFatalInternalException(getClass(), "releaseStoreManager", ex); 293 } 294 } 295 296 299 public Class getTrackedClass(Class type) 300 { 301 return (Class ) trackedClassesMap.get(type); 302 } 303 304 } 305 | Popular Tags |