KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > sessionEnhydra > persistent > PersistentSession


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: PersistentSession.java,v 1.2 2005/03/24 10:51:20 slobodan Exp $
23  */

24
25 package com.lutris.appserver.server.sessionEnhydra.persistent;
26
27 import java.io.Serializable JavaDoc;
28
29 import com.lutris.appserver.server.session.SessionException;
30 import com.lutris.appserver.server.sessionEnhydra.PagedSession;
31 import com.lutris.appserver.server.sessionEnhydra.StandardSessionManager;
32 import com.lutris.appserver.server.user.User;
33
34 /**
35  * A serializable version of BasicSession that
36  * can be written to persistent store.
37  *
38  * @version $Revision: 1.2 $
39  * @author Kyle Clark
40  */

41 public class PersistentSession extends PagedSession {
42
43     transient PersistentSessionHome sessionHome;
44
45     /**
46      * Need the following constructor in order to serialize?
47      */

48     public PersistentSession() {
49     }
50     
51     /**
52      * Construct a new session. Only called by <CODE>PersistentSessionHome</CODE>.
53      *
54      * @param sessionManager The session manager that will manager this session.
55      * @param sessionKey The unique session key associated with the session.
56      */

57     protected PersistentSession(StandardSessionManager sessionManager,
58                                 String JavaDoc sessionKey,
59                                 PersistentSessionHome sessionHome) {
60         super(sessionManager, sessionKey);
61         this.sessionHome = sessionHome;
62     }
63
64     /**
65      * Ensures that the user associated with the session is serializable.<p>
66      *
67      * @param user
68      * the user object to associate with the session.
69      * @exception SessionException
70      * if the user cannot be associated with the session.
71      */

72     public void setUser(User user) throws SessionException {
73         if (!(user instanceof Serializable JavaDoc)) {
74             throw new SessionException("Persistent session user must be serializable.");
75         }
76         super.setUser(user);
77         // Need to synchronize any changes to user since
78
// the session user table is maintained in the database.
79
DBUtil.dbUpdate(this, sessionHome.getDatabaseName());
80     }
81
82     /**
83      * Called when the session is read back into memory.
84      * Restores the (transient) session manager.
85      *
86      * @param mgr
87      * the session manager.
88      */

89     void restoreSessionManager(StandardSessionManager mgr) {
90         this.sessionManager = mgr;
91     }
92
93     /**
94      * Called when the session is read back into memory.
95      * Restores the (transient) session manager.
96      *
97      * @param mgr
98      * the session manager.
99      */

100     void restoreSessionHome(PersistentSessionHome home) {
101         this.sessionHome = home;
102     }
103
104 }
105
106
107
108
109
Popular Tags