KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > jdo > PersistenceManagerFactoryImpl


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

17
18 import javax.jdo.PersistenceManager;
19 import javax.jdo.PersistenceManagerFactory;
20 import java.util.Arrays JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import org.apache.commons.lang.BooleanUtils;
26
27 /**
28  * @author <a HREF="mailto:mattbaird@yahoo.com">Matthew Baird</a>
29  */

30
31 public class PersistenceManagerFactoryImpl implements PersistenceManagerFactory
32 {
33     /**
34      * flags
35      */

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     /**
45      * pool information
46      */

47     private int m_minPool = 1;
48     private int m_maxPool = 1;
49     private int m_msWait = 0;
50
51     /**
52      * connection factory information
53      */

54     private Object JavaDoc m_connectionFactory;
55     private String JavaDoc m_connectionFactoryName;
56
57     private Object JavaDoc m_connectionFactory2;
58     private String JavaDoc m_connectionFactory2Name;
59
60     private String JavaDoc m_connectionDriverName;
61     private String JavaDoc m_connectionURL;
62
63     private String JavaDoc m_connectionPassword;
64     private String JavaDoc m_connectionName;
65
66     private String JavaDoc m_alias;
67
68     /**
69      * support options
70      */

71     private final String JavaDoc[] m_implementedOptions = new String JavaDoc[]{
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     /**
96      * properties
97      */

98     private static Properties JavaDoc PROPERTIES = new Properties JavaDoc();
99
100     static
101     {
102         PROPERTIES.put("VendorName", "Apache ObjectRelationalBridge");
103         PROPERTIES.put("VersionNumber", "1.0");
104     }
105
106     /**
107      * This method returns an instance of PersistenceManagerFactory based on the properties
108      * in the parameter. It is used by JDOHelper to construct an instance of PersistenceManagerFactory
109      * based on user-specified properties.
110      * The following are standard key values for the Properties:
111      * Java Data Objects1.0
112      * javax.jdo.PersistenceManagerFactoryClass --> Ignored, we only have one and that is PersistenceManagerFactoryImpl
113      * javax.jdo.option.Optimistic
114      * javax.jdo.option.RetainValues
115      * javax.jdo.option.RestoreValues
116      * javax.jdo.option.IgnoreCache
117      * javax.jdo.option.NontransactionalRead
118      * javax.jdo.option.NontransactionalWrite
119      * javax.jdo.option.Multithreaded
120      *
121      * javax.jdo.option.ConnectionUserName
122      * javax.jdo.option.ConnectionPassword
123      * javax.jdo.option.ConnectionURL
124      * javax.jdo.option.ConnectionFactoryName
125      * javax.jdo.option.ConnectionFactory2Name
126      * @see JDOConstants
127      * @param props
128      * @return the PersistenceManagerFactory instance with the appropriate Properties.
129      */

130     public static PersistenceManagerFactory getPersistenceManagerFactory(Properties JavaDoc props)
131     {
132         PersistenceManagerFactoryImpl retval = new PersistenceManagerFactoryImpl();
133         // parse and set the properties
134
// boolean props
135
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         // string props
145
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 JavaDoc userid, String JavaDoc password)
160     {
161         return getPersistenceManager(null, userid, password);
162     }
163
164     public PersistenceManager getPersistenceManager(String JavaDoc alias, String JavaDoc userid, String JavaDoc password)
165     {
166         return new PersistenceManagerImpl(this, alias, userid, password);
167     }
168
169     public String JavaDoc getAlias()
170     {
171         return m_alias;
172     }
173
174     public void setAlias(String JavaDoc alias)
175     {
176         m_alias = alias;
177     }
178
179     public void setConnectionUserName(String JavaDoc s)
180     {
181         m_connectionName = s;
182     }
183
184     public String JavaDoc getConnectionUserName()
185     {
186         return m_connectionName;
187     }
188
189     public void setConnectionPassword(String JavaDoc s)
190     {
191         m_connectionPassword = s;
192     }
193
194     public void setConnectionURL(String JavaDoc s)
195     {
196         m_connectionURL = s;
197     }
198
199     public String JavaDoc getConnectionURL()
200     {
201         return m_connectionURL;
202     }
203
204     public void setConnectionDriverName(String JavaDoc s)
205     {
206         m_connectionDriverName = s;
207     }
208
209     public String JavaDoc getConnectionDriverName()
210     {
211         return m_connectionDriverName;
212     }
213
214     public void setConnectionFactoryName(String JavaDoc s)
215     {
216         m_connectionFactoryName = s;
217     }
218
219     public String JavaDoc getConnectionFactoryName()
220     {
221         return m_connectionFactoryName;
222     }
223
224     public void setConnectionFactory(Object JavaDoc o)
225     {
226         m_connectionFactory = o;
227     }
228
229     public Object JavaDoc getConnectionFactory()
230     {
231         return m_connectionFactory;
232     }
233
234     public void setConnectionFactory2Name(String JavaDoc s)
235     {
236         m_connectionFactory2Name = s;
237     }
238
239     public String JavaDoc getConnectionFactory2Name()
240     {
241         return m_connectionFactory2Name;
242     }
243
244     public void setConnectionFactory2(Object JavaDoc o)
245     {
246         m_connectionFactory2 = o;
247     }
248
249     public Object JavaDoc 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     /**
355      * Return "static" properties of this PersistenceManagerFactory.
356      * Properties with keys VendorName and VersionNumber are required. Other
357      * keys are optional.
358      * @return the non-operational properties of this PersistenceManagerFactory.
359      */

360     public Properties JavaDoc getProperties()
361     {
362         return PROPERTIES;
363     }
364
365     /** The application can determine from the results of this
366      * method which optional features are supported by the
367      * JDO implementation.
368      * <P>Each supported JDO optional feature is represented by a
369      * String with one of the following values:
370      *
371      * <P>javax.jdo.option.TransientTransactional
372      * <P>javax.jdo.option.NontransactionalRead
373      * <P>javax.jdo.option.NontransactionalWrite
374      * <P>javax.jdo.option.RetainValues
375      * <P>javax.jdo.option.RestoreValues
376      * <P>javax.jdo.option.Optimistic
377      * <P>javax.jdo.option.ApplicationIdentity
378      * <P>javax.jdo.option.DatastoreIdentity
379      * <P>javax.jdo.option.NonDatastoreIdentity
380      * <P>javax.jdo.option.ArrayList
381      * <P>javax.jdo.option.HashMap
382      * <P>javax.jdo.option.Hashtable
383      * <P>javax.jdo.option.LinkedList
384      * <P>javax.jdo.option.TreeMap
385      * <P>javax.jdo.option.TreeSet
386      * <P>javax.jdo.option.Vector
387      * <P>javax.jdo.option.Map
388      * <P>javax.jdo.option.List
389      * <P>javax.jdo.option.Array
390      * <P>javax.jdo.option.NullCollection
391      *
392      *<P>The standard JDO query language is represented by a String:
393      *<P>javax.jdo.query.JDOQL
394      * @return the Set of String representing the supported Options
395      */

396     public Collection JavaDoc supportedOptions()
397     {
398         return Collections.unmodifiableCollection(Arrays.asList(m_implementedOptions));
399     }
400     /* (non-Javadoc)
401      * @see javax.jdo.PersistenceManagerFactory#close()
402      */

403     public void close()
404     {
405         // TODO Auto-generated method stub
406

407     }
408
409 }
410
Popular Tags