Class HibernateSession
java.lang.Object
edu.internet2.middleware.grouper.hibernate.HibernateSession
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 Summary
Modifier and TypeMethodDescriptionstatic void
close all sessions, but dont throw errors, based on throwablestatic HibernateSession
get the current hibernate session.static HibernateSession
_internal_hibernateSession
(GrouperTransactionType grouperTransactionType) dont call this method unless you know what you are doingstatic void
_internal_hibernateSessionCatch
(HibernateSession hibernateSession, Throwable e) catch and handle an exception while working with hibernate session.static void
_internal_hibernateSessionEnd
(HibernateSession hibernateSession) end a hibernate session.static boolean
_internal_hibernateSessionFinally
(HibernateSession hibernateSession) finally block from hibernate session (dont call unless you know what you are doingstatic Set<HibernateSession>
this is for internal purposes only, dont use this unless you know what you are doingstatic void
make sure not readonly modestatic ByCriteriaStatic
do a criteria query with proper error handling and in an enclosing transaction (if applicable), or a new one if notbyHql()
hql action for hibernatestatic ByHqlStatic
do a hql query with proper error handling and in an enclosing transaction (if applicable), or a new one if notbyObject()
static ByObjectStatic
do an object operation with proper error handling and in an enclosing transaction (if applicable), or a new one if notbySql()
hql action for hibernatestatic BySqlStatic
do a sql query with proper error handling and in an enclosing transaction (if applicable), or a new one if notstatic Object
callbackHibernateSession
(GrouperTransactionType grouperTransactionType, AuditControl auditControl, HibernateHandler hibernateHandler) call this to send a callback for the hibernate session object.boolean
commit
(GrouperCommitType grouperCommitType) commit (perhaps, depending on type)static void
flush()
flush the current session if we are doing something out of band...this will return the underlying (if exist) transaction type, and if not, then the one this was constructed withorg.hibernate.Session
hibernate session object can be accessed by user.static void
internal_assignThreadlocalReadonly
(Boolean internal_threadlocalReadonly) static Boolean
boolean
provide ability to turn off all caching for this sessionboolean
see if this is a new hibernate sessionboolean
if this is readonly (based on this declaration or underlying)static boolean
if readonly by threadlocal or config paramboolean
see if tx is active (not committed or rolled back, see Hibernate transaction if there is no transaction, it will return falsemisc()
misc actions for hibernate sessionstatic void
call this at the end of requests to make sure everything is cleared out or call periodically...boolean
rollback
(GrouperRollbackType grouperRollbackType) rollback (perhaps, depending on type)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()static void
assign that grouper is in readonly mode, make sure to call clear in a finally blockstatic void
in finally block call this to not make grouper readonly anymoretoString()
descriptive toString for error handling
-
Method Details
-
flush
public static void flush()flush the current session if we are doing something out of band... -
byObject
- Returns:
- the class
-
internal_retrieveThreadlocalReadonly
- Returns:
- the internal_threadlocalReadonly
-
internal_assignThreadlocalReadonly
- 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
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
get the current hibernate session. dont call this unless you know what you are doing- Returns:
- the current hibernate session
-
_internal_closeAllHibernateSessions
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
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 nothibernateHandler
- 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
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
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
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
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
descriptive toString for error handling -
getSession
public org.hibernate.Session getSession()hibernate session object can be accessed by user.- Returns:
- the session
-
misc
misc actions for hibernate session- Returns:
- the class
-
byHql
hql action for hibernate- Returns:
- the byhql
-
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
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
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
rollback (perhaps, depending on type)- Parameters:
grouperRollbackType
- is type of rollback- Returns:
- true if rollback, false if not
-