01: /*
02: * Enhydra Java Application Server Project
03: *
04: * The contents of this file are subject to the Enhydra Public License
05: * Version 1.1 (the "License"); you may not use this file except in
06: * compliance with the License. You may obtain a copy of the License on
07: * the Enhydra web site ( http://www.enhydra.org/ ).
08: *
09: * Software distributed under the License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11: * the License for the specific terms governing rights and limitations
12: * under the License.
13: *
14: * The Initial Developer of the Enhydra Application Server is Lutris
15: * Technologies, Inc. The Enhydra Application Server and portions created
16: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17: * All Rights Reserved.
18: *
19: * Contributor(s):
20: *
21: * $Id: UserSessionsQuery.java,v 1.2 2006-06-15 13:47:00 sinisa Exp $
22: */
23:
24: package com.lutris.appserver.server.sessionEnhydra.persistent;
25:
26: import java.sql.PreparedStatement;
27: import java.sql.ResultSet;
28: import java.sql.SQLException;
29: import java.util.Vector;
30:
31: import com.lutris.appserver.server.sql.DBConnection;
32: import com.lutris.appserver.server.sql.Query;
33: import com.lutris.appserver.server.user.User;
34:
35: /**
36: * Queries the sessions associated with a user.
37: *
38: * @version $Revision: 1.2 $
39: * @author Kyle Clark
40: */
41: class UserSessionsQuery implements Query {
42:
43: private User user;
44:
45: /**
46: * @param sessionKey
47: * the key for the session that should be retrieved.
48: */
49: UserSessionsQuery(User user) {
50: this .user = user;
51: }
52:
53: /**
54: * Method to query the user's session keys.
55: *
56: * @param conn Handle to database connection.
57: * @exception java.sql.SQLException If a database access error occurs.
58: */
59: public ResultSet executeQuery(DBConnection conn)
60: throws SQLException {
61: String sql = "select sessionKey from "
62: + PersistentSessionHome.dbTableName
63: + " where userName = ?";
64: PreparedStatement stmt = conn.prepareStatement(sql);
65: stmt.setString(1, user.getName());
66: return conn.executeQuery(stmt, sql);
67: }
68:
69: /**
70: * Returns an enumeration of the session keys associated with
71: * the user.
72: *
73: * @return Enumeration of session keys.
74: * @param rs result set from which sesison keys enumeration
75: * will be instantiated.
76: * @return an Enumration of session keys.
77: * @exception SQLException If a database access error occurs.
78: */
79: public Object next(ResultSet rs) throws SQLException {
80: Vector v = new Vector();
81: while (rs.next()) {
82: v.addElement(rs.getString("sessionKey"));
83: }
84: return v.elements();
85: }
86:
87: }
|