Make sure to call ensureConnection() before accessing the database

directly (most calls should be via execute() but those that are not must
be sure that the connection is established).


git-svn-id: https://samskivert.googlecode.com/svn/trunk@118 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2001-05-26 03:23:22 +00:00
parent d2c770dafd
commit e0136b4ad8
@@ -1,5 +1,5 @@
// //
// $Id: UserRepository.java,v 1.6 2001/03/04 06:14:14 mdb Exp $ // $Id: UserRepository.java,v 1.7 2001/05/26 03:23:22 mdb Exp $
package com.samskivert.servlet.user; package com.samskivert.servlet.user;
@@ -109,6 +109,9 @@ public class UserRepository extends MySQLRepository
public User loadUser (String username) public User loadUser (String username)
throws SQLException throws SQLException
{ {
// make sure our session is established
ensureConnection();
// look up the user // look up the user
Cursor ec = _utable.select("where username = '" + username + "'"); Cursor ec = _utable.select("where username = '" + username + "'");
@@ -131,6 +134,9 @@ public class UserRepository extends MySQLRepository
public User loadUser (int userid) public User loadUser (int userid)
throws SQLException throws SQLException
{ {
// make sure our session is established
ensureConnection();
// look up the user // look up the user
Cursor ec = _utable.select("where userid = " + userid); Cursor ec = _utable.select("where userid = " + userid);
@@ -153,6 +159,9 @@ public class UserRepository extends MySQLRepository
public User loadUserBySession (String sessionKey) public User loadUserBySession (String sessionKey)
throws SQLException throws SQLException
{ {
// make sure our session is established
ensureConnection();
// look up the user // look up the user
Cursor ec = _utable.select("sessions", Cursor ec = _utable.select("sessions",
"where authcode = '" + sessionKey + "where authcode = '" + sessionKey +
@@ -269,6 +278,9 @@ public class UserRepository extends MySQLRepository
protected String[] loadNames (int[] userids, String column) protected String[] loadNames (int[] userids, String column)
throws SQLException throws SQLException
{ {
// make sure our session is established
ensureConnection();
// if userids is zero length, we've got no work to do // if userids is zero length, we've got no work to do
if (userids.length == 0) { if (userids.length == 0) {
return new String[0]; return new String[0];