001: /**
002: * com.mckoi.database.User 22 Jul 2000
003: *
004: * Mckoi SQL Database ( http://www.mckoi.com/database )
005: * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * Version 2 as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License Version 2 for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * Version 2 along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: * Change Log:
021: *
022: *
023: */package com.mckoi.database;
024:
025: import com.mckoi.util.Cache;
026:
027: /**
028: * Encapsulates the information about a single user logged into the system.
029: * The class provides access to information in the user database.
030: * <p>
031: * This object also serves as a storage for session state information. For
032: * example, this object stores the triggers that this session has created.
033: * <p>
034: * NOTE: This object is not immutable. The same user may log into the system
035: * and it will result in a new User object being created.
036: *
037: * @author Tobias Downer
038: */
039:
040: public final class User {
041:
042: /**
043: * The name of the user.
044: */
045: private String user_name;
046:
047: /**
048: * The database object that this user is currently logged into.
049: */
050: private Database database;
051:
052: /**
053: * The connection string that identifies how this user is connected to the
054: * database.
055: */
056: private String connection_string;
057:
058: /**
059: * The time this user connected.
060: */
061: private long time_connected;
062:
063: /**
064: * The last time this user executed a command on the connection.
065: */
066: private long last_command_time;
067:
068: /**
069: * The Constructor. This takes a user name and gets the privs for them.
070: * <p>
071: * Note that this method should only be created from within a Database
072: * object.
073: */
074: User(String user_name, Database database, String connection_string,
075: long time_connected) {
076: this .user_name = user_name;
077: this .database = database;
078: this .connection_string = connection_string;
079: this .time_connected = time_connected;
080: this .last_command_time = time_connected;
081: }
082:
083: /**
084: * Returns the name of the user.
085: */
086: public String getUserName() {
087: return user_name;
088: }
089:
090: /**
091: * Returns the string that describes how this user is connected to the
092: * engine. This is set by the protocol layer.
093: */
094: public String getConnectionString() {
095: return connection_string;
096: }
097:
098: /**
099: * Returns the time the user connected.
100: */
101: public long getTimeConnected() {
102: return time_connected;
103: }
104:
105: /**
106: * Returnst the last time a command was executed by this user.
107: */
108: public long getLastCommandTime() {
109: return last_command_time;
110: }
111:
112: /**
113: * Returns the Database object that this user belongs to.
114: */
115: public Database getDatabase() {
116: return database;
117: }
118:
119: /**
120: * Refreshes the last time a command was executed by this user.
121: */
122: public final void refreshLastCommandTime() {
123: last_command_time = System.currentTimeMillis();
124: }
125:
126: /**
127: * Logs out this user object. This will log the user out of the user manager.
128: */
129: public void logout() {
130: // Clear all triggers for this user,
131: UserManager user_manager = database.getUserManager();
132: if (user_manager != null) {
133: user_manager.userLoggedOut(this);
134: }
135: }
136:
137: }
|