Changeset 7900
- Timestamp:
- Jan 21, 2021, 8:18:54 AM (2 years ago)
- Location:
- trunk/src/core/net/sf/basedb/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/Application.java
r7899 r7900 564 564 // BouncyCastle 565 565 if (Security.getProvider("BC") == null) Security.addProvider(new BouncyCastleProvider()); 566 567 // Auto-logout existing session without logout time 568 if (options.autoLogoutSessions) 569 { 570 int numSessions = Session.autoLogout(); 571 log.info(numSessions + " sessions without a logout time was automatically logged out."); 572 } 566 573 567 574 // Initialize extensions system -
trunk/src/core/net/sf/basedb/core/Session.java
r7413 r7900 24 24 25 25 import net.sf.basedb.core.data.SessionData; 26 import net.sf.basedb.core.hibernate.TypeWrapper; 26 27 import net.sf.basedb.core.query.Restrictions; 27 28 import net.sf.basedb.core.query.Hql; … … 98 99 return query; 99 100 } 101 102 /** 103 Cleanup method that sets a logout-time on all sessions 104 that doesn't have a logout time. 105 @return The number of sessions updated 106 @since 3.18 107 */ 108 static int autoLogout() 109 { 110 org.hibernate.Transaction tx = null; 111 org.hibernate.Session session = null; 112 int numUpdated = 0; 113 try 114 { 115 session = HibernateUtil.newSession(); 116 tx = HibernateUtil.newTransaction(session); 117 118 // Update 'location' 119 org.hibernate.query.Query<?> query = HibernateUtil.createQuery(session, 120 "UPDATE SessionData s " + 121 "SET s.logoutTime = :now " + 122 "WHERE s.logoutTime IS NULL"); 123 query.setParameter("now", new Date(), TypeWrapper.H_TIMESTAMP); 124 numUpdated = query.executeUpdate(); 125 HibernateUtil.commit(tx); 126 } 127 catch (Exception ex) 128 { 129 // This should now be a fatal error, log a warning only 130 Application.getLogger().warn("Could not auto-logout existing sessions", ex); 131 } 132 finally 133 { 134 HibernateUtil.close(session); 135 } 136 return numUpdated; 137 } 100 138 101 139 Session(SessionData sessionData)
Note: See TracChangeset
for help on using the changeset viewer.