{
final Slot<Authenticated> retval = new Slot<Authenticated>();
if (realm==null) {
DBConnection connection = db.getConnection();
try {
connection.query(AuthDB.USER_AUTHENTICATED, new DBQueryHandler() {
public void prepare(PreparedStatement s)
throws SQLException
{
s.setInt(1,id);
s.setString(2,session.toString());
}
public void onResults(ResultSet set)
throws SQLException
{
if (set.next()) {
Timestamp created = set.getTimestamp(2);
Timestamp expiration = set.getTimestamp(3);
Authenticated auth = new Authenticated(db,set.getInt(1),session,created,expiration,User.this,realm);
retval.set(auth);
}
}
});
if (retval.get().isExpired()) {
// the session has expired
retval.get().delete();
retval.set(null);
}
} finally {
db.release(connection);
}
} else {
DBConnection connection = db.getConnection();
try {
connection.query(AuthDB.REALM_USER_AUTHENTICATED, new DBQueryHandler() {
public void prepare(PreparedStatement s)
throws SQLException
{
s.setInt(1,id);
s.setInt(2,realm.getId());