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: KeyExistsQuery.java,v 1.3 2007-10-19 10:05:39 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: * Performs a query to determine if a session key exists.
35: *
36: * @version $Revision: 1.3 $
37: * @author Kyle Clark
38: */
39: class KeyExistsQuery implements Query {
40:
41: private String sessionKey;
42:
43: /**
44: * @param sessionKey
45: * the key for the session that should be retrieved.
46: */
47: KeyExistsQuery(String sessionKey) {
48: this .sessionKey = sessionKey;
49: }
50:
51: /**
52: * Method to query the existence of the key.
53: *
54: * @param conn Handle to database connection.
55: * @exception java.sql.SQLException If a database access error occurs.
56: */
57: public ResultSet executeQuery(DBConnection conn)
58: throws SQLException {
59: String sql = "select sessionKey from "
60: + PersistentSessionHome.dbTableName
61: + " where sessionKey = ?";
62: PreparedStatement stmt = conn.prepareStatement(sql);
63: stmt.setString(1, sessionKey);
64: return conn.executeQuery(stmt, sql);
65: }
66:
67: /**
68: * Returns Boolean(true) if the key exists. Boolean(false) otherwise.
69: *
70: * @param rs
71: * result set from which the next object will be instantiated.
72: * @return Boolean
73: * indicating if the key exists.
74: * @exception SQLException
75: * if a database access error occurs.
76: */
77: public Object next(ResultSet rs) throws SQLException {
78: if (rs.next()) {
79: return Boolean.valueOf(true);
80: } else {
81: return Boolean.valueOf(false);
82: }
83: }
84:
85: }
|