001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: PersistentSessionUserTable.java,v 1.2 2006-06-15 13:44:07 sinisa Exp $
022: */
023:
024: package com.lutris.appserver.server.sessionEnhydra.persistent;
025:
026: import java.util.Enumeration;
027:
028: import com.lutris.appserver.server.session.SessionException;
029: import com.lutris.appserver.server.sessionEnhydra.StandardSessionUserTable;
030: import com.lutris.appserver.server.user.User;
031: import com.lutris.util.Config;
032: import com.lutris.util.ConfigException;
033:
034: /**
035: * Table used by StandardSessionManager to cross reference <CODE>User</CODE>
036: * objects and sessions.<p>
037: *
038: * @version $Revision: 1.2 $
039: * @author Kyle Clark
040: */
041: public class PersistentSessionUserTable implements
042: StandardSessionUserTable {
043:
044: String dbName = null;
045:
046: /**
047: * @param config
048: * configuration options for this table - currently ignored.
049: */
050: public PersistentSessionUserTable(Config config)
051: throws ConfigException {
052: // This is a bit messy....
053: dbName = PersistentSessionHome.getDatabaseName(config);
054: }
055:
056: /**
057: * Add a session key to the user to session xref table.
058: *
059: * @param session
060: * The session key.
061: * @param user
062: * the user to associated with the session key.
063: */
064: public void add(String sessionKey, User user) {
065: // noop - maintained in DB
066: }
067:
068: /**
069: * Remove a session from the user to session mapping table.
070: * If the session is not it the table, it is ignored.
071: *
072: * @param session The session object, with the user already
073: * filled in.
074: */
075: public void remove(String sessionKey, User user) {
076: // noop - maintained in DB
077: }
078:
079: /**
080: * Remove a session from the user to session mapping table.
081: * If the session is not it the table, it is ignored.
082: *
083: * @param session The session object, with the user already
084: * filled in.
085: */
086: public void remove(String sessionKey) {
087: // noop - maintained in DB
088: }
089:
090: /**
091: * Get the number of sessions for a user.
092: *
093: * @param user The user object to check for.
094: * @return The count of the number of sessions associated with this
095: * user.
096: * @exception SessionException if an error occurs.
097: */
098: public int numSessions(User user) throws SessionException {
099: try {
100: UserNumSessionsQuery q = new UserNumSessionsQuery(user);
101: Integer num = (Integer) DBUtil.dbQuery(q, dbName);
102: return num.intValue();
103: } catch (Exception e) {
104: throw new SessionException(e);
105: }
106: }
107:
108: /**
109: * Returns the session keys associated with a particular user.
110: *
111: * @param user The user object to check for.
112: * @return An enumeration of the session keys associated
113: * with the user.
114: * @exception SessionException if an error occurs.
115: */
116: public Enumeration getSessionKeys(User user)
117: throws SessionException {
118: try {
119: UserSessionsQuery q = new UserSessionsQuery(user);
120: return (Enumeration) DBUtil.dbQuery(q, dbName);
121: } catch (Exception e) {
122: throw new SessionException(e);
123: }
124: }
125:
126: /**
127: * Shutdown this session user table as required. The session
128: * user table should not be used after this method has been called
129: */
130: public void shutdown() {
131: // noop
132: }
133:
134: }
|