Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Creative commons Attribution-NonCommercial license. http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 
 package base.jee.api.sql;
 
public class ExpireTokens extends Command {
	private DataSource ds;
	private Settings settings;
	public ExpireTokens(DataSource dsSettings settings) {
		this. = ds;
		this. = settings;
	}
	public ExpireTokens() {
	}
	protected void execute() throws IOException {
		Connection c = null;
		PreparedStatement q = null;
		try {
			c.setAutoCommit(false);
			long now = (new Date().getTime())/1000;
			q = c.prepareStatement("delete from token where expiry<? or created<?");
			q.setLong(1, now);
			q.setLong(2, now - Long.parseLong(.get("session.max_age""300")));
			q.close();
			q = null;
			// Remove any expired throttles associated with authentication
			q = c.prepareStatement("delete from throttle where updated < (? - (select value from setting where name='throttle.auth.lockout'))");
			q.setLong(1, new Date().getTime()/1000);
			q.close();
			q = null;
			c.commit();
			c.close();
			c = null;
catch(SQLException e) {
			throw new IOException(e);
finally {
			if(q != null) { try { q.close(); } catch(SQLException e) {} }
			if(c != null) {
				try { c.rollback(); } catch (SQLException e) { }
				try { c.close(); } catch (SQLException e) { }
			}
		}
	}
		return "{}";
	}
New to GrepCode? Check out our FAQ X