java.lang.Object
es.uvigo.esei.sing.textproc.persistence.TextProcPersistence

public class TextProcPersistence
extends java.lang.Object
Entry point to the TextProc persistence access functionalities.
Author:
Alejandro González García
  • Constructor Summary

    Constructors 
    Constructor Description
    TextProcPersistence()  
  • Method Summary

    Modifier and Type Method Description
    void flushEntities()
    Commits the dirty transactions which were not rolled back, and then closes all the opened entity managers.
    static TextProcPersistence get()
    Returns the only instance of this class in the JVM.
    javax.persistence.EntityManager getEntityManager()
    Returns a entity manager ready for use for the current thread.
    boolean isRunning()
    Checks whether this persistence access layer is running.
    void start​(@NonNull java.util.Set<java.lang.Class<?>> entityTypes)
    Starts the TextProc persistence access layer, so it becomes ready to process data access operations.
    void stop()
    Stops the TextProc persistence access layer, so that all pending transactions are finished and no new data access operations can start until it is started again (if ever).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • get

      public static TextProcPersistence get()
      Returns the only instance of this class in the JVM. This method always returns the same object.
      Returns:
      The only instance of this class in the JVM.
    • isRunning

      public boolean isRunning()
      Checks whether this persistence access layer is running. When not running, most method calls on it will throw a IllegalStateException, as documented.
      Returns:
      True if the persistence access layer is running, false otherwise.
    • start

      public void start​(@NonNull @NonNull java.util.Set<java.lang.Class<?>> entityTypes)
      Starts the TextProc persistence access layer, so it becomes ready to process data access operations.
      Parameters:
      entityTypes - A set of entity types that the JPA provider will analyze, in order to make them available for use. The set doesn't need to be modifiable.
      Throws:
      javax.persistence.PersistenceException - If some error occurs while instantiating a entity manager factory for the persistence unit.
      java.lang.IllegalArgumentException - If entityTypes is null, or contains a null element.
    • stop

      public void stop()
      Stops the TextProc persistence access layer, so that all pending transactions are finished and no new data access operations can start until it is started again (if ever).
    • getEntityManager

      public javax.persistence.EntityManager getEntityManager()
      Returns a entity manager ready for use for the current thread. At any given time, there can be one entity manager per thread that requests one.
      Returns:
      The entity manager exclusive to the current thread.
      Throws:
      java.lang.IllegalStateException - If the persistence access layer is not running.
    • flushEntities

      public void flushEntities()
      Commits the dirty transactions which were not rolled back, and then closes all the opened entity managers. If other parts of the application are using entity transactions when this method is invoked, its outcome is undefined. Otherwise, when this method returns, no transaction or entity manager will remain to be committed, closed or strongly referenced by internal data structures (therefore, they can be garbage collected, barring strong references elsewhere). Subsequent calls to getEntityManager() will return new entity manager objects no matter what.
      Throws:
      java.lang.IllegalStateException - If the application is not running.