Sessions don't need integer ids. We can just pretend like they're not there and

this code will work equally well on our existing sessions tables and new ones
that have no sessionId.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2577 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
samskivert
2009-06-22 18:26:44 +00:00
parent 62a87561ea
commit 972c741ae3
@@ -267,17 +267,16 @@ public class UserRepository extends JORARepository
throws PersistenceException throws PersistenceException
{ {
// look for an existing session for this user // look for an existing session for this user
final String query = "select sessionId, authcode from sessions " + final String query = "select authcode from sessions where userId = " + user.userId;
"where userId = " + user.userId; String authcode = execute(new Operation<String>() {
Tuple<Integer,String> session = execute(new Operation<Tuple<Integer,String>>() { public String invoke (Connection conn, DatabaseLiaison liaison)
public Tuple<Integer,String> invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException throws PersistenceException, SQLException
{ {
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
try { try {
ResultSet rs = stmt.executeQuery(query); ResultSet rs = stmt.executeQuery(query);
while (rs.next()) { while (rs.next()) {
return new Tuple<Integer,String>(rs.getInt(1), rs.getString(2)); return rs.getString(1);
} }
return null; return null;
} finally { } finally {
@@ -292,16 +291,15 @@ public class UserRepository extends JORARepository
Date expires = new Date(cal.getTime().getTime()); Date expires = new Date(cal.getTime().getTime());
// if we found one, update its expires time and reuse it // if we found one, update its expires time and reuse it
if (session != null) { if (authcode != null) {
update("update sessions set expires = '" + expires + "' " + update("update sessions set expires = '" + expires + "' where authcode = " + authcode);
"where sessionId = " + session.left); } else {
return session.right; // otherwise create a new one and insert it into the table
authcode = UserUtil.genAuthCode(user);
update("insert into sessions (authcode, userId, expires) values('" + authcode + "', " +
user.userId + ", '" + expires + "')");
} }
// otherwise create a new one and insert it into the table
String authcode = UserUtil.genAuthCode(user);
update("insert into sessions (authcode, userId, expires) values('" + authcode + "', " +
user.userId + ", '" + expires + "')");
return authcode; return authcode;
} }