Class HB

java.lang.Object
com.isomorphic.hibernate.HB

public class HB extends Object
Singleton factory for hibernate Session and transaction with helper methods.

Configuration is read from server.properties file. Value of property hibernate.provider specifies actual implementation. Methods hiding Session and transaction object initialization are used by HibernateDataSource:

  • getEntityManager
  • returnEntityManager
  • getTransaction
  • commitTransaction
  • rollbackTransaction
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name of sub property for hibernate configuration lookup style.
    static final String
    Default Hibernate provider class name.
    static final String
    Default Spring Hibernate provider class name.
    static final String
    Name of prefix for hibernate provider block.
    static final String
    Name of property for JPA EMF provider implementation.
    static final String
    Lookup style value specifying Spring usage.
    static final String
    Name of sub property for hibernate provider implementation.
    static final String
    Attribute name for RPCManager.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    commitTransaction(String configName, org.hibernate.Transaction tx)
    Commits specified transaction.
    static void
    commitTransaction(org.hibernate.Transaction tx)
    Commits specified transaction.
    static org.hibernate.SessionFactory
    get()
    Returns SessionFactory.
    static org.hibernate.SessionFactory
    get(String configName)
    Returns SessionFactory.
    static org.hibernate.Session
    Returns Session for persistence operations.
    static org.hibernate.Session
    getSession(String configName)
    Returns Session for persistence operations.
    static org.hibernate.Transaction
    getTransaction(String configName, org.hibernate.Session session)
    Returns started transaction.
    static org.hibernate.Transaction
    getTransaction(org.hibernate.Session session)
    Returns started transaction.
    static void
    returnSession(String configName, org.hibernate.Session session)
    Closes Session.
    static void
    returnSession(org.hibernate.Session session)
    Closes Session.
    static void
    rollbackTransaction(String configName, org.hibernate.Transaction tx)
    Rolls back specified transaction.
    static void
    rollbackTransaction(org.hibernate.Transaction tx)
    Rolls back specified transaction.
  • Field Details

    • HB_PREFIX

      public static final String HB_PREFIX
      Name of prefix for hibernate provider block.
      See Also:
    • PROVIDER

      public static final String PROVIDER
      Name of sub property for hibernate provider implementation.
      See Also:
    • CONFIG_LOOKUP_STYLE

      public static final String CONFIG_LOOKUP_STYLE
      Name of sub property for hibernate configuration lookup style.
      See Also:
    • LOOKUP_STYLE_SPRING

      public static final String LOOKUP_STYLE_SPRING
      Lookup style value specifying Spring usage.
      See Also:
    • DEFAULT_HB_PROVIDER

      public static final String DEFAULT_HB_PROVIDER
      Default Hibernate provider class name. Will be used if provider is not specified in configuration.
      See Also:
    • DEFAULT_SPRING_HB_PROVIDER

      public static final String DEFAULT_SPRING_HB_PROVIDER
      Default Spring Hibernate provider class name. Will be used if provider is not specified in configuration and lookupStyle property is set to 'spring'.
      See Also:
    • HB_PROVIDER

      public static final String HB_PROVIDER
      Name of property for JPA EMF provider implementation.
      See Also:
    • TRANSACTION_ATTR

      public static final String TRANSACTION_ATTR
      Attribute name for RPCManager. Under this attribute current transaction is stored.
      See Also:
  • Method Details

    • get

      public static org.hibernate.SessionFactory get()
      Returns SessionFactory. Using default configuration.
      Returns:
      SessionFactory or null.
    • get

      public static org.hibernate.SessionFactory get(String configName)
      Returns SessionFactory.
      Parameters:
      configName - String configuration name. Default provider is used if null or empty string is passed.
      Returns:
      SessionFactory or null.
    • getSession

      public static org.hibernate.Session getSession() throws org.hibernate.HibernateException
      Returns Session for persistence operations. Using default configuration.
      Returns:
      Session for persistence operations.
      Throws:
      org.hibernate.HibernateException - if unable to acquire Session.
    • getSession

      public static org.hibernate.Session getSession(String configName) throws org.hibernate.HibernateException
      Returns Session for persistence operations.
      Parameters:
      configName - String configuration name. Default provider is used if null or empty string is passed.
      Returns:
      Session for persistence operations.
      Throws:
      org.hibernate.HibernateException - if unable to acquire Session.
    • returnSession

      public static void returnSession(org.hibernate.Session session)
      Closes Session. Using default configuration.
      Parameters:
      session - Session which should be closed.
    • returnSession

      public static void returnSession(String configName, org.hibernate.Session session)
      Closes Session.
      Parameters:
      configName - String configuration name. Default provider is used if null or empty string is passed.
      session - Session which should be closed.
    • getTransaction

      public static org.hibernate.Transaction getTransaction(org.hibernate.Session session) throws org.hibernate.HibernateException
      Returns started transaction. Using default configuration.
      Parameters:
      session - Session needed if joining to existing transaction or starting transaction locally.
      Returns:
      Transaction Already started transaction for persistence operations.
      Throws:
      org.hibernate.HibernateException - if unable to acquire or open transaction.
    • getTransaction

      public static org.hibernate.Transaction getTransaction(String configName, org.hibernate.Session session) throws org.hibernate.HibernateException
      Returns started transaction.
      Parameters:
      configName - String configuration name. Default provider is used if null or empty string is passed.
      session - Session needed if joining to existing transaction or starting transaction locally.
      Returns:
      Transaction Already started transaction for persistence operations.
      Throws:
      org.hibernate.HibernateException - if unable to acquire or open transaction.
    • commitTransaction

      public static void commitTransaction(org.hibernate.Transaction tx) throws org.hibernate.HibernateException
      Commits specified transaction. Using default configuration.
      Parameters:
      tx - Transaction transaction to be committed.
      Throws:
      org.hibernate.HibernateException - occurred while committing transaction.
    • commitTransaction

      public static void commitTransaction(String configName, org.hibernate.Transaction tx) throws org.hibernate.HibernateException
      Commits specified transaction.
      Parameters:
      configName - String configuration name. Default provider is used if null or empty string is passed.
      tx - Transaction transaction to be committed.
      Throws:
      org.hibernate.HibernateException - occurred while committing transaction.
    • rollbackTransaction

      public static void rollbackTransaction(org.hibernate.Transaction tx)
      Rolls back specified transaction. Using default configuration.
      Parameters:
      tx - Transaction transaction to be rolled back.
    • rollbackTransaction

      public static void rollbackTransaction(String configName, org.hibernate.Transaction tx)
      Rolls back specified transaction.
      Parameters:
      configName - String configuration name. Default provider is used if null or empty string is passed.
      tx - Transaction transaction to be rolled back.