org.apache.openjpa.kernel
Class AbstractBrokerFactory

java.lang.Object
  extended by org.apache.openjpa.kernel.AbstractBrokerFactory
All Implemented Interfaces:
Serializable, BrokerFactory, Closeable
Direct Known Subclasses:
AbstractStoreBrokerFactory, JDBCBrokerFactory

public abstract class AbstractBrokerFactory
extends Object
implements BrokerFactory

Abstract implementation of the BrokerFactory that must be subclassed for a specific runtime.

Author:
Abe White
See Also:
Serialized Form

Constructor Summary
protected AbstractBrokerFactory(OpenJPAConfiguration config)
          Constructor.
 
Method Summary
 void addLifecycleListener(Object listener, Class[] classes)
          Register a listener for lifecycle-related events on the specified classes.
protected  void addLifecycleListeners(BrokerImpl broker)
          Add factory-registered lifecycle listeners to the broker.
 void close()
          Close the factory.
protected  void configureBroker(BrokerImpl broker)
          Configures the given broker with the current factory option settings.
protected  BrokerImpl findBroker(String user, String pass, boolean managed)
          Find a pooled broker, or return null if none.
protected  BrokerImpl findTransactionalBroker(String user, String pass)
          Find a managed runtime broker associated with the current transaction, or returns null if none.
 OpenJPAConfiguration getConfiguration()
          Return the configuration for this factory.
protected  Object getFactoryInitializationBanner()
          Return an object to be written to the log when this broker factory initializes.
protected static AbstractBrokerFactory getPooledFactory(Map map)
          Return the pooled factory matching the given configuration data, or null if none.
static AbstractBrokerFactory getPooledFactory(OpenJPAConfiguration conf)
          Return the pooled factory matching the given configuration, or null if none.
 Properties getProperties()
          Subclasses should override this method to add a Platform property listing the runtime platform, such as: OpenJPA JDBC Edition: Oracle Database
 Object getUserObject(Object key)
          Get the value for the specified key from the map of user objects.
 boolean isClosed()
          Returns true if this broker factory is closed.
 void lock()
          Synchronizes on an internal lock.
 void makeReadOnly()
          Freezes the configuration of this factory.
 Broker newBroker()
          Return a broker with default settings.
 Broker newBroker(boolean managed, int connRetainMode)
           
 Broker newBroker(String user, String pass)
           
 Broker newBroker(String user, String pass, boolean managed, int connRetainMode)
           
 Broker newBroker(String user, 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.
protected  BrokerImpl newBrokerImpl(String user, String pass)
          Return a broker configured with the proper settings.
protected abstract  StoreManager newStoreManager()
          Return a new StoreManager for this runtime.
protected  void pool()
          Add the factory to the pool.
 Object putUserObject(Object key, Object val)
          Put the specified key-value pair into the map of user objects.
protected  Object readResolve()
          Replaces the factory with this JVMs pooled version if it exists.
 void removeLifecycleListener(Object listener)
          Remove a listener for lifecycle-related events.
protected  void setup()
          Setup transient state used by this factory based on the current configuration, which will subsequently be locked down.
 void unlock()
          Release the internal lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractBrokerFactory

protected AbstractBrokerFactory(OpenJPAConfiguration config)
Constructor. Configuration must be provided on construction.

Method Detail

getPooledFactory

public static AbstractBrokerFactory getPooledFactory(OpenJPAConfiguration conf)
Return the pooled factory matching the given configuration, or null if none.


getPooledFactory

protected static AbstractBrokerFactory getPooledFactory(Map map)
Return the pooled factory matching the given configuration data, or null if none.


getConfiguration

public OpenJPAConfiguration getConfiguration()
Return the configuration for this factory.

Specified by:
getConfiguration in interface BrokerFactory

newBroker

public Broker newBroker()
Description copied from interface: BrokerFactory
Return a broker with default settings.

Specified by:
newBroker in interface BrokerFactory

newBroker

public Broker newBroker(String user,
                        String pass)

newBroker

public Broker newBroker(boolean managed,
                        int connRetainMode)

newBroker

public Broker newBroker(String user,
                        String pass,
                        boolean managed,
                        int connRetainMode)

newBroker

public Broker newBroker(String user,
                        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 interface BrokerFactory

addLifecycleListeners

protected void addLifecycleListeners(BrokerImpl broker)
Add factory-registered lifecycle listeners to the broker.


addLifecycleListener

public void addLifecycleListener(Object listener,
                                 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 interface BrokerFactory

removeLifecycleListener

public void removeLifecycleListener(Object listener)
Description copied from interface: BrokerFactory
Remove a listener for lifecycle-related events.

Specified by:
removeLifecycleListener in interface BrokerFactory

isClosed

public boolean isClosed()
Returns true if this broker factory is closed.

Specified by:
isClosed in interface BrokerFactory

close

public void close()
Description copied from interface: BrokerFactory
Close the factory.

Specified by:
close in interface BrokerFactory
Specified by:
close in interface Closeable

getProperties

public Properties getProperties()
Subclasses should override this method to add a Platform property listing the runtime platform, such as: OpenJPA JDBC Edition: Oracle Database

Specified by:
getProperties in interface BrokerFactory

getUserObject

public Object getUserObject(Object key)
Description copied from interface: BrokerFactory
Get the value for the specified key from the map of user objects.

Specified by:
getUserObject in interface BrokerFactory

putUserObject

public Object putUserObject(Object key,
                            Object val)
Description copied from interface: BrokerFactory
Put the specified key-value pair into the map of user objects.

Specified by:
putUserObject in interface BrokerFactory

lock

public void lock()
Description copied from interface: BrokerFactory
Synchronizes on an internal lock.

Specified by:
lock in interface BrokerFactory

unlock

public void unlock()
Description copied from interface: BrokerFactory
Release the internal lock.

Specified by:
unlock in interface BrokerFactory

readResolve

protected Object readResolve()
                      throws ObjectStreamException
Replaces the factory with this JVMs pooled version if it exists. Also freezes the factory.

Throws:
ObjectStreamException

newStoreManager

protected abstract StoreManager newStoreManager()
Return a new StoreManager for this runtime. Note that the instance returned here may be wrapped before being passed to the newBroker() method.


findBroker

protected BrokerImpl findBroker(String user,
                                String pass,
                                boolean managed)
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 before newStoreManager() so that factory subclasses implementing pooling can return a matching manager before a new StoreManager is created.


newBrokerImpl

protected BrokerImpl newBrokerImpl(String user,
                                   String pass)
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

protected BrokerImpl findTransactionalBroker(String user,
                                             String pass)
Find a managed runtime broker associated with the current transaction, or returns null if none.


configureBroker

protected void configureBroker(BrokerImpl broker)
Configures the given broker with the current factory option settings.


pool

protected void pool()
Add the factory to the pool.


makeReadOnly

public void makeReadOnly()
Freezes the configuration of this factory.


getFactoryInitializationBanner

protected Object getFactoryInitializationBanner()
Return an object to be written to the log when this broker factory initializes. This happens after the configuration is fully loaded.



Copyright © 2006 Apache Software Foundation. All Rights Reserved.