Package edu.wisc.game.sql
Class Main
- java.lang.Object
-
- edu.wisc.game.sql.Main
-
public class Main extends Object
An object that is responsible for getting EntityManager object(s) for the application. Normally, an app would have just 1 instance of Main (Main.oneMain), because we work with just 1 database. Only applications that work with 2 (or more) databases, e.g. copying data between databases, would need additional instances of Main.
-
-
Field Summary
Fields Modifier and Type Field Description static StringpersistenceUnitNameThis name will be used to configure the EntityManagerFactory based on the corresponding name in the META-INF/persistence.xml file
-
Constructor Summary
Constructors Constructor Description Main(MainConfig _config)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.persistence.EntityManagerdoGetEM()javax.persistence.EntityManagerdoGetNewEM()voiddoPersistObjects(Object... v)<T> voiddoSaveObject(T o)static javax.persistence.EntityManagergetEM()Creates a new EntityManager from the EntityManagerFactory.static intgetMyPid()Finds the process id of the UNIX process for this application.static javax.persistence.EntityManagergetNewEM()static voidmemory()Reports memory usestatic voidmemory(String title)Reports memory usestatic StringmemoryInfo(String title, boolean doGc)static voidpersistObjects(Object... v)See also https://download.oracle.com/otn-pub/jcp/persistence-2_1-fr-eval-spec/JavaPersistence.pdf, which says (in "3.2.2 Persisting an Entity Instance"): If X is a new entity, it becomes managed.static <T> voidsaveObject(T o)StringtoString()
-
-
-
Field Detail
-
persistenceUnitName
public static final String persistenceUnitName
This name will be used to configure the EntityManagerFactory based on the corresponding name in the META-INF/persistence.xml file- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Main
public Main(MainConfig _config)
-
-
Method Detail
-
getMyPid
public static int getMyPid()
Finds the process id of the UNIX process for this application. FIXME: This obviously is non-portable outside of UNIX.- Returns:
- PID, or -1 on failure
-
getEM
public static javax.persistence.EntityManager getEM()
Creates a new EntityManager from the EntityManagerFactory.
-
doGetEM
public javax.persistence.EntityManager doGetEM()
-
getNewEM
public static javax.persistence.EntityManager getNewEM()
-
doGetNewEM
public javax.persistence.EntityManager doGetNewEM()
-
memory
public static void memory()
Reports memory use
-
memory
public static void memory(String title)
Reports memory use
-
persistObjects
public static void persistObjects(Object... v)
See also https://download.oracle.com/otn-pub/jcp/persistence-2_1-fr-eval-spec/JavaPersistence.pdf, which says (in "3.2.2 Persisting an Entity Instance"):- If X is a new entity, it becomes managed. The entity X will be entered into the database at or before transaction commit or as a result of the flush operation.
- If X is a preexisting managed entity, it is ignored by the persist operation (...)
- If X is a detached object, the EntityExistsException may be thrown when the persist operation is invoked, or the EntityExistsException or another PersistenceException may be thrown at flush or commit time
-
doPersistObjects
public void doPersistObjects(Object... v)
-
saveObject
public static <T> void saveObject(T o)
- Parameters:
o- a detached object
-
doSaveObject
public <T> void doSaveObject(T o)
-
-