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: PersistentSession.java,v 1.3 2007-10-19 10:05:39 sinisa Exp $
022: */
023:
024: package com.lutris.appserver.server.sessionEnhydra.persistent;
025:
026: import java.io.Serializable;
027:
028: import com.lutris.appserver.server.session.SessionException;
029: import com.lutris.appserver.server.sessionEnhydra.PagedSession;
030: import com.lutris.appserver.server.sessionEnhydra.StandardSessionManager;
031: import com.lutris.appserver.server.user.User;
032:
033: /**
034: * A serializable version of BasicSession that
035: * can be written to persistent store.
036: *
037: * @version $Revision: 1.3 $
038: * @author Kyle Clark
039: */
040: public class PersistentSession extends PagedSession {
041:
042: transient PersistentSessionHome sessionHome;
043:
044: /**
045: * Need the following constructor in order to serialize?
046: */
047: public PersistentSession() {
048: }
049:
050: /**
051: * Construct a new session. Only called by <CODE>PersistentSessionHome</CODE>.
052: *
053: * @param sessionManager The session manager that will manager this session.
054: * @param sessionKey The unique session key associated with the session.
055: */
056: protected PersistentSession(StandardSessionManager sessionManager,
057: String sessionKey, PersistentSessionHome sessionHome) {
058: super (sessionManager, sessionKey);
059: this .sessionHome = sessionHome;
060: }
061:
062: /**
063: * Ensures that the user associated with the session is serializable.<p>
064: *
065: * @param user
066: * the user object to associate with the session.
067: * @exception SessionException
068: * if the user cannot be associated with the session.
069: */
070: public void setUser(User user) throws SessionException {
071: /* Alex
072: * if (!(user instanceof Serializable)) {
073: throw new SessionException("Persistent session user must be serializable.");
074: }*/
075: super .setUser(user);
076: // Need to synchronize any changes to user since
077: // the session user table is maintained in the database.
078: DBUtil.dbUpdate(this , sessionHome.getDatabaseName());
079: }
080:
081: /**
082: * Called when the session is read back into memory.
083: * Restores the (transient) session manager.
084: *
085: * @param mgr
086: * the session manager.
087: */
088: void restoreSessionManager(StandardSessionManager mgr) {
089: this .sessionManager = mgr;
090: }
091:
092: /**
093: * Called when the session is read back into memory.
094: * Restores the (transient) session manager.
095: *
096: * @param mgr
097: * the session manager.
098: */
099: void restoreSessionHome(PersistentSessionHome home) {
100: this.sessionHome = home;
101: }
102:
103: }
|