Package org.apache.openjpa.kernel
Class DelegatingBrokerFactory
- java.lang.Object
-
- org.apache.openjpa.kernel.DelegatingBrokerFactory
-
- All Implemented Interfaces:
java.io.Serializable
,BrokerFactory
,Closeable
public class DelegatingBrokerFactory extends java.lang.Object implements BrokerFactory
Delegating broker factory that can also perform exception translation for use in facades.- Since:
- 0.4.0
- Author:
- Abe White
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DelegatingBrokerFactory(BrokerFactory factory)
Constructor; supply delegate.DelegatingBrokerFactory(BrokerFactory factory, RuntimeExceptionTranslator trans)
Constructor; supply delegate and exception translator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLifecycleListener(java.lang.Object listener, java.lang.Class[] classes)
Register a listener for lifecycle-related events on the specified classes.void
addTransactionListener(java.lang.Object listener)
Register a listener for transaction-related events on the specified classes.void
assertOpen()
assert that this broker is open.void
close()
Close the factory.boolean
equals(java.lang.Object other)
OpenJPAConfiguration
getConfiguration()
Return the configuration for this factory.BrokerFactory
getDelegate()
Return the direct delegate.BrokerFactory
getInnermostDelegate()
Return the native delegate.java.util.Map<java.lang.String,java.lang.Object>
getProperties()
Return properties describing this runtime.java.util.Set<java.lang.String>
getSupportedProperties()
Return all of the supported properties as a set of keys.java.lang.Object
getUserObject(java.lang.Object key)
Get the value for the specified key from the map of user objects.int
hashCode()
boolean
isClosed()
Returns true if this broker factory is closed.void
lock()
Synchronizes on an internal lock.Broker
newBroker()
Return a broker with default settings.Broker
newBroker(java.lang.String user, java.lang.String pass, boolean managed, int connRetainMode, boolean findExisting)
Return a broker using the given credentials and in the given transaction and connection retain mode, optionally finding existing broker in the global transaction.Broker
newBroker(java.lang.String user, java.lang.String pass, boolean managed, int connRetainMode, boolean findExisting, java.lang.String cfName, java.lang.String cf2Name)
Return a new broker using the supplied credentials transaction management mode connectionRetainMode connectionFactoriesvoid
postCreationCallback()
This method is invoked AFTER a BrokerFactory has been instantiated.java.lang.Object
putUserObject(java.lang.Object key, java.lang.Object val)
Put the specified key-value pair into the map of user objects.void
removeLifecycleListener(java.lang.Object listener)
Remove a listener for lifecycle-related events.void
removeTransactionListener(java.lang.Object listener)
Remove a listener for transaction-related events.protected java.lang.RuntimeException
translate(java.lang.RuntimeException re)
Translate the OpenJPA exception.void
unlock()
Release the internal lock.
-
-
-
Constructor Detail
-
DelegatingBrokerFactory
public DelegatingBrokerFactory(BrokerFactory factory)
Constructor; supply delegate.
-
DelegatingBrokerFactory
public DelegatingBrokerFactory(BrokerFactory factory, RuntimeExceptionTranslator trans)
Constructor; supply delegate and exception translator.
-
-
Method Detail
-
getDelegate
public BrokerFactory getDelegate()
Return the direct delegate.
-
getInnermostDelegate
public BrokerFactory getInnermostDelegate()
Return the native delegate.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
translate
protected java.lang.RuntimeException translate(java.lang.RuntimeException re)
Translate the OpenJPA exception.
-
getConfiguration
public OpenJPAConfiguration getConfiguration()
Description copied from interface:BrokerFactory
Return the configuration for this factory.- Specified by:
getConfiguration
in interfaceBrokerFactory
-
getProperties
public java.util.Map<java.lang.String,java.lang.Object> getProperties()
Description copied from interface:BrokerFactory
Return properties describing this runtime.- Specified by:
getProperties
in interfaceBrokerFactory
-
getSupportedProperties
public java.util.Set<java.lang.String> getSupportedProperties()
Description copied from interface:BrokerFactory
Return all of the supported properties as a set of keys. If a property has multiple keys, all keys will be returned.- Specified by:
getSupportedProperties
in interfaceBrokerFactory
-
putUserObject
public java.lang.Object putUserObject(java.lang.Object key, java.lang.Object val)
Description copied from interface:BrokerFactory
Put the specified key-value pair into the map of user objects.- Specified by:
putUserObject
in interfaceBrokerFactory
-
getUserObject
public java.lang.Object getUserObject(java.lang.Object key)
Description copied from interface:BrokerFactory
Get the value for the specified key from the map of user objects.- Specified by:
getUserObject
in interfaceBrokerFactory
-
newBroker
public Broker newBroker()
Description copied from interface:BrokerFactory
Return a broker with default settings.- Specified by:
newBroker
in interfaceBrokerFactory
-
newBroker
public Broker newBroker(java.lang.String user, java.lang.String pass, boolean managed, int connRetainMode, boolean findExisting)
Description copied from interface:BrokerFactory
Return 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:
newBroker
in interfaceBrokerFactory
-
newBroker
public Broker newBroker(java.lang.String user, java.lang.String pass, boolean managed, int connRetainMode, boolean findExisting, java.lang.String cfName, java.lang.String cf2Name)
Description copied from interface:BrokerFactory
Return a new broker using the supplied- credentials
- transaction management mode
- connectionRetainMode
- connectionFactories
- Specified by:
newBroker
in 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
-ConnectionRetainMode
findExisting
- Whether the internal pool of brokers should be used.cfName
- JTA ConnectionFactory to usecf2Name
- Non-JTA ConnectionFactory to use.- Returns:
- A Broker which matches the provided criteria.
-
addLifecycleListener
public void addLifecycleListener(java.lang.Object listener, java.lang.Class[] classes)
Description copied from interface:BrokerFactory
Register 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:
addLifecycleListener
in interfaceBrokerFactory
-
removeLifecycleListener
public void removeLifecycleListener(java.lang.Object listener)
Description copied from interface:BrokerFactory
Remove a listener for lifecycle-related events.- Specified by:
removeLifecycleListener
in interfaceBrokerFactory
-
addTransactionListener
public void addTransactionListener(java.lang.Object listener)
Description copied from interface:BrokerFactory
Register a listener for transaction-related events on the specified classes. It will be registered with allBroker
s created from this instance moving forward.- Specified by:
addTransactionListener
in interfaceBrokerFactory
-
removeTransactionListener
public void removeTransactionListener(java.lang.Object listener)
Description copied from interface:BrokerFactory
Remove a listener for transaction-related events. It will no longer be registered with newBroker
s created from this instance.- Specified by:
removeTransactionListener
in interfaceBrokerFactory
-
close
public void close()
Description copied from interface:BrokerFactory
Close the factory.- Specified by:
close
in interfaceBrokerFactory
- Specified by:
close
in interfaceCloseable
-
isClosed
public boolean isClosed()
Description copied from interface:BrokerFactory
Returns true if this broker factory is closed.- Specified by:
isClosed
in interfaceBrokerFactory
-
lock
public void lock()
Description copied from interface:BrokerFactory
Synchronizes on an internal lock.- Specified by:
lock
in interfaceBrokerFactory
-
unlock
public void unlock()
Description copied from interface:BrokerFactory
Release the internal lock.- Specified by:
unlock
in interfaceBrokerFactory
-
assertOpen
public void assertOpen()
Description copied from interface:BrokerFactory
assert that this broker is open. If the broker has been closed an IllegalStateException will be thrown with information on when the broker was closed.- Specified by:
assertOpen
in interfaceBrokerFactory
-
postCreationCallback
public void postCreationCallback()
Description copied from interface:BrokerFactory
This method is invoked AFTER a BrokerFactory has been instantiated.- Specified by:
postCreationCallback
in interfaceBrokerFactory
-
-