Class PersistenceManagerFactory

java.lang.Object
alpine.server.persistence.PersistenceManagerFactory
All Implemented Interfaces:
IPersistenceManagerFactory, EventListener, javax.servlet.ServletContextListener

public class PersistenceManagerFactory extends Object implements IPersistenceManagerFactory, javax.servlet.ServletContextListener
Initializes the JDO persistence manager on server startup.
Since:
1.0.0
Author:
Steve Springett
  • Constructor Details

    • PersistenceManagerFactory

      public PersistenceManagerFactory()
  • Method Details

    • contextInitialized

      public void contextInitialized(javax.servlet.ServletContextEvent event)
      Specified by:
      contextInitialized in interface javax.servlet.ServletContextListener
    • contextDestroyed

      public void contextDestroyed(javax.servlet.ServletContextEvent event)
      Specified by:
      contextDestroyed in interface javax.servlet.ServletContextListener
    • createPersistenceManager

      public static javax.jdo.PersistenceManager createPersistenceManager()
      Creates a new JDO PersistenceManager.
      Returns:
      a PersistenceManager
    • getPersistenceManager

      public javax.jdo.PersistenceManager getPersistenceManager()
      Specified by:
      getPersistenceManager in interface IPersistenceManagerFactory
    • setJdoPersistenceManagerFactory

      public static void setJdoPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory pmf)
      Set the JDOPersistenceManagerFactory to be used by PersistenceManagerFactory.

      This is mainly useful for integration tests that run outside a servlet context, yet require a persistence context setup with an external database.

      Parameters:
      pmf - The JDOPersistenceManagerFactory to set
      Throws:
      IllegalStateException - When the JDOPersistenceManagerFactory was already initialized
      Since:
      2.1.0
    • tearDown

      public static void tearDown()
      Closes the JDOPersistenceManagerFactory and removes any reference to it.

      This method should be called in the tearDown method of unit- and integration tests that interact with the persistence layer.

      Since:
      2.1.0