Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PersistenceBrokerFactory |
|
| 1.0;1 |
1 | package org.apache.ojb.broker; | |
2 | ||
3 | /* Copyright 2002-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 org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory; | |
19 | import org.apache.ojb.broker.util.configuration.Configurator; | |
20 | import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator; | |
21 | import org.apache.ojb.broker.metadata.MetadataManager; | |
22 | ||
23 | /** | |
24 | * Convenience factory class that produces {@link PersistenceBroker} instances. | |
25 | * | |
26 | * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory | |
27 | * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF | |
28 | * @author Thomas Mahler | |
29 | * @version $Id: PersistenceBrokerFactory.java,v 1.1 2007-08-24 22:17:36 ewestfal Exp $ | |
30 | */ | |
31 | public class PersistenceBrokerFactory | |
32 | { | |
33 | /** | |
34 | * Returns the {@link org.apache.ojb.broker.util.configuration.Configurator} | |
35 | * object. | |
36 | * | |
37 | * @return The configurator | |
38 | */ | |
39 | public static Configurator getConfigurator() | |
40 | { | |
41 | return OjbConfigurator.getInstance(); | |
42 | } | |
43 | ||
44 | /** | |
45 | * Sets the key that specifies the default persistence manager. | |
46 | * | |
47 | * @param key The default broker key | |
48 | * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#setDefaultKey | |
49 | */ | |
50 | public static void setDefaultKey(PBKey key) | |
51 | { | |
52 | MetadataManager.getInstance().setDefaultPBKey(key); | |
53 | } | |
54 | ||
55 | /** | |
56 | * Returns the key that specifies the default persistence manager. | |
57 | * | |
58 | * @return The default broker key | |
59 | * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#getDefaultKey | |
60 | */ | |
61 | public static PBKey getDefaultKey() | |
62 | { | |
63 | return MetadataManager.getInstance().getDefaultPBKey(); | |
64 | } | |
65 | ||
66 | /** | |
67 | * Creates a default broker instance for the default broker key. | |
68 | * | |
69 | * @return The persistence broker | |
70 | * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#defaultPersistenceBroker | |
71 | */ | |
72 | public static PersistenceBroker defaultPersistenceBroker() throws PBFactoryException | |
73 | { | |
74 | return PersistenceBrokerFactoryFactory.instance(). | |
75 | defaultPersistenceBroker(); | |
76 | } | |
77 | ||
78 | /** | |
79 | * Creates a new broker instance. | |
80 | * | |
81 | * @param jcdAlias The jdbc connection descriptor name as defined in the repository | |
82 | * @param user The user name to be used for connecting to the database | |
83 | * @param password The password to be used for connecting to the database | |
84 | * @return The persistence broker | |
85 | * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#createPersistenceBroker(java.lang.String, java.lang.String, java.lang.String) | |
86 | */ | |
87 | public static PersistenceBroker createPersistenceBroker(String jcdAlias, | |
88 | String user, | |
89 | String password) throws PBFactoryException | |
90 | { | |
91 | return PersistenceBrokerFactoryFactory.instance(). | |
92 | createPersistenceBroker(jcdAlias, user, password); | |
93 | } | |
94 | ||
95 | /** | |
96 | * Creates a new broker instance for the given key. | |
97 | * | |
98 | * @param key The broker key | |
99 | * @return The persistence broker | |
100 | * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#createPersistenceBroker(org.apache.ojb.broker.PBKey) | |
101 | */ | |
102 | public static PersistenceBroker createPersistenceBroker(PBKey key) throws PBFactoryException | |
103 | { | |
104 | return PersistenceBrokerFactoryFactory.instance().createPersistenceBroker(key); | |
105 | } | |
106 | ||
107 | /** | |
108 | * Releases all broker instances pooled by this factory (if any). Note that the broker are | |
109 | * closed prior to releasing them. | |
110 | * | |
111 | * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#releaseAllInstances | |
112 | */ | |
113 | public static void releaseAllInstances() | |
114 | { | |
115 | PersistenceBrokerFactoryFactory.instance().releaseAllInstances(); | |
116 | } | |
117 | ||
118 | /** | |
119 | * Shuts OJB down, i.e. releases all resources. You should not use any OJB functionality | |
120 | * after calling this method. | |
121 | * | |
122 | * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#shutdown() | |
123 | */ | |
124 | public static void shutdown() | |
125 | { | |
126 | PersistenceBrokerFactoryFactory.instance().shutdown(); | |
127 | } | |
128 | } |