01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: StoreManagerFactory.java,v 1.2 2002/10/17 21:00:58 pierreg0 Exp $
09: */
10:
11: package com.triactive.jdo.store;
12:
13: import com.triactive.jdo.PersistenceManagerFactoryImpl;
14: import java.util.HashMap;
15: import java.util.Map;
16: import java.util.WeakHashMap;
17:
18: public class StoreManagerFactory {
19: private static final Map cachesByPMF = new WeakHashMap();
20:
21: private StoreManagerFactory() {
22: }
23:
24: public static synchronized StoreManager getStoreManager(
25: PersistenceManagerFactoryImpl pmf, String userName,
26: String password) {
27: Map managersByLogon = (Map) cachesByPMF.get(pmf);
28:
29: if (managersByLogon == null) {
30: managersByLogon = new HashMap();
31: cachesByPMF.put(pmf, managersByLogon);
32: }
33:
34: String key = "" + userName + ';' + password;
35: StoreManager storeMgr = (StoreManager) managersByLogon.get(key);
36:
37: if (storeMgr == null) {
38: storeMgr = new StoreManager(pmf, userName, password);
39:
40: managersByLogon.put(key, storeMgr);
41: }
42:
43: return storeMgr;
44: }
45: }
|