Class 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 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

    • 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
      • memoryInfo

        public static String memoryInfo​(String title,
                                        boolean doGc)
      • 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)