Package org.apache.openjpa.kernel
Class AbstractBrokerFactory
java.lang.Object
org.apache.openjpa.kernel.AbstractBrokerFactory
- All Implemented Interfaces:
Serializable,BrokerFactory,Closeable
- Direct Known Subclasses:
AbstractStoreBrokerFactory,JDBCBrokerFactory
Abstract implementation of the
BrokerFactory
that must be subclassed for a specific runtime.- Author:
- Abe White
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLifecycleListener(Object listener, Class<?>[] classes) Register a listener for lifecycle-related events on the specified classes.protected voidaddListeners(Broker broker) Add factory-registered lifecycle listeners to the broker.voidaddTransactionListener(Object listener) Register a listener for transaction-related events on the specified classes.voidThrow an exception if the factory is closed.voidclose()Close the factory.protected voidconfigureBroker(BrokerImpl broker) Configures the given broker with the current factory option settings.protected DelegatingStoreManagerCreate a DelegatingStoreManager for use with a Broker created by this factory.protected BrokerfindBroker(String user, String pass, boolean managed) Find a pooled broker, or return null if none.protected BrokerfindTransactionalBroker(String user, String pass) Find a managed runtime broker associated with the current transaction, or returns null if none.Return the configuration for this factory.protected ObjectReturn an object to be written to the log when this broker factory initializes.Returns a set of all the open brokers associated with this factory.static AbstractBrokerFactoryReturn the pooled factory matching the given key, or null if none.Subclasses should override this method to add aPlatformproperty listing the runtime platform, such as:OpenJPA JDBC Edition: Oracle DatabaseReturn all of the supported properties as a set of keys.getUserObject(Object key) Get the value for the specified key from the map of user objects.booleanisClosed()Returns true if this broker factory is closed.voidloadPersistentTypes(ClassLoader envLoader) Load the configured persistent classes list.voidlock()Synchronizes on an internal lock.voidFreezes the configuration of this factory.Return a broker with default settings.newBroker(boolean managed, int connRetainMode) Return a broker using the given credentials and in the given transaction and connection retain mode, optionally finding existing broker in the global transaction.newBroker(String user, String pass, boolean managed, int connRetainMode, boolean findExisting, String cf1Name, String cf2Name) Return a new broker using the supplied credentials transaction management mode connectionRetainMode connectionFactoriesprotected BrokerImplnewBrokerImpl(String user, String pass) Return a broker configured with the proper settings.protected abstract StoreManagerReturn a new StoreManager for this runtime.protected static voidpool(Object key, AbstractBrokerFactory factory) Registerfactoryin the pool underkey.voidThis method is invoked AFTER a BrokerFactory has been instantiated.putUserObject(Object key, Object val) Put the specified key-value pair into the map of user objects.protected ObjectReplaces the factory with this JVMs pooled version if it exists.protected voidreleaseBroker(BrokerImpl broker) Releasebrokerfrom any internal data structures.voidremoveLifecycleListener(Object listener) Remove a listener for lifecycle-related events.voidremoveTransactionListener(Object listener) Remove a listener for transaction-related events.protected voidsetup()Setup transient state used by this factory based on the current configuration, which will subsequently be locked down.protected static ObjectReturn an internal factory pool key for the given configuration.voidunlock()Release the internal lock.
-
Constructor Details
-
AbstractBrokerFactory
Constructor. Configuration must be provided on construction.
-
-
Method Details
-
toPoolKey
Return an internal factory pool key for the given configuration.- Since:
- 1.1.0
-
pool
Registerfactoryin the pool underkey.- Since:
- 1.1.0
-
getPooledFactoryForKey
Return the pooled factory matching the given key, or null if none. The key must be of the form created bygetPoolKey(). -
getConfiguration
Return the configuration for this factory.- Specified by:
getConfigurationin interfaceBrokerFactory
-
newBroker
Description copied from interface:BrokerFactoryReturn a broker with default settings.- Specified by:
newBrokerin interfaceBrokerFactory
-
newBroker
-
newBroker
-
newBroker
-
newBroker
public Broker newBroker(String user, String pass, boolean managed, int connRetainMode, boolean findExisting) Description copied from interface:BrokerFactoryReturn a broker using the given credentials and in the given transaction and connection retain mode, optionally finding existing broker in the global transaction.- Specified by:
newBrokerin interfaceBrokerFactory
-
newBroker
public Broker newBroker(String user, String pass, boolean managed, int connRetainMode, boolean findExisting, String cf1Name, String cf2Name) Description copied from interface:BrokerFactoryReturn a new broker using the supplied- credentials
- transaction management mode
- connectionRetainMode
- connectionFactories
- Specified by:
newBrokerin interfaceBrokerFactory- Parameters:
user- Username to use when obtaining a connection. Will be ignored if a connection factory is obtained from JNDI.pass- Password to use when obtaining a connection. Will be ignored if a connection factory is obtained from JNDI.managed- Whether managed transactions will be used by this BrokerconnRetainMode-ConnectionRetainModefindExisting- Whether the internal pool of brokers should be used.cf1Name- JTA ConnectionFactory to usecf2Name- Non-JTA ConnectionFactory to use.- Returns:
- A Broker which matches the provided criteria.
-
addListeners
Add factory-registered lifecycle listeners to the broker. -
loadPersistentTypes
Load the configured persistent classes list. Performed automatically whenever a broker is created. -
addLifecycleListener
Description copied from interface:BrokerFactoryRegister a listener for lifecycle-related events on the specified classes. If the classes are null, all events will be propagated to the listener. The listener will be passed on to all new brokers.- Specified by:
addLifecycleListenerin interfaceBrokerFactory
-
removeLifecycleListener
Description copied from interface:BrokerFactoryRemove a listener for lifecycle-related events.- Specified by:
removeLifecycleListenerin interfaceBrokerFactory
-
addTransactionListener
Description copied from interface:BrokerFactoryRegister a listener for transaction-related events on the specified classes. It will be registered with allBrokers created from this instance moving forward.- Specified by:
addTransactionListenerin interfaceBrokerFactory
-
removeTransactionListener
Description copied from interface:BrokerFactoryRemove a listener for transaction-related events. It will no longer be registered with newBrokers created from this instance.- Specified by:
removeTransactionListenerin interfaceBrokerFactory
-
isClosed
public boolean isClosed()Returns true if this broker factory is closed.- Specified by:
isClosedin interfaceBrokerFactory
-
close
public void close()Description copied from interface:BrokerFactoryClose the factory.- Specified by:
closein interfaceBrokerFactory- Specified by:
closein interfaceCloseable
-
getProperties
Subclasses should override this method to add aPlatformproperty listing the runtime platform, such as:OpenJPA JDBC Edition: Oracle Database- Specified by:
getPropertiesin interfaceBrokerFactory
-
getSupportedProperties
Description copied from interface:BrokerFactoryReturn all of the supported properties as a set of keys. If a property has multiple keys, all keys will be returned.- Specified by:
getSupportedPropertiesin interfaceBrokerFactory
-
getUserObject
Description copied from interface:BrokerFactoryGet the value for the specified key from the map of user objects.- Specified by:
getUserObjectin interfaceBrokerFactory
-
putUserObject
Description copied from interface:BrokerFactoryPut the specified key-value pair into the map of user objects.- Specified by:
putUserObjectin interfaceBrokerFactory
-
lock
public void lock()Description copied from interface:BrokerFactorySynchronizes on an internal lock.- Specified by:
lockin interfaceBrokerFactory
-
unlock
public void unlock()Description copied from interface:BrokerFactoryRelease the internal lock.- Specified by:
unlockin interfaceBrokerFactory
-
readResolve
Replaces the factory with this JVMs pooled version if it exists. Also freezes the factory.- Throws:
ObjectStreamException
-
newStoreManager
Return a new StoreManager for this runtime. Note that the instance returned here may be wrapped before being passed to thenewBroker()method. -
findBroker
Find a pooled broker, or return null if none. If using managed transactions, looks for a transactional broker; otherwise returns null by default. This method will be called beforenewStoreManager()so that factory subclasses implementing pooling can return a matching manager before a newStoreManageris created. -
newBrokerImpl
Return a broker configured with the proper settings. By default, this method constructs a new BrokerImpl of the class set for this factory. -
setup
protected void setup()Setup transient state used by this factory based on the current configuration, which will subsequently be locked down. This method will be called before the first broker is requested, and will be re-called each time the factory is deserialized into a JVM that has no configuration for this data store. -
findTransactionalBroker
Find a managed runtime broker associated with the current transaction, or returns null if none. -
configureBroker
Configures the given broker with the current factory option settings. -
makeReadOnly
public void makeReadOnly()Freezes the configuration of this factory. -
getFactoryInitializationBanner
Return an object to be written to the log when this broker factory initializes. This happens after the configuration is fully loaded. -
assertOpen
public void assertOpen()Throw an exception if the factory is closed. The exact message and content of the exception varies whether TRACE is enabled or not.- Specified by:
assertOpenin interfaceBrokerFactory
-
getOpenBrokers
Returns a set of all the open brokers associated with this factory. The returned set is unmodifiable, and may contain null references. -
releaseBroker
Releasebrokerfrom any internal data structures. This is invoked bybrokerafter the broker is fully closed.- Since:
- 1.1.0
-
getPoolKey
- Returns:
- a key that can be used to obtain this broker factory from the pool at a later time.
- Since:
- 1.1.0
-
createDelegatingStoreManager
Create a DelegatingStoreManager for use with a Broker created by this factory. If a DataCache has been enabled a DataCacheStoreManager will be returned.
If no DataCache is in use an ROPStoreManager will be returned.
- Returns:
- A delegating store manager suitable for the current configuration.
-
postCreationCallback
public void postCreationCallback()This method is invoked AFTER a BrokerFactory has been instantiated.- Specified by:
postCreationCallbackin interfaceBrokerFactory
-