Revision: 4024
Author:   seba.wagner
Date:     Sat Aug  6 05:50:47 2011
Log:      Fixes Problem with refresh in SOAPSession
http://code.google.com/p/openmeetings/source/detail?r=4024

Modified:
/trunk/singlewebapp/src/app/org/openmeetings/app/data/basic/Sessionmanagement.java

=======================================
--- /trunk/singlewebapp/src/app/org/openmeetings/app/data/basic/Sessionmanagement.java Sat Jul 23 04:37:43 2011 +++ /trunk/singlewebapp/src/app/org/openmeetings/app/data/basic/Sessionmanagement.java Sat Aug 6 05:50:47 2011
@@ -26,25 +26,30 @@

 /**
  *
- * @author swagner
- * This Class handles all session management
+ * @author swagner This Class handles all session management
  *
- * TODO: Delete all inactive session by a scheduler
- *
- */
+ *         TODO: Delete all inactive session by a scheduler
+ *
+ */
 public class Sessionmanagement {
-
- private static final Logger log = Red5LoggerFactory.getLogger(Sessionmanagement.class, ScopeApplicationAdapter.webAppRootKey);
-
- //private static final Logger log = new Logger(Sessionmanagement.class, ScopeApplicationAdapter.webAppRootKey);
-
- //private static final Logger log = Red5Red5LoggerFactory.getLogger(Sessionmanagement.class, ScopeApplicationAdapter.webAppRootKey); - //private static final Logger log = Red5LoggerFactory.getLogger(Sessionmanagement.class, ScopeApplicationAdapter.webAppRootKey);
+
+       private static final Logger log = Red5LoggerFactory.getLogger(
+                       Sessionmanagement.class, 
ScopeApplicationAdapter.webAppRootKey);
+
+       // private static final Logger log = new Logger(Sessionmanagement.class,
+       // ScopeApplicationAdapter.webAppRootKey);
+
+       // private static final Logger log =
+       // Red5Red5LoggerFactory.getLogger(Sessionmanagement.class,
+       // ScopeApplicationAdapter.webAppRootKey);
+       // private static final Logger log =
+       // Red5LoggerFactory.getLogger(Sessionmanagement.class,
+       // ScopeApplicationAdapter.webAppRootKey);

        private static Sessionmanagement instance;

        private Sessionmanagement() {
-               //log.setLevel(Level.DEBUG);
+               // log.setLevel(Level.DEBUG);
        }

        public static synchronized Sessionmanagement getInstance() {
@@ -56,22 +61,25 @@

        /**
         * creates a new session-object in the database
+        *
         * @return
         */
        public Sessiondata startsession() {
-               //log.error("startsession User: || ");
+               // log.error("startsession User: || ");
                try {
-
+
                        System.out.println("startsession :: startsession");
                        log.debug("startsession :: startsession");
-
+
                        long thistime = new Date().getTime();
                        Sessiondata sessiondata = new Sessiondata();
- sessiondata.setSession_id(ManageCryptStyle.getInstance().getInstanceOfCrypt().createPassPhrase(String.valueOf(thistime).toString()));
+                       sessiondata.setSession_id(ManageCryptStyle.getInstance()
+                                       .getInstanceOfCrypt()
+                                       
.createPassPhrase(String.valueOf(thistime).toString()));
                        sessiondata.setRefresh_time(new Date());
                        sessiondata.setStarttermin_time(new Date());
                        sessiondata.setUser_id(null);
-
+
                        Object idf = PersistenceSessionUtil.createSession();
                        EntityManager session = 
PersistenceSessionUtil.getSession();
                        EntityTransaction tx = session.getTransaction();
@@ -82,19 +90,19 @@
                        session.refresh(sessiondata);
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
+
                        return sessiondata;
                } catch (Exception ex2) {
-                       log.error("[startsession]: " ,ex2);
+                       log.error("[startsession]: ", ex2);
                }

                return null;
        }
-
+
        public Sessiondata getSessionByHash(String SID) {
                try {
-                       log.debug("updateUser User SID: "+SID);
-
+                       log.debug("updateUser User SID: " + SID);
+
                        Object idf = PersistenceSessionUtil.createSession();
                        EntityManager session = 
PersistenceSessionUtil.getSession();
                        EntityTransaction tx = session.getTransaction();
@@ -111,190 +119,200 @@
                        List<Sessiondata> fullList = q.getResultList();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-                       if (fullList.size() == 0){
-                               log.error("Could not find session to update: 
"+SID);
+                       if (fullList.size() == 0) {
+                               log.error("Could not find session to update: " 
+ SID);
                                return null;
                        } else {
-                               //log.error("Found session to update: "+SID);
-                       }
-
+                               // log.error("Found session to update: "+SID);
+                       }
+
                        Sessiondata sd = (Sessiondata) fullList.get(0);
-
+
                        return sd;
                } catch (Exception ex2) {
-                       log.error("[updateUser]: " ,ex2);
+                       log.error("[updateUser]: ", ex2);
                }
                return null;
-       }
+       }

        /**
         * check if a given sessionID is loged in
+        *
         * @param SID
         * @return the User_id or 0 if not logged in
         */
-//     public Long checkSession(String SID) {
-//             try {
-//                     //log.debug("checkSession User: || "+SID);
-//                     Object idf = HibernateUtil.createSession();
-//                     EntityManager session = HibernateUtil.getSession();
-//                     EntityTransaction tx = session.getTransaction();
-//
-//                     //session.flush();
-//                     CriteriaBuilder crit = session.getCriteriaBuilder();
-//                     crit.add(Restrictions.eq("session_id", SID));
-//
-//                     List<Sessiondata> sessions = crit.list();
-//                     Sessiondata sessiondata = null;
-//                     if (sessions != null && sessions.size() > 0) {
-//                             sessiondata = sessions.get(0);
-//                     }
-//
-//                     if (sessiondata!=null) session.refresh(sessiondata);
-//                     //session.flush();
-//                     tx.commit();
-//                     HibernateUtil.closeSession(idf);
-// //if (sessiondata!=null) log.debug("checkSession USER_ID: "+sessiondata.getUser_id());
-//
-//                     if (sessiondata!=null) updatesession(SID);
-//
-// //Checks if wether the Session or the User Object of that Session is set yet -// if (sessiondata==null || sessions.size() >0 || sessiondata.equals(null) || -// sessiondata.getUser_id()==null || sessiondata.getUser_id().equals(null)
-//                                     || sessiondata.getUser_id().equals(new 
Long(0)) ) {
-//                             return new Long(0);
-//                     } else {
-//                             return sessiondata.getUser_id();
-//                     }
-//             } catch (HibernateException ex) {
-//                     log.error("[checkSession]: " ,ex);
-//             } catch (Exception ex2) {
-//                     log.error("[checkSession]: " ,ex2);
-//             }
-//             return null;
-//     }
-
+       // public Long checkSession(String SID) {
+       // try {
+       // //log.debug("checkSession User: || "+SID);
+       // Object idf = HibernateUtil.createSession();
+       // EntityManager session = HibernateUtil.getSession();
+       // EntityTransaction tx = session.getTransaction();
+       //
+       // //session.flush();
+       // CriteriaBuilder crit = session.getCriteriaBuilder();
+       // crit.add(Restrictions.eq("session_id", SID));
+       //
+       // List<Sessiondata> sessions = crit.list();
+       // Sessiondata sessiondata = null;
+       // if (sessions != null && sessions.size() > 0) {
+       // sessiondata = sessions.get(0);
+       // }
+       //
+       // if (sessiondata!=null) session.refresh(sessiondata);
+       // //session.flush();
+       // tx.commit();
+       // HibernateUtil.closeSession(idf);
+       // //if (sessiondata!=null)
+       // log.debug("checkSession USER_ID: "+sessiondata.getUser_id());
+       //
+       // if (sessiondata!=null) updatesession(SID);
+       //
+ // //Checks if wether the Session or the User Object of that Session is set
+       // yet
+       // if (sessiondata==null || sessions.size() >0 || 
sessiondata.equals(null)
+       // ||
+       // sessiondata.getUser_id()==null || 
sessiondata.getUser_id().equals(null)
+       // || sessiondata.getUser_id().equals(new Long(0)) ) {
+       // return new Long(0);
+       // } else {
+       // return sessiondata.getUser_id();
+       // }
+       // } catch (HibernateException ex) {
+       // log.error("[checkSession]: " ,ex);
+       // } catch (Exception ex2) {
+       // log.error("[checkSession]: " ,ex2);
+       // }
+       // return null;
+       // }
+
        public Long checkSession(String SID) {
                try {
-
-                       String hql = "select c from Sessiondata as c " +
-                                       "where c.session_id LIKE :session_id";
-
-                       //log.debug("checkSession User: || "+SID);
+
+                       String hql = "select c from Sessiondata as c "
+                                       + "where c.session_id LIKE :session_id";
+
+                       // log.debug("checkSession User: || "+SID);
                        Object idf = PersistenceSessionUtil.createSession();
                        EntityManager session = 
PersistenceSessionUtil.getSession();
                        EntityTransaction tx = session.getTransaction();
                        tx.begin();
-
-                       //session.flush();
+
+                       // session.flush();
                        Query query = session.createQuery(hql);
                        query.setParameter("session_id", SID);
-
+
                        List<Sessiondata> sessions = query.getResultList();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
+
                        Sessiondata sessiondata = null;
                        if (sessions != null && sessions.size() > 0) {
                                sessiondata = sessions.get(0);
                        }
-
-//                     if (sessiondata!=null)  {
-//                             log.debug("checkSession USER_ID: 
"+sessiondata.getUser_id());
-//                     } else {
-//                             log.debug("Session IS NULL SID: "+SID);
-//                     }
-
-                       //Update the Session Object
-                       if (sessiondata!=null) updatesession(SID);
-
- //Checks if wether the Session or the User Object of that Session is set yet - if (sessiondata==null || sessiondata.getUser_id()==null || sessiondata.getUser_id().equals(new Long(0)) ) {
+
+                       // if (sessiondata!=null) {
+                       // log.debug("checkSession USER_ID: 
"+sessiondata.getUser_id());
+                       // } else {
+                       // log.debug("Session IS NULL SID: "+SID);
+                       // }
+
+                       // Update the Session Object
+                       if (sessiondata != null)
+                               updatesession(SID);
+
+                       // Checks if wether the Session or the User Object of 
that Session
+                       // is set yet
+                       if (sessiondata == null || sessiondata.getUser_id() == 
null
+                                       || sessiondata.getUser_id().equals(new 
Long(0))) {
                                return new Long(0);
                        } else {
                                return sessiondata.getUser_id();
-                       }
+                       }
                } catch (Exception ex2) {
-                       log.error("[checkSession]: " ,ex2);
+                       log.error("[checkSession]: ", ex2);
                }
                return null;
        }

        /**
-        * update the session of a user with a new user id
-        * this is needed to see if the session is loggedin
+ * update the session of a user with a new user id this is needed to see if
+        * the session is loggedin
+        *
         * @param SID
         * @param USER_ID
         */
        public Boolean updateUser(String SID, long USER_ID) {
                try {
-                       log.debug("updateUser User: "+USER_ID+" || "+SID);
-
-                       String hql = "select c from Sessiondata as c " +
-                                                       "where c.session_id LIKE 
:session_id";
-
-                       //log.debug("checkSession User: || "+SID);
+                       log.debug("updateUser User: " + USER_ID + " || " + SID);
+
+                       String hql = "select c from Sessiondata as c "
+                                       + "where c.session_id LIKE :session_id";
+
+                       // log.debug("checkSession User: || "+SID);
                        Object idf = PersistenceSessionUtil.createSession();
                        EntityManager session = 
PersistenceSessionUtil.getSession();
                        EntityTransaction tx = session.getTransaction();
                        tx.begin();
-
-                       //session.flush();
+
+                       // session.flush();
                        Query query = session.createQuery(hql);
                        query.setParameter("session_id", SID);

                        List<Sessiondata> sessions = query.getResultList();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
+
                        Sessiondata sessiondata = null;
                        if (sessions != null && sessions.size() > 0) {
                                sessiondata = sessions.get(0);
                        }
-
+
                        if (sessiondata == null) {
                                log.error("Could not find session to Update");
                                return false;
                        }
- log.debug("Found session to update: "+sessiondata.getSession_id()+ " userId: "+USER_ID);
-
+                       log.debug("Found session to update: " + 
sessiondata.getSession_id()
+                                       + " userId: " + USER_ID);
+
                        idf = PersistenceSessionUtil.createSession();
                        session = PersistenceSessionUtil.getSession();
                        tx = session.getTransaction();
                        tx.begin();
                        sessiondata.setRefresh_time(new Date());
-                       //session.refresh(sd);
+                       // session.refresh(sd);
                        sessiondata.setUser_id(USER_ID);
                        if (sessiondata.getId() == null) {
                                session.persist(sessiondata);
-                           } else {
-                               if (!session.contains(sessiondata)) {
-                                       session.merge(sessiondata);
-                           }
+                       } else {
+                               if (!session.contains(sessiondata)) {
+                                       session.merge(sessiondata);
+                               }
                        }
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
-                       //log.debug("session updated User: "+USER_ID);
+
+                       // log.debug("session updated User: "+USER_ID);
                        return true;
                } catch (Exception ex2) {
-                       log.error("[updateUser]: " ,ex2);
+                       log.error("[updateUser]: ", ex2);
                }
                return null;
        }
