KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > User


1 /**
2  * com.mckoi.database.User 22 Jul 2000
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database;
26
27 import com.mckoi.util.Cache;
28
29 /**
30  * Encapsulates the information about a single user logged into the system.
31  * The class provides access to information in the user database.
32  * <p>
33  * This object also serves as a storage for session state information. For
34  * example, this object stores the triggers that this session has created.
35  * <p>
36  * NOTE: This object is not immutable. The same user may log into the system
37  * and it will result in a new User object being created.
38  *
39  * @author Tobias Downer
40  */

41
42 public final class User {
43
44   /**
45    * The name of the user.
46    */

47   private String JavaDoc user_name;
48
49   /**
50    * The database object that this user is currently logged into.
51    */

52   private Database database;
53
54   /**
55    * The connection string that identifies how this user is connected to the
56    * database.
57    */

58   private String JavaDoc connection_string;
59
60   /**
61    * The time this user connected.
62    */

63   private long time_connected;
64
65   /**
66    * The last time this user executed a command on the connection.
67    */

68   private long last_command_time;
69
70   /**
71    * The Constructor. This takes a user name and gets the privs for them.
72    * <p>
73    * Note that this method should only be created from within a Database
74    * object.
75    */

76   User(String JavaDoc user_name, Database database,
77        String JavaDoc connection_string, long time_connected) {
78     this.user_name = user_name;
79     this.database = database;
80     this.connection_string = connection_string;
81     this.time_connected = time_connected;
82     this.last_command_time = time_connected;
83   }
84
85   /**
86    * Returns the name of the user.
87    */

88   public String JavaDoc getUserName() {
89     return user_name;
90   }
91
92   /**
93    * Returns the string that describes how this user is connected to the
94    * engine. This is set by the protocol layer.
95    */

96   public String JavaDoc getConnectionString() {
97     return connection_string;
98   }
99
100   /**
101    * Returns the time the user connected.
102    */

103   public long getTimeConnected() {
104     return time_connected;
105   }
106
107   /**
108    * Returnst the last time a command was executed by this user.
109    */

110   public long getLastCommandTime() {
111     return last_command_time;
112   }
113
114   /**
115    * Returns the Database object that this user belongs to.
116    */

117   public Database getDatabase() {
118     return database;
119   }
120
121   /**
122    * Refreshes the last time a command was executed by this user.
123    */

124   public final void refreshLastCommandTime() {
125     last_command_time = System.currentTimeMillis();
126   }
127
128   /**
129    * Logs out this user object. This will log the user out of the user manager.
130    */

131   public void logout() {
132     // Clear all triggers for this user,
133
UserManager user_manager = database.getUserManager();
134     if (user_manager != null) {
135       user_manager.userLoggedOut(this);
136     }
137   }
138
139 }
140
Popular Tags