Class HibernateSession

java.lang.Object
edu.internet2.middleware.grouper.hibernate.HibernateSession

public class HibernateSession extends Object
 Hibernate helper class.  These are kept in a threadlocal to keep 
 transactions going smoothly.  If you are in a nested callback situation,
 and in the same transaction, then the HibernateSession instance will be
 different, but the underlying Session (from hibernate) object will be the same.  
 To get an instanceof HibernateSession, use the callbackHibernateSession
 inverse of control method.
 
 
  • Method Details

    • flush

      public static void flush()
      flush the current session if we are doing something out of band...
    • byObject

      public ByObject byObject()
      Returns:
      the class
    • internal_retrieveThreadlocalReadonly

      public static Boolean internal_retrieveThreadlocalReadonly()
      Returns:
      the internal_threadlocalReadonly
    • internal_assignThreadlocalReadonly

      public static void internal_assignThreadlocalReadonly(Boolean internal_threadlocalReadonly)
      Parameters:
      internal_threadlocalReadonly - the internal_threadlocalReadonly to set
    • isReadonlyMode

      public static boolean isReadonlyMode()
      if readonly by threadlocal or config param
      Returns:
      true if readonly
    • threadLocalReadonlyAssign

      public static void threadLocalReadonlyAssign()
      assign that grouper is in readonly mode, make sure to call clear in a finally block
    • threadLocalReadonlyClear

      public static void threadLocalReadonlyClear()
      in finally block call this to not make grouper readonly anymore
    • isCachingEnabled

      public boolean isCachingEnabled()
      provide ability to turn off all caching for this session
      Returns:
      the enabledCaching
    • setCachingEnabled

      public void setCachingEnabled(boolean enabledCaching1)
      provide ability to turn off all caching for this session note, you can also use a try/finally with HibUtils.assignDisallowCacheThreadLocal() and HibUtils.clearDisallowCacheThreadLocal()
      Parameters:
      enabledCaching1 - the enabledCaching to set
    • _internal_staticSessions

      public static Set<HibernateSession> _internal_staticSessions()
      this is for internal purposes only, dont use this unless you know what you are doing
      Returns:
      the set of hibernate sessions
    • resetAllThreadLocals

      public static void resetAllThreadLocals()
      call this at the end of requests to make sure everything is cleared out or call periodically...
    • _internal_hibernateSession

      public static HibernateSession _internal_hibernateSession()
      get the current hibernate session. dont call this unless you know what you are doing
      Returns:
      the current hibernate session
    • _internal_closeAllHibernateSessions

      public static void _internal_closeAllHibernateSessions(Throwable t)
      close all sessions, but dont throw errors, based on throwable
      Parameters:
      t -
    • _internal_hibernateSession

      public static HibernateSession _internal_hibernateSession(GrouperTransactionType grouperTransactionType) throws GrouperDAOException
      dont call this method unless you know what you are doing
      Parameters:
      grouperTransactionType -
      Returns:
      the hiberate session for internal purposes
      Throws:
      GrouperDAOException
    • _internal_hibernateSessionEnd

      public static void _internal_hibernateSessionEnd(HibernateSession hibernateSession) throws SQLException
      end a hibernate session. dont call this unless you know what you are doing
      Parameters:
      hibernateSession -
      Throws:
      SQLException
    • assertNotGrouperReadonly

      public static void assertNotGrouperReadonly()
      make sure not readonly mode
    • _internal_hibernateSessionCatch

      public static void _internal_hibernateSessionCatch(HibernateSession hibernateSession, Throwable e) throws GrouperDAOException
      catch and handle an exception while working with hibernate session. Dont call this if you dont know what you are doing.
      Parameters:
      hibernateSession -
      e -
      Throws:
      GrouperDAOException
    • _internal_hibernateSessionFinally

      public static boolean _internal_hibernateSessionFinally(HibernateSession hibernateSession)
      finally block from hibernate session (dont call unless you know what you are doing
      Parameters:
      hibernateSession -
      Returns:
      if closed
    • callbackHibernateSession

      public static Object callbackHibernateSession(GrouperTransactionType grouperTransactionType, AuditControl auditControl, HibernateHandler hibernateHandler) throws GrouperDAOException
      call this to send a callback for the hibernate session object. cant use inverse of control for this since it runs it
      Parameters:
      grouperTransactionType - is enum of how the transaction should work.
      auditControl - WILL_AUDIT if caller will create an audit record, WILL_NOT_AUDIT if not
      hibernateHandler - will get the callback
      Returns:
      the object returned from the callback
      Throws:
      GrouperDAOException - if there is a problem, will preserve runtime exceptions so they are thrown to the caller
    • byHqlStatic

      public static ByHqlStatic byHqlStatic()
      do a hql query with proper error handling and in an enclosing transaction (if applicable), or a new one if not
      Returns:
      the class
    • bySqlStatic

      public static BySqlStatic bySqlStatic()
      do a sql query with proper error handling and in an enclosing transaction (if applicable), or a new one if not
      Returns:
      the class
    • byCriteriaStatic

      public static ByCriteriaStatic byCriteriaStatic()
      do a criteria query with proper error handling and in an enclosing transaction (if applicable), or a new one if not
      Returns:
      the class
    • byObjectStatic

      public static ByObjectStatic byObjectStatic()
      do an object operation with proper error handling and in an enclosing transaction (if applicable), or a new one if not
      Returns:
      the class
    • toString

      public String toString()
      descriptive toString for error handling
      Overrides:
      toString in class Object
    • getSession

      public org.hibernate.Session getSession()
      hibernate session object can be accessed by user.
      Returns:
      the session
    • misc

      public HibernateMisc misc()
      misc actions for hibernate session
      Returns:
      the class
    • byHql

      public ByHql byHql()
      hql action for hibernate
      Returns:
      the byhql
    • bySql

      public BySql bySql()
      hql action for hibernate
      Returns:
      the byhql
    • isNewHibernateSession

      public boolean isNewHibernateSession()
      see if this is a new hibernate session
      Returns:
      the newHibernateSession
    • isReadonly

      public boolean isReadonly()
      if this is readonly (based on this declaration or underlying)
      Returns:
      the readonly
    • getGrouperTransactionType

      public GrouperTransactionType getGrouperTransactionType()
      this will return the underlying (if exist) transaction type, and if not, then the one this was constructed with
      Returns:
      the hibernate transaction type
    • commit

      public boolean commit(GrouperCommitType grouperCommitType)
      commit (perhaps, depending on type)
      Parameters:
      grouperCommitType - is type of commit
      Returns:
      true if committed, false if not
    • isTransactionActive

      public boolean isTransactionActive()
      see if tx is active (not committed or rolled back, see Hibernate transaction if there is no transaction, it will return false
      Returns:
      true if active, false if not or not transaction
    • rollback

      public boolean rollback(GrouperRollbackType grouperRollbackType)
      rollback (perhaps, depending on type)
      Parameters:
      grouperRollbackType - is type of rollback
      Returns:
      true if rollback, false if not