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: UnusedQuery.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: import java.util.Vector;
30:
31: import com.lutris.appserver.server.sql.DBConnection;
32: import com.lutris.appserver.server.sql.ObjectIdException;
33: import com.lutris.appserver.server.sql.Query;
34:
35: /**
36: * Returns an unused session.
37: *
38: * @version $Revision: 1.3 $
39: * @author Kyle Clark
40: */
41: class UnusedQuery implements Query {
42:
43: UnusedQuery() {
44: }
45:
46: /**
47: * Method to query objects from the database.
48: *
49: * @param conn Handle to database connection.
50: * @exception java.sql.SQLException If a database access error occurs.
51: */
52: public ResultSet executeQuery(DBConnection conn)
53: throws SQLException {
54: // TODO - should select the oldest one.
55: String sql = "select sessionKey from "
56: + PersistentSessionHome.dbTableName
57: + " where isNew = ?";
58: PreparedStatement stmt = conn.prepareStatement(sql);
59: stmt.setString(1, "1");
60: return conn.executeQuery(stmt, sql);
61: }
62:
63: /**
64: * Method to get next object from query results.
65: *
66: * @param rs JDBC result set from which the next object
67: * will be instantiated.
68: * @exception java.sql.SQLException If a database access error occurs.
69: * @exception ObjectIdException If ObjectId was not found.
70: */
71: public Object next(ResultSet rs) throws SQLException {
72: // Vector v = new Vector();
73: if (rs.next()) {
74: return rs.getString("sessionKey");
75: }
76: return null;
77: }
78:
79: }
|