KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > sessionEnhydra > persistent > UserSessionsQuery


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: UserSessionsQuery.java,v 1.2 2005/03/24 10:51:20 slobodan Exp $
23  */

24
25 package com.lutris.appserver.server.sessionEnhydra.persistent;
26
27 import java.sql.PreparedStatement JavaDoc;
28 import java.sql.ResultSet JavaDoc;
29 import java.sql.SQLException JavaDoc;
30 import java.util.Vector JavaDoc;
31
32 import com.lutris.appserver.server.sql.DBConnection;
33 import com.lutris.appserver.server.sql.Query;
34 import com.lutris.appserver.server.user.User;
35
36 /**
37  * Queries the sessions associated with a user.
38  *
39  * @version $Revision: 1.2 $
40  * @author Kyle Clark
41  */

42 class UserSessionsQuery implements Query {
43
44     private User user;
45
46     /**
47      * @param sessionKey
48      * the key for the session that should be retrieved.
49      */

50     UserSessionsQuery(User user) {
51         this.user = user;
52     }
53
54     /**
55      * Method to query the user's session keys.
56      *
57      * @param conn Handle to database connection.
58      * @exception java.sql.SQLException If a database access error occurs.
59      */

60     public ResultSet JavaDoc executeQuery(DBConnection conn)
61         throws SQLException JavaDoc {
62         String JavaDoc sql = "select sessionKey from "
63             + PersistentSessionHome.dbTableName
64             + " where userName = ?";
65         PreparedStatement JavaDoc stmt = conn.prepareStatement(sql);
66         stmt.setString(1, user.getName());
67         return conn.executeQuery(stmt, sql);
68     }
69
70     /**
71      * Returns an enumeration of the session keys associated with
72      * the user.
73      *
74      * @return Enumeration of session keys.
75      * @param rs result set from which sesison keys enumeration
76      * will be instantiated.
77      * @return an Enumration of session keys.
78      * @exception SQLException If a database access error occurs.
79      */

80     public Object JavaDoc next(ResultSet JavaDoc rs) throws SQLException JavaDoc {
81         Vector JavaDoc v = new Vector JavaDoc();
82         while (rs.next()) {
83             v.addElement(rs.getString("sessionKey"));
84         }
85         return v.elements();
86     }
87
88 }
89
Popular Tags