KickJava   Java API By Example, From Geeks To Geeks.

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


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: SessionQuery.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
31 import com.lutris.appserver.server.sql.DBConnection;
32 import com.lutris.appserver.server.sql.Query;
33
34 /**
35  * Queries a session from the database.
36  *
37  * @version $Revision: 1.2 $
38  * @author Kyle Clark
39  */

40 class SessionQuery implements Query {
41
42     private String JavaDoc sessionKey;
43     private ClassLoader JavaDoc loader;
44
45     /**
46      * @param sessionKey
47      * the key for the session that should be retrieved.
48      * @param loader
49      * the class loader to use when loading the serialized
50      * session data.
51      */

52     SessionQuery(String JavaDoc sessionKey, ClassLoader JavaDoc loader) {
53         this.sessionKey = sessionKey;
54         this.loader = loader;
55     }
56
57     /**
58      * Method to query objects from the database.
59      *
60      * @param conn Handle to database connection.
61      * @exception java.sql.SQLException If a database access error occurs.
62      */

63     public ResultSet JavaDoc executeQuery(DBConnection conn)
64         throws SQLException JavaDoc {
65         String JavaDoc sql = "select * from " + PersistentSessionHome.dbTableName
66             + " where sessionKey = ?";
67         PreparedStatement JavaDoc stmt = conn.prepareStatement(sql);
68         stmt.setString(1, sessionKey);
69         return conn.executeQuery(stmt, sql);
70     }
71
72     /**
73      * Method to get next object from query results.
74      *
75      * @param rs JDBC result set from which the next object
76      * will be instantiated.
77      * @exception SQLException If a database access error occurs.
78      */

79     public Object JavaDoc next(ResultSet JavaDoc rs) throws SQLException JavaDoc {
80         try {
81             if (rs.next()) {
82                 return new PersistentSessionDO(rs, loader).getSession();
83             }
84         } catch (SQLException JavaDoc e) {
85             throw e;
86         } catch (Exception JavaDoc e) {
87             throw new SQLException JavaDoc(e.getMessage());
88         }
89         return null;
90     }
91
92 }
93
Popular Tags