Package edu.wisc.game.sql
Class Main
java.lang.Object
edu.wisc.game.sql.Main
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
FieldsModifier and TypeFieldDescriptionstatic final String
This name will be used to configure the EntityManagerFactory based on the corresponding name in the META-INF/persistence.xml file -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionjavax.persistence.EntityManager
doGetEM()
javax.persistence.EntityManager
void
doPersistObjects
(Object... v) <T> void
doSaveObject
(T o) static javax.persistence.EntityManager
getEM()
Creates a new EntityManager from the EntityManagerFactory.static int
getMyPid()
Finds the process id of the UNIX process for this application.static javax.persistence.EntityManager
getNewEM()
static void
memory()
Reports memory usestatic void
Reports memory usestatic String
memoryInfo
(String title, boolean doGc) 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.static <T> void
saveObject
(T o) toString()
-
Field Details
-
persistenceUnitName
This name will be used to configure the EntityManagerFactory based on the corresponding name in the META-INF/persistence.xml file- See Also:
-
-
Constructor Details
-
Main
-
-
Method Details
-
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
Reports memory use -
memoryInfo
-
persistObjects
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
-
saveObject
public static <T> void saveObject(T o) - Parameters:
o
- a detached object
-
doSaveObject
public <T> void doSaveObject(T o) -
toString
-