KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > jdori > sql > OjbStorePMF


1 package org.apache.ojb.jdori.sql;
2 /* Copyright 2002-2005 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 import java.util.HashMap JavaDoc;
18 import java.util.Properties JavaDoc;
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 /**
32  * PMF for OjbStore implementation
33  * @author thma
34  *
35  */

36 public class OjbStorePMF extends PersistenceManagerFactoryImpl
37 {
38     private final HashMap JavaDoc storeManagers = new HashMap JavaDoc();
39
40     private static HashMap JavaDoc trackedClassesMap = getTrackedClasses();
41     
42     private static final OjbStorePMF INSTANCE = new OjbStorePMF();
43
44     public static OjbStorePMF getInstance()
45     {
46         return INSTANCE;
47     }
48
49     /**
50      * Constructor for PMF.
51      */

52     public OjbStorePMF()
53     {
54         super();
55     }
56
57     /**
58      * Constructor for PMF.
59      * @param URL
60      * @param userName
61      * @param password
62      * @param driverName
63      */

64     public OjbStorePMF(String JavaDoc URL, String JavaDoc userName, String JavaDoc password, String JavaDoc driverName)
65     {
66         super(URL, userName, password, driverName);
67     }
68
69     private static HashMap JavaDoc getTrackedClasses()
70     {
71         HashMap JavaDoc classMap = new HashMap JavaDoc();
72         // java.util.Date and java.sql classes:
73
classMap.put(java.util.Date JavaDoc.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 JavaDoc.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 JavaDoc.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 JavaDoc.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         // java.util.Set
89
classMap.put(java.util.HashSet JavaDoc.class, com.sun.jdori.common.sco.HashSet.class);
90         classMap.put(java.util.AbstractSet JavaDoc.class, com.sun.jdori.common.sco.HashSet.class);
91         classMap.put(java.util.Set JavaDoc.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         // java.util.List
97
classMap.put(java.util.ArrayList JavaDoc.class, com.sun.jdori.common.sco.ArrayList.class);
98         classMap.put(java.util.AbstractList JavaDoc.class, com.sun.jdori.common.sco.ArrayList.class);
99         classMap.put(java.util.List JavaDoc.class, com.sun.jdori.common.sco.ArrayList.class);
100         classMap.put(java.util.AbstractCollection JavaDoc.class, com.sun.jdori.common.sco.ArrayList.class);
101         classMap.put(java.util.Collection JavaDoc.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         // java.util.Vector
107
classMap.put(java.util.Vector JavaDoc.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         // java.util.SortedSet
111
classMap.put(java.util.TreeSet JavaDoc.class, com.sun.jdori.common.sco.TreeSet.class);
112         classMap.put(java.util.SortedSet JavaDoc.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         // java.util.LinkedList
118
classMap.put(java.util.LinkedList JavaDoc.class, com.sun.jdori.common.sco.LinkedList.class);
119         classMap.put(
120             java.util.AbstractSequentialList JavaDoc.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         // java.util.Map
127
classMap.put(java.util.Map JavaDoc.class, com.sun.jdori.common.sco.HashMap.class);
128         classMap.put(java.util.AbstractMap JavaDoc.class, com.sun.jdori.common.sco.HashMap.class);
129         classMap.put(java.util.HashMap JavaDoc.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         // java.util.Hashtable
135
classMap.put(java.util.Hashtable JavaDoc.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         // java.util.SortedMap
141
classMap.put(java.util.SortedMap JavaDoc.class, com.sun.jdori.common.sco.TreeMap.class);
142         classMap.put(java.util.TreeMap JavaDoc.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     /**
151      * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#getOptionArray()
152      */

153     protected String JavaDoc[] getOptionArray()
154     {
155         String JavaDoc[] optionsA = {""};
156         return optionsA;
157     }
158
159     /**
160      * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#createPersistenceManager(String, String)
161      */

162     protected PersistenceManager createPersistenceManager(String JavaDoc aUserid, String JavaDoc 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 JavaDoc ex)
175         {
176             throw new OjbStoreFatalInternalException(
177                 getClass(),
178                 "createPersistenceManager(userid, password)",
179                 ex);
180         }
181         return result;
182     }
183
184     /**
185      * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#setPMFClassProperty(Properties)
186      */

187     protected void setPMFClassProperty(Properties JavaDoc props)
188     {
189         props.setProperty("javax.jdo.PersistenceManagerFactoryClass", this.getClass().getName());
190     }
191
192     /**
193      * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#encrypt(String)
194      */

195     protected String JavaDoc encrypt(String JavaDoc s)
196     {
197         return s;
198     }
199
200     /**
201      * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#decrypt(String)
202      */

203     protected String JavaDoc decrypt(String JavaDoc s)
204     {
205         return s;
206     }
207
208     /**
209      * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#setCFProperties(Properties)
210      */

211     protected void setCFProperties(Properties JavaDoc p)
212     {
213     }
214
215     /**
216      * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#getCFFromProperties(Properties)
217      */

218     protected void getCFFromProperties(Properties JavaDoc p)
219     {
220     }
221
222     /**
223      * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#isConnectionFactoryConfigured()
224      */

225     protected boolean isConnectionFactoryConfigured()
226     {
227         return true;
228     }
229
230     /**
231      * @see com.sun.jdori.PersistenceManagerFactoryInternal#getTranscriberFactory()
232      */

233     public TranscriberFactory getTranscriberFactory()
234     {
235         return null;
236     }
237
238     /**
239      * @see com.sun.jdori.PersistenceManagerFactoryInternal#getObjectIdClass(Class)
240      */

241     public Class JavaDoc getObjectIdClass(Class JavaDoc cls)
242     {
243         Class JavaDoc result = null;
244         if (null != cls && PersistenceCapable.class.isAssignableFrom(cls))
245         {
246             result = Identity.class;
247         }
248         return result;
249     }
250
251     /**
252      * @see com.sun.jdori.PersistenceManagerFactoryInternal#getStoreManager(PersistenceManager)
253      */

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 JavaDoc ex)
271         {
272             throw new OjbStoreFatalInternalException(getClass(), "getStoreManager", ex);
273         }
274         return result;
275     }
276
277     /**
278      * @see com.sun.jdori.PersistenceManagerFactoryInternal#releaseStoreManager(PersistenceManager)
279      */

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 JavaDoc ex)
291         {
292             throw new OjbStoreFatalInternalException(getClass(), "releaseStoreManager", ex);
293         }
294     }
295
296     /**
297      * @see com.sun.jdori.PersistenceManagerFactoryInternal#getTrackedClass(Class)
298      */

299     public Class JavaDoc getTrackedClass(Class JavaDoc type)
300     {
301         return (Class JavaDoc) trackedClassesMap.get(type);
302     }
303
304 }
305
Popular Tags