Class TextProcPersistence
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).
-
Constructor Details
-
TextProcPersistence
public TextProcPersistence()
-
-
Method Details
-
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
Checks whether this persistence access layer is running. When not running, most method calls on it will throw aIllegalStateException
, as documented.- Returns:
- True if the persistence access layer is running, false otherwise.
-
start
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
- IfentityTypes
isnull
, or contains anull
element.
-
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
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
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 togetEntityManager()
will return new entity manager objects no matter what.- Throws:
java.lang.IllegalStateException
- If the application is not running.
-