Class OSGiManagedRuntime

java.lang.Object
org.apache.openjpa.ee.AbstractManagedRuntime
org.apache.openjpa.ee.OSGiManagedRuntime
All Implemented Interfaces:
ManagedRuntime

public class OSGiManagedRuntime extends AbstractManagedRuntime

Implementation of the ManagedRuntime interface that listens for an OSGi service with interface jakarta.transaction.TransactionManager to create a TransactionManager for controlling transactions.

The support for a transaction manager is usually activated inside an OSGi BundleActivator implementation using registerServiceListener(BundleContext) and deregisterServiceListener(BundleContext).

  • Constructor Details

    • OSGiManagedRuntime

      public OSGiManagedRuntime()
  • Method Details

    • registerServiceListener

      public static void registerServiceListener(org.osgi.framework.BundleContext bundleContext) throws org.osgi.framework.InvalidSyntaxException

      Register a service listener to the given bundle context by BundleContext.addServiceListener(ServiceListener,String) with a filter expression of (objectClass=jakarta.transaction.TransactionManager).

      The caller is responsible for calling deregisterServiceListener(BundleContext), when the bundle context is being stopped.

      Parameters:
      bundle - The bundle, which is currently being started.
      Throws:
      org.osgi.framework.InvalidSyntaxException - When the filter expression is invalid.
    • deregisterServiceListener

      public static void deregisterServiceListener(org.osgi.framework.BundleContext bundleContext)
      Remove a service listener previously started inside registerServiceListener(BundleContext).
      Parameters:
      bundleContext - The bundle context to call BundleContext.removeServiceListener(ServiceListener) on.
    • getTransactionManager

      public jakarta.transaction.TransactionManager getTransactionManager() throws Exception
      Description copied from interface: ManagedRuntime
      Return the TransactionManager for the managed runtime. This manager is used to register synchronization listeners, to map transactional PersistenceManagers to the current transaction, and possibly to enlist XA resources.
      Throws:
      Exception
    • setRollbackOnly

      public void setRollbackOnly(Throwable cause) throws Exception
      Description copied from interface: ManagedRuntime
      Sets the rollback only flag on the current transaction. If the TransactionManager is capable of tracking the cause of the rollback-only flag, it will also pass along cause information.
      Parameters:
      cause - the Throwable that caused the transaction to be marked for rollback, or null of none is known
      Throws:
      Exception
    • getRollbackCause

      public Throwable getRollbackCause() throws Exception
      Description copied from interface: ManagedRuntime
      Returns the Throwable that caused the current transaction to be marked for rollback, provided that any exists.
      Returns:
      the Throwable cause, or null if none
      Throws:
      Exception