Class AbstractBrokerFactory

    • Method Summary

      All Methods Static Methods Instance Methods Abstract 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.
      protected void addListeners​(Broker broker)
      Add factory-registered lifecycle listeners to the broker.
      void addTransactionListener​(java.lang.Object listener)
      Register a listener for transaction-related events on the specified classes.
      void assertOpen()
      Throw an exception if the factory is closed.
      void close()
      Close the factory.
      protected void configureBroker​(BrokerImpl broker)
      Configures the given broker with the current factory option settings.
      protected DelegatingStoreManager createDelegatingStoreManager()
      Create a DelegatingStoreManager for use with a Broker created by this factory.
      protected Broker findBroker​(java.lang.String user, java.lang.String pass, boolean managed)
      Find a pooled broker, or return null if none.
      protected Broker findTransactionalBroker​(java.lang.String user, java.lang.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 java.lang.Object getFactoryInitializationBanner()
      Return an object to be written to the log when this broker factory initializes.
      java.util.Collection<Broker> getOpenBrokers()
      Returns a set of all the open brokers associated with this factory.
      static AbstractBrokerFactory getPooledFactoryForKey​(java.lang.Object key)
      Return the pooled factory matching the given key, or null if none.
      java.lang.Object getPoolKey()  
      java.util.Map<java.lang.String,​java.lang.Object> getProperties()
      Subclasses should override this method to add a Platform property listing the runtime platform, such as: OpenJPA JDBC Edition: Oracle Database
      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.
      boolean isClosed()
      Returns true if this broker factory is closed.
      void loadPersistentTypes​(java.lang.ClassLoader envLoader)
      Load the configured persistent classes list.
      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​(java.lang.String user, java.lang.String pass)  
      Broker newBroker​(java.lang.String user, java.lang.String pass, boolean managed, int connRetainMode)  
      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 cf1Name, java.lang.String cf2Name)
      Return a new broker using the supplied credentials transaction management mode connectionRetainMode connectionFactories
      protected BrokerImpl newBrokerImpl​(java.lang.String user, java.lang.String pass)
      Return a broker configured with the proper settings.
      protected abstract StoreManager newStoreManager()
      Return a new StoreManager for this runtime.
      protected static void pool​(java.lang.Object key, AbstractBrokerFactory factory)
      Register factory in the pool under key.
      void 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.
      protected java.lang.Object readResolve()
      Replaces the factory with this JVMs pooled version if it exists.
      protected void releaseBroker​(BrokerImpl broker)
      Release broker from any internal data structures.
      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 void setup()
      Setup transient state used by this factory based on the current configuration, which will subsequently be locked down.
      protected static java.lang.Object toPoolKey​(java.util.Map<java.lang.String,​java.lang.Object> map)
      Return an internal factory pool key for the given configuration.
      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

      • toPoolKey

        protected static java.lang.Object toPoolKey​(java.util.Map<java.lang.String,​java.lang.Object> map)
        Return an internal factory pool key for the given configuration.
        Since:
        1.1.0
      • pool

        protected static void pool​(java.lang.Object key,
                                   AbstractBrokerFactory factory)
        Register factory in the pool under key.
        Since:
        1.1.0
      • getPooledFactoryForKey

        public static AbstractBrokerFactory getPooledFactoryForKey​(java.lang.Object key)
        Return the pooled factory matching the given key, or null if none. The key must be of the form created by getPoolKey().
      • newBroker

        public Broker newBroker​(java.lang.String user,
                                java.lang.String pass)
      • newBroker

        public Broker newBroker​(boolean managed,
                                int connRetainMode)
      • newBroker

        public Broker newBroker​(java.lang.String user,
                                java.lang.String pass,
                                boolean managed,
                                int connRetainMode)
      • 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 interface BrokerFactory
      • newBroker

        public Broker newBroker​(java.lang.String user,
                                java.lang.String pass,
                                boolean managed,
                                int connRetainMode,
                                boolean findExisting,
                                java.lang.String cf1Name,
                                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 interface BrokerFactory
        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 Broker
        connRetainMode - ConnectionRetainMode
        findExisting - Whether the internal pool of brokers should be used.
        cf1Name - JTA ConnectionFactory to use
        cf2Name - Non-JTA ConnectionFactory to use.
        Returns:
        A Broker which matches the provided criteria.
      • addListeners

        protected void addListeners​(Broker broker)
        Add factory-registered lifecycle listeners to the broker.
      • loadPersistentTypes

        public void loadPersistentTypes​(java.lang.ClassLoader envLoader)
        Load the configured persistent classes list. Performed automatically whenever a broker is created.
      • 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 interface BrokerFactory
      • removeLifecycleListener

        public void removeLifecycleListener​(java.lang.Object listener)
        Description copied from interface: BrokerFactory
        Remove a listener for lifecycle-related events.
        Specified by:
        removeLifecycleListener in interface BrokerFactory
      • 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 all Brokers created from this instance moving forward.
        Specified by:
        addTransactionListener in interface BrokerFactory
      • 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 new Brokers created from this instance.
        Specified by:
        removeTransactionListener in interface BrokerFactory
      • isClosed

        public boolean isClosed()
        Returns true if this broker factory is closed.
        Specified by:
        isClosed in interface BrokerFactory
      • getProperties

        public java.util.Map<java.lang.String,​java.lang.Object> 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
      • 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 interface BrokerFactory
      • 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 interface BrokerFactory
      • 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 interface BrokerFactory
      • lock

        public void lock()
        Description copied from interface: BrokerFactory
        Synchronizes on an internal lock.
        Specified by:
        lock in interface BrokerFactory
      • readResolve

        protected java.lang.Object readResolve()
                                        throws java.io.ObjectStreamException
        Replaces the factory with this JVMs pooled version if it exists. Also freezes the factory.
        Throws:
        java.io.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 Broker findBroker​(java.lang.String user,
                                    java.lang.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​(java.lang.String user,
                                           java.lang.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 Broker findTransactionalBroker​(java.lang.String user,
                                                 java.lang.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.
      • makeReadOnly

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

        protected java.lang.Object 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:
        assertOpen in interface BrokerFactory
      • getOpenBrokers

        public java.util.Collection<Broker> getOpenBrokers()
        Returns a set of all the open brokers associated with this factory. The returned set is unmodifiable, and may contain null references.
      • releaseBroker

        protected void releaseBroker​(BrokerImpl broker)
        Release broker from any internal data structures. This is invoked by broker after the broker is fully closed.
        Since:
        1.1.0
      • getPoolKey

        public java.lang.Object 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

        protected DelegatingStoreManager 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:
        postCreationCallback in interface BrokerFactory