Class SessionFactoryUtil


  • public class SessionFactoryUtil
    extends Object
    Utility methods for a SessionFactory.
    Author:
    Rick O'Sullivan
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Map<String,​Object> gatherProperties​(javax.persistence.EntityManagerFactory emf)
      Gather configurable properties from the SessionFactory context for the given EntityManagerFactory.
      static Map<String,​Object> gatherProperties​(javax.persistence.EntityManagerFactory emf, Map<String,​Object> emfProperties)
      Gather configurable properties from the SessionFactory context for the given EntityManagerFactory.
      static Map<String,​Object> gatherProperties​(org.hibernate.SessionFactory sf, Map<String,​Object> emfProperties)
      Gather the Hibernate configurable SessionFactory properties from an SessionFactory instance.
      static boolean isInitialized​(Object proxy)
      Check if the proxy or persistent collection is initialized.
      static boolean isProxy​(Object entity)
      Is this entity a proxy?
      static boolean logSummaryStatistics​(javax.persistence.EntityManagerFactory emf)
      Exposes statistics for a particular SessionFactory.
      static int sqlAction​(javax.persistence.EntityManagerFactory emf, String sqlAction)
      Execute a SQL action (insert, update, delete, etc.) using a connection provided by a JPA EntityManagerFactory.
      static int sqlAction​(org.hibernate.SessionFactory sf, String sqlAction)
      Execute a SQL action (insert, update, delete, etc.) using a connection provided by a Hibernate SessionFactory.
      static int[] sqlBatch​(javax.persistence.EntityManagerFactory emf, List<String> sqlBatch)
      Execute a JDBC batch of SQL actions (insert, update, delete, etc.) using a connection provided by a Hibernate SessionFactory.
      static int[] sqlBatch​(org.hibernate.SessionFactory sf, List<String> sqlBatch)
      Execute a JDBC batch of SQL actions (insert, update, delete, etc.) using a connection provided by a Hibernate SessionFactory.
      static Map<String,​List<Object>> sqlQuery​(javax.persistence.EntityManagerFactory emf, String sql)
      Execute a JDBC query using a connection provided by a JPA EntityManagerFactory.
      static Map<String,​List<Object>> sqlQuery​(org.hibernate.SessionFactory sf, String sql)
      Execute a JDBC query using a connection provided by a Hibernate SessionFactory.
    • Constructor Detail

      • SessionFactoryUtil

        public SessionFactoryUtil()
    • Method Detail

      • gatherProperties

        public static Map<String,​Object> gatherProperties​(javax.persistence.EntityManagerFactory emf)
        Gather configurable properties from the SessionFactory context for the given EntityManagerFactory.
        Parameters:
        emf - An EntityManagerFactory instance.
        Returns:
        A map of configurable properties with current values.
      • gatherProperties

        public static Map<String,​Object> gatherProperties​(javax.persistence.EntityManagerFactory emf,
                                                                Map<String,​Object> emfProperties)
        Gather configurable properties from the SessionFactory context for the given EntityManagerFactory.
        Parameters:
        emf - An EntityManagerFactory instance.
        emfProperties - A map of the initial (or filtered) EntityManagerFactory properties.
        Returns:
        A map of configurable properties with current values.
      • gatherProperties

        public static Map<String,​Object> gatherProperties​(org.hibernate.SessionFactory sf,
                                                                Map<String,​Object> emfProperties)
        Gather the Hibernate configurable SessionFactory properties from an SessionFactory instance.
        Parameters:
        sf - A Hibernate SessionFactory instance.
        emfProperties - A map of the initial (or filtered) EntityManagerFactory properties.
        Returns:
        A map of properties representing the configurable Hibernate external properties.
      • isInitialized

        public static boolean isInitialized​(Object proxy)
        Check if the proxy or persistent collection is initialized.
        Parameters:
        proxy - a persistable object, proxy, persistent collection or null.
        Returns:
        true if the argument is already initialized, or is not a proxy or collection
      • isProxy

        public static boolean isProxy​(Object entity)
        Is this entity a proxy?
        Parameters:
        entity - The entity to examine.
        Returns:
        True when entity is proxied; otherwise, false.
      • logSummaryStatistics

        public static boolean logSummaryStatistics​(javax.persistence.EntityManagerFactory emf)
        Exposes statistics for a particular SessionFactory. Beware of milliseconds metrics, they are dependent of the JVM precision: you may then encounter a 10 ms approximation depending on you OS platform. Please refer to the JVM documentation for more information.
        Parameters:
        emf - An Entity Manager Factory.
      • sqlAction

        public static int sqlAction​(javax.persistence.EntityManagerFactory emf,
                                    String sqlAction)
        Execute a SQL action (insert, update, delete, etc.) using a connection provided by a JPA EntityManagerFactory. The EntityManagerFactory is used to unwrap a Hibernate SessionFactory. The batch is executed in a JDBC transaction.
        Parameters:
        emf - The JPA EntityManagerFactory
        sqlAction - A SQL action.
        Returns:
        The action count.
      • sqlAction

        public static int sqlAction​(org.hibernate.SessionFactory sf,
                                    String sqlAction)
        Execute a SQL action (insert, update, delete, etc.) using a connection provided by a Hibernate SessionFactory. The batch is executed in a JDBC transaction.
        Parameters:
        sf - The Hibernate SessionFactory;
        sqlAction - A SQL action.
        Returns:
        The action count.
      • sqlBatch

        public static int[] sqlBatch​(javax.persistence.EntityManagerFactory emf,
                                     List<String> sqlBatch)
        Execute a JDBC batch of SQL actions (insert, update, delete, etc.) using a connection provided by a Hibernate SessionFactory. The EntityManagerFactory is used to unwrap a Hibernate SessionFactory. The batch is executed in a JDBC transaction.
        Parameters:
        emf - The JPA EntityManagerFactory
        sqlBatch - A batch of SQL actions.
        Returns:
        A list of counts for each SQL is the batch.
      • sqlBatch

        public static int[] sqlBatch​(org.hibernate.SessionFactory sf,
                                     List<String> sqlBatch)
        Execute a JDBC batch of SQL actions (insert, update, delete, etc.) using a connection provided by a Hibernate SessionFactory. The batch is executed in a JDBC transaction.
        Parameters:
        sf - The Hibernate SessionFactory;
        sqlBatch - A batch of SQL actions.
        Returns:
        A list of counts for each SQL is the batch.
      • sqlQuery

        public static Map<String,​List<Object>> sqlQuery​(javax.persistence.EntityManagerFactory emf,
                                                              String sql)
        Execute a JDBC query using a connection provided by a JPA EntityManagerFactory. The EntityManagerFactory is used to unwrap a Hibernate SessionFactory. The query is executed in a JDBC transaction.
        Parameters:
        emf - The JPA EntityManagerFactory.
        sql - The SQL to execute.
        Returns:
        A map of column names and values.
      • sqlQuery

        public static Map<String,​List<Object>> sqlQuery​(org.hibernate.SessionFactory sf,
                                                              String sql)
        Execute a JDBC query using a connection provided by a Hibernate SessionFactory. The query is executed in a JDBC transaction.
        Parameters:
        sf - The Hibernate SessionFactory.
        sql - The SQL to execute.
        Returns:
        A map of column names and values.