KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > StoreManagerFactory


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: StoreManagerFactory.java,v 1.2 2002/10/17 21:00:58 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import com.triactive.jdo.PersistenceManagerFactoryImpl;
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16 import java.util.WeakHashMap JavaDoc;
17
18
19 public class StoreManagerFactory
20 {
21     private static final Map JavaDoc cachesByPMF = new WeakHashMap JavaDoc();
22
23     private StoreManagerFactory()
24     {
25     }
26
27     public static synchronized StoreManager getStoreManager(PersistenceManagerFactoryImpl pmf,
28                                                             String JavaDoc userName,
29                                                             String JavaDoc password)
30     {
31         Map JavaDoc managersByLogon = (Map JavaDoc)cachesByPMF.get(pmf);
32
33         if (managersByLogon == null)
34         {
35             managersByLogon = new HashMap JavaDoc();
36             cachesByPMF.put(pmf, managersByLogon);
37         }
38
39         String JavaDoc key = "" + userName + ';' + password;
40         StoreManager storeMgr = (StoreManager)managersByLogon.get(key);
41
42         if (storeMgr == null)
43         {
44             storeMgr = new StoreManager(pmf, userName, password);
45
46             managersByLogon.put(key, storeMgr);
47         }
48
49         return storeMgr;
50     }
51 }
52
Popular Tags