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: SessionQuery.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:
30: import com.lutris.appserver.server.sql.DBConnection;
31: import com.lutris.appserver.server.sql.Query;
32:
33: /**
34: * Queries a session from the database.
35: *
36: * @version $Revision: 1.2 $
37: * @author Kyle Clark
38: */
39: class SessionQuery implements Query {
40:
41: private String sessionKey;
42: private ClassLoader loader;
43:
44: /**
45: * @param sessionKey
46: * the key for the session that should be retrieved.
47: * @param loader
48: * the class loader to use when loading the serialized
49: * session data.
50: */
51: SessionQuery(String sessionKey, ClassLoader loader) {
52: this .sessionKey = sessionKey;
53: this .loader = loader;
54: }
55:
56: /**
57: * Method to query objects from the database.
58: *
59: * @param conn Handle to database connection.
60: * @exception java.sql.SQLException If a database access error occurs.
61: */
62: public ResultSet executeQuery(DBConnection conn)
63: throws SQLException {
64: String sql = "select * from "
65: + PersistentSessionHome.dbTableName
66: + " where sessionKey = ?";
67: PreparedStatement 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 next(ResultSet rs) throws SQLException {
80: try {
81: if (rs.next()) {
82: return new PersistentSessionDO(rs, loader).getSession();
83: }
84: } catch (SQLException e) {
85: throw e;
86: } catch (Exception e) {
87: throw new SQLException(e.getMessage());
88: }
89: return null;
90: }
91:
92: }
|