-
- public Boolean updateUser(String SID, long USER_ID, boolean storePermanent, Long language_id) {
+
+ public Boolean updateUser(String SID, long USER_ID, boolean storePermanent,
+                       Long language_id) {
                try {
-                       log.debug("updateUser User: "+USER_ID+" || "+SID);
-
-                       String hql = "select c from Sessiondata as c " +
-                                                       "where c.session_id LIKE 
:session_id";
-
-                       //log.debug("checkSession User: || "+SID);
+                       log.debug("updateUser User: " + USER_ID + " || " + SID);
+
+                       String hql = "select c from Sessiondata as c "
+                                       + "where c.session_id LIKE :session_id";
+
+                       // log.debug("checkSession User: || "+SID);
                        Object idf = PersistenceSessionUtil.createSession();
                        EntityManager session = 
PersistenceSessionUtil.getSession();
                        EntityTransaction tx = session.getTransaction();
                        tx.begin();
-
+
                        session.flush();
                        Query query = session.createQuery(hql);
                        query.setParameter("session_id", SID);
@@ -302,24 +320,25 @@
                        List<Sessiondata> sessions = query.getResultList();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
+
                        Sessiondata sessiondata = null;
                        if (sessions != null && sessions.size() > 0) {
                                sessiondata = sessions.get(0);
                        }
-
+
                        if (sessiondata == null) {
                                log.error("Could not find session to Update");
                                return false;
                        }
- log.debug("Found session to update: "+sessiondata.getSession_id()+ " userId: "+USER_ID);
-
+                       log.debug("Found session to update: " + 
sessiondata.getSession_id()
+                                       + " userId: " + USER_ID);
+
                        idf = PersistenceSessionUtil.createSession();
                        session = PersistenceSessionUtil.getSession();
                        tx = session.getTransaction();
                        tx.begin();
                        sessiondata.setRefresh_time(new Date());
-                       //session.refresh(sd);
+                       // session.refresh(sd);
                        sessiondata.setUser_id(USER_ID);
                        if (storePermanent) {
                                sessiondata.setStorePermanent(storePermanent);
@@ -327,36 +346,36 @@
                        sessiondata.setLanguage_id(language_id);
                        if (sessiondata.getId() == null) {
                                session.persist(sessiondata);
-                           } else {
-                               if (!session.contains(sessiondata)) {
-                                       session.merge(sessiondata);
-                           }
+                       } else {
+                               if (!session.contains(sessiondata)) {
+                                       session.merge(sessiondata);
+                               }
                        }
                        session.flush();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
-                       //log.debug("session updated User: "+USER_ID);
+
+                       // log.debug("session updated User: "+USER_ID);
                        return true;
                } catch (Exception ex2) {
-                       log.error("[updateUser]: " ,ex2);
+                       log.error("[updateUser]: ", ex2);
                }
                return null;
        }
-
+
        public Boolean updateUserOrg(String SID, Long organization_id) {
                try {
-                       log.debug("updateUserOrg User: "+organization_id+" || 
"+SID);
-
-                       String hql = "select c from Sessiondata as c " +
-                                                       "where c.session_id LIKE 
:session_id";
-
-                       //log.debug("checkSession User: || "+SID);
+                       log.debug("updateUserOrg User: " + organization_id + " || 
" + SID);
+
+                       String hql = "select c from Sessiondata as c "
+                                       + "where c.session_id LIKE :session_id";
+
+                       // log.debug("checkSession User: || "+SID);
                        Object idf = PersistenceSessionUtil.createSession();
                        EntityManager session = 
PersistenceSessionUtil.getSession();
                        EntityTransaction tx = session.getTransaction();
                        tx.begin();
-
+
                        session.flush();
                        Query query = session.createQuery(hql);
                        query.setParameter("session_id", SID);
@@ -364,58 +383,58 @@
                        List<Sessiondata> sessions = query.getResultList();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
+
                        Sessiondata sessiondata = null;
                        if (sessions != null && sessions.size() > 0) {
                                sessiondata = sessions.get(0);
                        }
-
+
                        if (sessiondata == null) {
                                log.error("Could not find session to Update");
                                return false;
                        }
- log.debug("Found session to update: "+sessiondata.getSession_id()+ " organisation_id: "+organization_id);
-
+                       log.debug("Found session to update: " + 
sessiondata.getSession_id()
+                                       + " organisation_id: " + 
organization_id);
+
                        idf = PersistenceSessionUtil.createSession();
                        session = PersistenceSessionUtil.getSession();
                        tx = session.getTransaction();
                        tx.begin();
                        sessiondata.setRefresh_time(new Date());
-                       //session.refresh(sd);
+                       // session.refresh(sd);
                        sessiondata.setOrganization_id(organization_id);
                        if (sessiondata.getId() == null) {
                                session.persist(sessiondata);
-                           } else {
-                               if (!session.contains(sessiondata)) {
-                                       session.merge(sessiondata);
-                           }
+                       } else {
+                               if (!session.contains(sessiondata)) {
+                                       session.merge(sessiondata);
+                               }
                        }
                        session.flush();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
-                       //log.debug("session updated User: "+USER_ID);
+
+                       // log.debug("session updated User: "+USER_ID);
                        return true;
                } catch (Exception ex2) {
-                       log.error("[updateUser]: " ,ex2);
+                       log.error("[updateUser]: ", ex2);
                }
                return null;
        }
-
-
+
        public Boolean updateUserWithoutSession(String SID, Long USER_ID) {
                try {
-                       log.debug("updateUser User: "+USER_ID+" || "+SID);
-
-                       String hql = "select c from Sessiondata as c " +
-                                                       "where c.session_id LIKE 
:session_id";
-
-                       //log.debug("checkSession User: || "+SID);
+                       log.debug("updateUser User: " + USER_ID + " || " + SID);
+
+                       String hql = "select c from Sessiondata as c "
+                                       + "where c.session_id LIKE :session_id";
+
+                       // log.debug("checkSession User: || "+SID);
                        Object idf = PersistenceSessionUtil.createSession();
                        EntityManager session = 
PersistenceSessionUtil.getSession();
                        EntityTransaction tx = session.getTransaction();
                        tx.begin();
-
+
                        session.flush();
                        Query query = session.createQuery(hql);
                        query.setParameter("session_id", SID);
@@ -423,48 +442,49 @@
                        List<Sessiondata> sessions = query.getResultList();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
+
                        Sessiondata sessiondata = null;
                        if (sessions != null && sessions.size() > 0) {
                                sessiondata = sessions.get(0);
                        }
-
+
                        if (sessiondata == null) {
                                log.error("Could not find session to Update");
                                return false;
                        }
- log.debug("Found session to update: "+sessiondata.getSession_id()+ " userId: "+USER_ID);
-
+                       log.debug("Found session to update: " + 
sessiondata.getSession_id()
+                                       + " userId: " + USER_ID);
+
                        idf = PersistenceSessionUtil.createSession();
                        session = PersistenceSessionUtil.getSession();
                        tx = session.getTransaction();
                        tx.begin();
                        sessiondata.setRefresh_time(new Date());
-                       //session.refresh(sd);
+                       // session.refresh(sd);
                        sessiondata.setUser_id(USER_ID);
                        if (sessiondata.getId() == null) {
                                session.persist(sessiondata);
-                           } else {
-                               if (!session.contains(sessiondata)) {
-                                       session.merge(sessiondata);
-                           }
+                       } else {
+                               if (!session.contains(sessiondata)) {
+                                       session.merge(sessiondata);
+                               }
                        }
                        session.flush();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
-                       //log.debug("session updated User: "+USER_ID);
+
+                       // log.debug("session updated User: "+USER_ID);
                        return true;
                } catch (Exception ex2) {
-                       log.error("[updateUser]: " ,ex2);
+                       log.error("[updateUser]: ", ex2);
                }
                return null;
        }
-
+
        public Boolean updateUserRemoteSession(String SID, String sessionXml) {
                try {
-                       log.debug("updateUser User SID: "+SID);
-
+                       log.debug("updateUser User SID: " + SID);
+
                        Object idf = PersistenceSessionUtil.createSession();
                        EntityManager session = 
PersistenceSessionUtil.getSession();
                        EntityTransaction tx = session.getTransaction();
@@ -480,50 +500,55 @@
                        List<Sessiondata> fullList = q.getResultList();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
-                       if (fullList.size() == 0){
-                               log.error("Could not find session to update: 
"+SID);
+
+                       if (fullList.size() == 0) {
+                               log.error("Could not find session to update: " 
+ SID);
                                return false;
                        } else {
-                               //log.error("Found session to update: "+SID);
+                               // log.error("Found session to update: "+SID);
                        }
                        Sessiondata sd = (Sessiondata) fullList.get(0);
- //log.debug("Found session to update: "+sd.getSession_id()+ " userId: "+USER_ID);
-
+                       // log.debug("Found session to update: 
"+sd.getSession_id()+
+                       // " userId: "+USER_ID);
+
+                       sd.setRefresh_time(new Date());
+                       sd.setSessionXml(sessionXml);
+
                        idf = PersistenceSessionUtil.createSession();
                        session = PersistenceSessionUtil.getSession();
                        tx = session.getTransaction();
                        tx.begin();
-                       sd.setRefresh_time(new Date());
-                       session.refresh(sd);
-                       sd.setSessionXml(sessionXml);
+
+                       // session.refresh(sd);
+
                        session.flush();
                        if (sd.getId() == null) {
                                session.persist(sd);
-                           } else {
-                               if (!session.contains(sd)) {
-                                       session.merge(sd);
-                           }
+                       } else {
+                               if (!session.contains(sd)) {
+                                       session.merge(sd);
+                               }
                        }
                        session.flush();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
-                       //log.debug("session updated User: "+USER_ID);
+
+                       // log.debug("session updated User: "+USER_ID);
                        return true;
                } catch (Exception ex2) {
-                       log.error("[updateUserRemoteSession]: " ,ex2);
+                       log.error("[updateUserRemoteSession]: ", ex2);
                }
                return null;
        }

        /**
         * update the session every time a user makes a request
+        *
         * @param SID
         */
        private void updatesession(String SID) {
                try {
-                       //log.debug("****** updatesession: "+SID);
+                       // log.debug("****** updatesession: "+SID);
                        Object idf = PersistenceSessionUtil.createSession();
                        EntityManager session = 
PersistenceSessionUtil.getSession();
                        EntityTransaction tx = session.getTransaction();
@@ -538,53 +563,50 @@

                        List<Sessiondata> fullList = q.getResultList();
                        tx.commit();
-                       PersistenceSessionUtil.closeSession(idf);
+                       PersistenceSessionUtil.closeSession(idf);
                        if (fullList.size() == 0) {
                                log.error("Found NO session to updateSession: 
");

                        } else {
-                               //log.debug("Found session to updateSession: ");
+                               // log.debug("Found session to updateSession: 
");
                                Sessiondata sd = (Sessiondata) 
fullList.iterator().next();
- //log.debug("Found session to updateSession sd "+sd.getUser_id()+" "+sd.getSession_id()); + // log.debug("Found session to updateSession sd "+sd.getUser_id()+" "+sd.getSession_id());
                                sd.setRefresh_time(new Date());
-
+
                                Object idf2 = 
PersistenceSessionUtil.createSession();
                                EntityManager session2 = 
PersistenceSessionUtil.getSession();
                                EntityTransaction tx2 = 
session2.getTransaction();
                                tx2.begin();
                                if (sd.getId() == null) {
                                        session2.persist(sd);
-                                   } else {
-                                       if (!session2.contains(sd)) {
-                                               session2.merge(sd);
-                                   }
+                               } else {
+                                       if (!session2.contains(sd)) {
+                                               session2.merge(sd);
+                                       }
                                }
                                session2.flush();
                                tx2.commit();
-                               PersistenceSessionUtil.closeSession(idf2);
-                       }
-
+                               PersistenceSessionUtil.closeSession(idf2);
+                       }
+
                } catch (Exception ex2) {
-                       log.error("[updatesession]: " ,ex2);
+                       log.error("[updatesession]: ", ex2);
                }
        }
-
+
        /**
         *
         * @param date
         * @return
         */
-       private List<Sessiondata> getSessionToDelete(Date refresh_time){
+       private List<Sessiondata> getSessionToDelete(Date refresh_time) {
                try {
-
-                       String hql = "Select c from Sessiondata c " +
-                                                       "WHERE c.refresh_time < 
:refresh_time " +
-                                                       "AND ( " +
-                                                       "c.storePermanent IS NULL 
" +
-                                                       "OR " +
-                                                       "c.storePermanent = false 
" +
-                                                       ")";
-
+
+                       String hql = "Select c from Sessiondata c "
+                                       + "WHERE c.refresh_time < :refresh_time " + 
"AND ( "
+                                       + "c.storePermanent IS NULL " + "OR "
+                                       + "c.storePermanent = false " + ")";
+
                        Object idf = PersistenceSessionUtil.createSession();
                        EntityManager session = 
PersistenceSessionUtil.getSession();
                        EntityTransaction tx = session.getTransaction();
@@ -594,42 +616,42 @@
                        List<Sessiondata> fullList = query.getResultList();
                        tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
-                       log.debug("Sessions To Delete :: "+fullList.size());
-
-                       return fullList;
-
+
+                       log.debug("Sessions To Delete :: " + fullList.size());
+
+                       return fullList;
+
                } catch (Exception ex2) {
-                       log.error("[getSessionToDelete]: " ,ex2);
+                       log.error("[getSessionToDelete]: ", ex2);
                }
                return null;
        }
-
+
        /**
         *
         *
         */
-       public void clearSessionTable(){
+       public void clearSessionTable() {
                try {
                        log.debug("****** clearSessionTable: ");
                        Calendar rightNow = Calendar.getInstance();
-                       
rightNow.setTimeInMillis(rightNow.getTimeInMillis()-1800000);
-                   List l = this.getSessionToDelete(rightNow.getTime());
-                   log.debug("clearSessionTable: "+l.size());
-            Object idf = PersistenceSessionUtil.createSession();
+                       rightNow.setTimeInMillis(rightNow.getTimeInMillis() - 
1800000);
+                       List l = this.getSessionToDelete(rightNow.getTime());
+                       log.debug("clearSessionTable: " + l.size());
+                       Object idf = PersistenceSessionUtil.createSession();
                        EntityManager session = 
PersistenceSessionUtil.getSession();
                        EntityTransaction tx = session.getTransaction();
                        tx.begin();
-                   for (Iterator it = l.iterator();it.hasNext();){
+                       for (Iterator it = l.iterator(); it.hasNext();) {
                                Sessiondata sData = (Sessiondata) it.next();
                                sData = session.find(Sessiondata.class, 
sData.getId());
                                session.remove(sData);
-                   }
-            tx.commit();
+                       }
+                       tx.commit();
                        PersistenceSessionUtil.closeSession(idf);
-
+
                } catch (Exception err) {
-                       log.error("clearSessionTable",err);
+                       log.error("clearSessionTable", err);
                }
        }

@@ -655,7 +677,7 @@
                                if (end_pos > aux.length())
                                        end_pos = aux.length();
                                String SID = aux.substring(init_pos, end_pos);
-
+
                                Sessiondata sData = this.getSessionByHash(SID);

                                Object idf = 
PersistenceSessionUtil.createSession();

--
You received this message because you are subscribed to the Google Groups 
"OpenMeetings developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/openmeetings-dev?hl=en.

Reply via email to