1 package org.apache.ojb.jdo; 2 3 17 18 import javax.jdo.PersistenceManager; 19 import javax.jdo.PersistenceManagerFactory; 20 import java.util.Arrays ; 21 import java.util.Collection ; 22 import java.util.Collections ; 23 import java.util.Properties ; 24 25 import org.apache.commons.lang.BooleanUtils; 26 27 30 31 public class PersistenceManagerFactoryImpl implements PersistenceManagerFactory 32 { 33 36 private boolean m_optimistic = true; 37 private boolean m_retainValues = true; 38 private boolean m_restoreValues = true; 39 private boolean m_nonTransactionalRead = true; 40 private boolean m_nonTransactionalWrite = false; 41 private boolean m_ignoreCache = true; 42 private boolean m_multiThreaded = false; 43 44 47 private int m_minPool = 1; 48 private int m_maxPool = 1; 49 private int m_msWait = 0; 50 51 54 private Object m_connectionFactory; 55 private String m_connectionFactoryName; 56 57 private Object m_connectionFactory2; 58 private String m_connectionFactory2Name; 59 60 private String m_connectionDriverName; 61 private String m_connectionURL; 62 63 private String m_connectionPassword; 64 private String m_connectionName; 65 66 private String m_alias; 67 68 71 private final String [] m_implementedOptions = new String []{ 72 "javax.jdo.option.TransientTransactional", 73 "javax.jdo.option.NontransactionalRead", 74 "javax.jdo.option.NontransactionalWrite", 75 "javax.jdo.option.RetainValues", 76 "javax.jdo.option.RestoreValues", 77 "javax.jdo.option.Optimistic", 78 "javax.jdo.option.ApplicationIdentity", 79 "javax.jdo.option.DatastoreIdentity", 80 "javax.jdo.option.NonDatastoreIdentity", 81 "javax.jdo.option.ArrayList", 82 "javax.jdo.option.HashMap", 83 "javax.jdo.option.Hashtable", 84 "javax.jdo.option.LinkedList", 85 "javax.jdo.option.TreeMap", 86 "javax.jdo.option.TreeSet", 87 "javax.jdo.option.Vector", 88 "javax.jdo.option.Map", 89 "javax.jdo.option.List", 90 "javax.jdo.option.Array", 91 "javax.jdo.option.NullCollection", 92 "javax.jdo.query.JDOQL" 93 }; 94 95 98 private static Properties PROPERTIES = new Properties (); 99 100 static 101 { 102 PROPERTIES.put("VendorName", "Apache ObjectRelationalBridge"); 103 PROPERTIES.put("VersionNumber", "1.0"); 104 } 105 106 130 public static PersistenceManagerFactory getPersistenceManagerFactory(Properties props) 131 { 132 PersistenceManagerFactoryImpl retval = new PersistenceManagerFactoryImpl(); 133 retval.setOptimistic(Boolean.getBoolean(props.getProperty(JDOConstants.OPTIMISTIC, BooleanUtils.toStringTrueFalse(retval.getOptimistic())))); 136 retval.setRetainValues(Boolean.getBoolean(props.getProperty(JDOConstants.RETAIN_VALUES, BooleanUtils.toStringTrueFalse(retval.getRetainValues())))); 137 retval.setRestoreValues(Boolean.getBoolean(props.getProperty(JDOConstants.RESTORE_VALUES, BooleanUtils.toStringTrueFalse(retval.getRestoreValues())))); 138 retval.setIgnoreCache(Boolean.getBoolean(props.getProperty(JDOConstants.IGNORE_CACHE, BooleanUtils.toStringTrueFalse(retval.getIgnoreCache())))); 139 retval.setNontransactionalRead(Boolean.getBoolean(props.getProperty(JDOConstants.NON_TRANSACTIONAL_READ, BooleanUtils.toStringTrueFalse(retval.getNontransactionalRead())))); 140 retval.setMultithreaded(Boolean.getBoolean(props.getProperty(JDOConstants.MULTI_THREADED, BooleanUtils.toStringTrueFalse(retval.getMultithreaded())))); 141 retval.setOptimistic(Boolean.getBoolean(props.getProperty(JDOConstants.OPTIMISTIC, BooleanUtils.toStringTrueFalse(retval.getOptimistic())))); 142 retval.setOptimistic(Boolean.getBoolean(props.getProperty(JDOConstants.OPTIMISTIC, BooleanUtils.toStringTrueFalse(retval.getOptimistic())))); 143 144 retval.setConnectionUserName(props.getProperty(JDOConstants.CONNECTION_USER_NAME, retval.getConnectionUserName())); 146 retval.setConnectionPassword(props.getProperty(JDOConstants.CONNECTION_PASSWORD, null)); 147 retval.setConnectionURL(props.getProperty(JDOConstants.CONNECTION_URL, retval.getConnectionURL())); 148 retval.setConnectionFactoryName(props.getProperty(JDOConstants.CONNECTION_FACTORY_NAME, retval.getConnectionFactoryName())); 149 retval.setConnectionFactory2Name(props.getProperty(JDOConstants.CONNECTION_FACTORY_2_NAME, retval.getConnectionFactory2Name())); 150 retval.setAlias(props.getProperty(JDOConstants.ALIAS, retval.getAlias())); 151 return retval; 152 } 153 154 public PersistenceManager getPersistenceManager() 155 { 156 return getPersistenceManager(null, null, null); 157 } 158 159 public PersistenceManager getPersistenceManager(String userid, String password) 160 { 161 return getPersistenceManager(null, userid, password); 162 } 163 164 public PersistenceManager getPersistenceManager(String alias, String userid, String password) 165 { 166 return new PersistenceManagerImpl(this, alias, userid, password); 167 } 168 169 public String getAlias() 170 { 171 return m_alias; 172 } 173 174 public void setAlias(String alias) 175 { 176 m_alias = alias; 177 } 178 179 public void setConnectionUserName(String s) 180 { 181 m_connectionName = s; 182 } 183 184 public String getConnectionUserName() 185 { 186 return m_connectionName; 187 } 188 189 public void setConnectionPassword(String s) 190 { 191 m_connectionPassword = s; 192 } 193 194 public void setConnectionURL(String s) 195 { 196 m_connectionURL = s; 197 } 198 199 public String getConnectionURL() 200 { 201 return m_connectionURL; 202 } 203 204 public void setConnectionDriverName(String s) 205 { 206 m_connectionDriverName = s; 207 } 208 209 public String getConnectionDriverName() 210 { 211 return m_connectionDriverName; 212 } 213 214 public void setConnectionFactoryName(String s) 215 { 216 m_connectionFactoryName = s; 217 } 218 219 public String getConnectionFactoryName() 220 { 221 return m_connectionFactoryName; 222 } 223 224 public void setConnectionFactory(Object o) 225 { 226 m_connectionFactory = o; 227 } 228 229 public Object getConnectionFactory() 230 { 231 return m_connectionFactory; 232 } 233 234 public void setConnectionFactory2Name(String s) 235 { 236 m_connectionFactory2Name = s; 237 } 238 239 public String getConnectionFactory2Name() 240 { 241 return m_connectionFactory2Name; 242 } 243 244 public void setConnectionFactory2(Object o) 245 { 246 m_connectionFactory2 = o; 247 } 248 249 public Object getConnectionFactory2() 250 { 251 return m_connectionFactory2; 252 } 253 254 public void setMultithreaded(boolean b) 255 { 256 m_multiThreaded = b; 257 } 258 259 public boolean getMultithreaded() 260 { 261 return m_multiThreaded; 262 } 263 264 public void setOptimistic(boolean b) 265 { 266 m_optimistic = b; 267 } 268 269 public boolean getOptimistic() 270 { 271 return m_optimistic; 272 } 273 274 public void setRetainValues(boolean b) 275 { 276 m_retainValues = b; 277 } 278 279 public boolean getRetainValues() 280 { 281 return m_retainValues; 282 } 283 284 public void setRestoreValues(boolean b) 285 { 286 m_restoreValues = b; 287 } 288 289 public boolean getRestoreValues() 290 { 291 return m_restoreValues; 292 } 293 294 public void setNontransactionalRead(boolean b) 295 { 296 m_nonTransactionalRead = b; 297 } 298 299 public boolean getNontransactionalRead() 300 { 301 return m_nonTransactionalRead; 302 } 303 304 public void setNontransactionalWrite(boolean b) 305 { 306 m_nonTransactionalWrite = b; 307 } 308 309 public boolean getNontransactionalWrite() 310 { 311 return m_nonTransactionalWrite; 312 } 313 314 public void setIgnoreCache(boolean b) 315 { 316 m_ignoreCache = b; 317 } 318 319 public boolean getIgnoreCache() 320 { 321 return m_ignoreCache; 322 } 323 324 public int getMaxPool() 325 { 326 return m_maxPool; 327 } 328 329 public void setMaxPool(int i) 330 { 331 m_maxPool = i; 332 } 333 334 public int getMinPool() 335 { 336 return m_minPool; 337 } 338 339 public void setMinPool(int i) 340 { 341 m_minPool = i; 342 } 343 344 public int getMsWait() 345 { 346 return m_msWait; 347 } 348 349 public void setMsWait(int i) 350 { 351 m_msWait = i; 352 } 353 354 360 public Properties getProperties() 361 { 362 return PROPERTIES; 363 } 364 365 396 public Collection supportedOptions() 397 { 398 return Collections.unmodifiableCollection(Arrays.asList(m_implementedOptions)); 399 } 400 403 public void close() 404 { 405 407 } 408 409 } 410 | Popular Tags |