001: package org.apache.ojb.broker;
002:
003: /* Copyright 2002-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory;
019: import org.apache.ojb.broker.util.configuration.Configurator;
020: import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
021: import org.apache.ojb.broker.metadata.MetadataManager;
022:
023: /**
024: * Convenience factory class that produces {@link PersistenceBroker} instances.
025: *
026: * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory
027: * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF
028: * @author Thomas Mahler
029: * @version $Id: PersistenceBrokerFactory.java,v 1.23.2.3 2005/12/22 21:24:51 tomdz Exp $
030: */
031: public class PersistenceBrokerFactory {
032: /**
033: * Returns the {@link org.apache.ojb.broker.util.configuration.Configurator}
034: * object.
035: *
036: * @return The configurator
037: */
038: public static Configurator getConfigurator() {
039: return OjbConfigurator.getInstance();
040: }
041:
042: /**
043: * Sets the key that specifies the default persistence manager.
044: *
045: * @param key The default broker key
046: * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#setDefaultKey
047: */
048: public static void setDefaultKey(PBKey key) {
049: MetadataManager.getInstance().setDefaultPBKey(key);
050: }
051:
052: /**
053: * Returns the key that specifies the default persistence manager.
054: *
055: * @return The default broker key
056: * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#getDefaultKey
057: */
058: public static PBKey getDefaultKey() {
059: return MetadataManager.getInstance().getDefaultPBKey();
060: }
061:
062: /**
063: * Creates a default broker instance for the default broker key.
064: *
065: * @return The persistence broker
066: * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#defaultPersistenceBroker
067: */
068: public static PersistenceBroker defaultPersistenceBroker()
069: throws PBFactoryException {
070: return PersistenceBrokerFactoryFactory.instance()
071: .defaultPersistenceBroker();
072: }
073:
074: /**
075: * Creates a new broker instance.
076: *
077: * @param jcdAlias The jdbc connection descriptor name as defined in the repository
078: * @param user The user name to be used for connecting to the database
079: * @param password The password to be used for connecting to the database
080: * @return The persistence broker
081: * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#createPersistenceBroker(java.lang.String, java.lang.String, java.lang.String)
082: */
083: public static PersistenceBroker createPersistenceBroker(
084: String jcdAlias, String user, String password)
085: throws PBFactoryException {
086: return PersistenceBrokerFactoryFactory.instance()
087: .createPersistenceBroker(jcdAlias, user, password);
088: }
089:
090: /**
091: * Creates a new broker instance for the given key.
092: *
093: * @param key The broker key
094: * @return The persistence broker
095: * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#createPersistenceBroker(org.apache.ojb.broker.PBKey)
096: */
097: public static PersistenceBroker createPersistenceBroker(PBKey key)
098: throws PBFactoryException {
099: return PersistenceBrokerFactoryFactory.instance()
100: .createPersistenceBroker(key);
101: }
102:
103: /**
104: * Releases all broker instances pooled by this factory (if any). Note that the broker are
105: * closed prior to releasing them.
106: *
107: * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#releaseAllInstances
108: */
109: public static void releaseAllInstances() {
110: PersistenceBrokerFactoryFactory.instance()
111: .releaseAllInstances();
112: }
113:
114: /**
115: * Shuts OJB down, i.e. releases all resources. You should not use any OJB functionality
116: * after calling this method.
117: *
118: * @see org.apache.ojb.broker.core.PersistenceBrokerFactoryIF#shutdown()
119: */
120: public static void shutdown() {
121: PersistenceBrokerFactoryFactory.instance().shutdown();
122: }
123: }
|