001
014
015 package com.liferay.portal.spring.hibernate;
016
017 import com.liferay.portal.kernel.exception.SystemException;
018 import com.liferay.portal.kernel.util.AutoResetThreadLocal;
019
020 import org.hibernate.Session;
021
022
025 public class LastSessionRecorderUtil {
026
027 public static void syncLastSessionState() throws SystemException {
028 Session session = _lastSessionThreadLocal.get();
029
030 if ((session != null) && session.isOpen()) {
031 try {
032 session.flush();
033 session.clear();
034 }
035 catch (Exception e) {
036 throw new SystemException(e);
037 }
038 }
039 }
040
041 protected static void setLastSession(Session session) {
042 _lastSessionThreadLocal.set(session);
043 }
044
045 private static ThreadLocal<Session> _lastSessionThreadLocal =
046 new AutoResetThreadLocal<Session>(
047 LastSessionRecorderUtil.class.getName() +
048 "._lastSessionThreadLocal");
049
050 }