I am including two new files which *should* take care of anyone wanting
to use Turbine without a db context. The new files are TurbineNoDbUser
and TurbineNoDbUserPeer. They are basically just mirrors of the
original files with some obvious adjustments.
I am still having some problems but I willl post that note in the
morning as my 14-month-old is starting to cry...
josh
====
package org.apache.turbine.om.user;
/*
* Copyright (c) 1997-1999 The Java Apache Project. All rights
reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Java Apache
* Project for use in the Apache JServ servlet engine project
* <http://java.apache.org/>."
*
* 4. The names "Apache JServ", "Apache JServ Servlet Engine",
"Turbine",
* "Apache Turbine", "Turbine Project", "Apache Turbine Project" and
* "Java Apache Project" must not be used to endorse or promote
products
* derived from this software without prior written permission.
*
* 5. Products derived from this software may not be called "Apache
JServ"
* nor may "Apache" nor "Apache JServ" appear in their names without
* prior written permission of the Java Apache Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Java Apache
* Project for use in the Apache JServ servlet engine project
* <http://java.apache.org/>."
*
* THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JAVA APACHE PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Java Apache Group. For more information
* on the Java Apache Project and the Apache JServ Servlet Engine
project,
* please see <http://java.apache.org/>.
*
*/
// Java Core Classes
import java.util.*;
import java.io.*;
// Java Servlet Classes
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.turbine.om.BaseObject;
import org.apache.turbine.om.user.peer.TurbineNoDbUserPeer;
import org.apache.turbine.util.db.Criteria;
/**
* The User class describes a user in the system. This object is
* associated with a particular HttpSession. Data that you want
* to associate with a particular User can be stored here.
*
* @author Josh Lucas <a
href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
* @author Jon S. Stevens <a
href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
* @author John D. McNally
* @author Frank Y. Kim
*
*/
public class TurbineNoDbUser extends BaseObject implements User
{
/* A few attributes common to a User */
private java.util.Date createDate = null;
private java.util.Date lastAccessDate = null;
private int timeout = 15;
private static final String HAS_LOGGED_IN = "_has_logged_in";
/**
* This is here for debugging purposes during development. It
should
* not be depended upon to stay
*/
public String stackTrace = new String();
/** this is data that will survive a servlet engine restart */
private Hashtable permStorage = null;
/** this is data that will not survive a servlet engine restart */
private Hashtable tempStorage = null;
/**
* Create a new User and set the createDate.
*/
public TurbineNoDbUser()
{
createDate = new java.util.Date();
tempStorage = new Hashtable(10);
permStorage = new Hashtable(10);
setHasLoggedIn(new Boolean(false));
}
/**
* Gets the access counter for a user during a session.
*/
public int getAccessCounterForSession()
{
try
{
return ((Integer)
getTemp("_session_access_counter")).intValue();
}
catch (Exception e)
{
return 0;
}
}
/**
* Gets the access counter for a user from perm storage.
*/
public int getAccessCounter()
{
try
{
return ((Integer) getPerm("_access_counter")).intValue();
}
catch (Exception e)
{
return 0;
}
}
/**
* Gets the create date for this User. This is
* the time that the user object was created.
*/
public java.util.Date getCreateDate()
{
return createDate;
}
/** Not implemented. Included as example */
// public String getCitizenship()
// {
// return null;
// }
/** Not implemented. Included as example */
public String getCompanyName()
{
return null;
}
/**
* Gets the last access date for this User. This is
* the last time that the user object was referenced.
*/
public java.util.Date getLastAccessDate()
{
if ( lastAccessDate == null )
setLastAccessDate();
return lastAccessDate;
}
/**
* Get last login date/time.
*/
public java.util.Date getLastLogin()
{
return (java.util.Date)
getPerm(TurbineNoDbUserPeer.LAST_LOGIN);
}
/**
* Get password.
*/
public String getPassword()
{
return (String) getPerm(TurbineNoDbUserPeer.PASSWORD);
}
/**
* Get an object from permanent storage.
*/
public Object getPerm ( String name )
{
return permStorage.get (name);
}
/**
* Get an object from permant storage
* return default if value is null.
*/
public Object getPerm ( String name, Object def )
{
try
{
Object val = permStorage.get (name);
if ( val == null )
return def;
return val;
}
catch (Exception e)
{
return def;
}
}
/**
* This should only be used in the case where we want
* to save the data to the database.
*/
public Hashtable getPermStorage()
{
if ( this.permStorage == null )
this.permStorage = new Hashtable();
return this.permStorage;
}
/**
* Get an object from temporary storage.
*/
public Object getTemp ( String name )
{
return tempStorage.get (name);
}
/**
* Get an object from temporary storage
* return default if value is null.
*/
public Object getTemp ( String name, Object def )
{
try
{
Object val = tempStorage.get (name);
if ( val == null )
return def;
return val;
}
catch (Exception e)
{
return def;
}
}
/**
* A User object can have a variable Timeout which is
* defined in minutes. If the user has been timed out,
* then the hasLoggedIn() value will return false.
*/
public int getTimeout()
{
return this.timeout;
}
/**
* Returns the username for this user. If this is defined,
* then the user is considered logged in.
*/
public String getUserName()
{
String tmp = null;
try
{
tmp = (String) getPerm (TurbineNoDbUserPeer.USERNAME);
if ( tmp.length() == 0 )
tmp = null;
}
catch ( Exception e )
{
}
return tmp;
}
/**
* Returns the lastname for this user. If this is defined,
* then the user is considered logged in.
*/
public String getFirstName()
{
String tmp = null;
try
{
tmp = (String) getPerm (TurbineNoDbUserPeer.FIRST_NAME);
if ( tmp.length() == 0 )
tmp = null;
}
catch ( Exception e )
{
}
return tmp;
}
/**
* Returns the lastname for this user. If this is defined,
* then the user is considered logged in.
*/
public String getLastName()
{
String tmp = null;
try
{
tmp = (String) getPerm (TurbineNoDbUserPeer.LAST_NAME);
if ( tmp.length() == 0 )
tmp = null;
}
catch ( Exception e )
{
}
return tmp;
}
/**
* The user is considered logged in if they have not
* timedout.
*/
public boolean hasLoggedIn()
{
Boolean tmp = getHasLoggedIn();
if ( tmp != null && tmp.booleanValue())
return true;
else
return false;
}
/**
* Increments the permanent hit counter for the user.
*/
public void incrementAccessCounter()
{
setAccessCounter(getAccessCounter() + 1);
}
/**
* Increments the session hit counter for the user.
*/
public void incrementAccessCounterForSession()
{
setAccessCounterForSession(getAccessCounterForSession() + 1);
}
/**
* Remove an object from temporary storage and return the object
*/
public Object removeTemp ( String name )
{
return tempStorage.remove (name);
}
/*
* This function returns a TurbineUser which has been upcast to a
User.
*/
public User retrieveFromStorage( String username ) throws Exception
{
return this;
}
/*
* This function returns a TurbineUser which has been upcast to a
User.
*/
public User retrieveFromStorage( Integer visitorid ) throws
Exception
{
return this;
}
/*
* This function returns a TurbineUser which has been upcast to a
User.
*/
public User retrieveFromStorage( int visitorid ) throws Exception
{
return retrieveFromStorage ( new Integer(visitorid) );
}
/**
* Sets the access counter for a user...saved in perm storage.
*/
public void setAccessCounter(int cnt)
{
setPerm("_access_counter", new Integer(cnt));
}
/**
* Sets the session access counter for a user...saved in temp
storage.
*/
public void setAccessCounterForSession(int cnt)
{
setTemp("_session_access_counter", new Integer(cnt));
}
/**
* Sets the last access date for this User. This is
* the last time that the user object was referenced.
*/
public void setLastAccessDate()
{
lastAccessDate = new java.util.Date();
}
/**
* Sets the create date for this User. This is
* the time that the user object was created.
*/
public void setCreateDate(java.util.Date date)
{
createDate = date;
}
/**
* Set last Login date/time.
*/
public void setLastLogin(java.util.Date date)
{
setPerm( TurbineNoDbUserPeer.LAST_LOGIN, date );
}
/**
* Set password.
*/
public void setPassword(String password)
{
setPerm( TurbineNoDbUserPeer.PASSWORD, password );
}
/**
* Put an object into permanent storage.
*/
public void setPerm ( String name, Object value )
{
permStorage.put(name, value);
}
/**
* This should only be used in the case where we want
* to save the data to the database.
*/
public void setPermStorage(Hashtable stuff)
{
this.permStorage = stuff;
}
/**
* This should only be used in the case where we want
* to save the data to the database.
*/
public Hashtable getTempStorage()
{
if ( this.tempStorage == null )
this.tempStorage = new Hashtable();
return this.tempStorage;
}
/**
* This should only be used in the case where we want
* to save the data to the database.
*/
public void setTempStorage(Hashtable storage)
{
this.tempStorage = storage;
}
/**
* This gets whether or not someone has logged in.
* hasLoggedIn() returns this value as a boolean
* This is private because you should use hasLoggedIn()
* instead.
*/
private Boolean getHasLoggedIn()
{
return (Boolean) getTemp (HAS_LOGGED_IN);
}
/**
* This sets whether or not someone has logged in.
* hasLoggedIn() returns this value
*/
public void setHasLoggedIn (Boolean value)
{
setTemp (HAS_LOGGED_IN, value);
}
/**
* Put an object into temporary storage.
*/
public void setTemp ( String name, Object value )
{
tempStorage.put (name, value);
}
/**
* A User object can have a variable Timeout which is
* defined in minutes. If the user has been timed out,
* then the hasLoggedIn() value will return false.
*/
public void setTimeout(int time)
{
this.timeout = time;
}
/**
* Sets the username for this user.
*/
public void setUserName(String username)
{
setPerm (TurbineNoDbUserPeer.USERNAME, username);
}
/**
* updates the last login date in the database
*/
public void updateLastLogin() throws Exception
{
setTemp(TurbineNoDbUserPeer.LAST_LOGIN, new java.util.Date() );
}
/**
* Implement this method if you wish to be notified
* when the User has been Bound to the session.
*/
public void valueBound(HttpSessionBindingEvent hsbe)
{
// do not currently need this method
}
/**
* Implement this method if you wish to be notified
* when the User has been Unbound from the session.
*/
public void valueUnbound(HttpSessionBindingEvent hsbe)
{
}
public void saveToStorage() throws Exception
{
}
}
==========================
package org.apache.turbine.om.user.peer;
/*
* Copyright (c) 1997-1999 The Java Apache Project. All rights
reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Java Apache
* Project for use in the Apache JServ servlet engine project
* <http://java.apache.org/>."
*
* 4. The names "Apache JServ", "Apache JServ Servlet Engine",
"Turbine",
* "Apache Turbine", "Turbine Project", "Apache Turbine Project" and
* "Java Apache Project" must not be used to endorse or promote
products
* derived from this software without prior written permission.
*
* 5. Products derived from this software may not be called "Apache
JServ"
* nor may "Apache" nor "Apache JServ" appear in their names without
* prior written permission of the Java Apache Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Java Apache
* Project for use in the Apache JServ servlet engine project
* <http://java.apache.org/>."
*
* THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JAVA APACHE PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Java Apache Group. For more information
* on the Java Apache Project and the Apache JServ Servlet Engine
project,
* please see <http://java.apache.org/>.
*
*/
// Java Core Classes
import java.util.*;
import java.io.*;
// Turbine Utility Classes
import org.apache.turbine.util.*;
import org.apache.turbine.util.db.*;
import org.apache.turbine.util.db.map.*;
import org.apache.turbine.om.*;
import org.apache.turbine.om.peer.*;
import org.apache.turbine.om.user.*;
import org.apache.turbine.om.user.peer.*;
import org.apache.turbine.services.resources.TurbineResources;
/**
* This class handles all the meta info for the
* User/Visitor table.
*
* @author Josh Lucas
*/
public class TurbineNoDbUserPeer extends BasePeer
{
/** the mapBuilder for this Peer */
private static final TurbineMapBuilder mapBuilder =
(TurbineMapBuilder) getMapBuilder();
/** The column name for the visitor id field. */
private static final String VISITOR_ID_COLUMN =
mapBuilder.getVisitor_VisitorId();
/** The column name for the visitor id field. */
private static final String OBJECT_DATA_COLUMN = "OBJECTDATA";
/** The key name for the first name field. */
public static final String FIRST_NAME_COLUMN = "FIRST_NAME";
/** The key name for the last name field. */
public static final String LAST_NAME_COLUMN = "LAST_NAME";
/** The column name for the modified field. */
private static final String MODIFIED_COLUMN = "MODIFIED";
/** The column name for the created field. */
private static final String CREATED_COLUMN = "CREATED";
/** The column name for the last_login field. */
private static final String LAST_LOGIN_COLUMN = "LASTLOGIN";
/** The column name for the email field. */
private static final String EMAIL_COLUMN = "EMAIL";
/** The column name for the confirm_value field. */
private static final String CONFIRM_VALUE_COLUMN = "CONFIRM_VALUE";
/** this is the value that is stored in the database for confirmed
users */
public static final String CONFIRM_DATA = "CONFIRMED";
/** The table name for this peer. */
private static final String TABLE_NAME =
mapBuilder.getTableVisitor();
// Criteria Keys
/** The key name for the visitor id field. */
public static final String VISITOR_ID =
mapBuilder.getVisitor_VisitorId();
/** The key name for the first name field. */
public static final String FIRST_NAME = TABLE_NAME + "." +
FIRST_NAME_COLUMN;
/** The key name for the last name field. */
public static final String LAST_NAME = TABLE_NAME + "." +
LAST_NAME_COLUMN;
/** The key name for the username field. */
public static final String USERNAME =
mapBuilder.getVisitor_Username();
/** The key name for the password field. */
public static final String PASSWORD =
mapBuilder.getVisitor_Password();
/** The key name for the modified field. */
public static final String MODIFIED = TABLE_NAME + "." +
MODIFIED_COLUMN;
/** The key name for the created field. */
public static final String CREATED = TABLE_NAME + "." +
CREATED_COLUMN;
/** The key name for the last_login field. */
public static final String LAST_LOGIN =
mapBuilder.getVisitor_LastLogin();
/** The key name for the email field. */
public static final String EMAIL = TABLE_NAME + "." + EMAIL_COLUMN;
/** The key name for the confirm_value field. */
public static final String CONFIRM_VALUE = TABLE_NAME + "." +
CONFIRM_VALUE_COLUMN;
/** The key name for the object_data field. */
public static final String OBJECT_DATA =
mapBuilder.getVisitor_ObjectData();
/** The Oracle sequence name for this peer. */
private static final String SEQUENCE_NAME =
mapBuilder.getSequenceVisitor();
/**
Get the name of this table
*/
public static String getTableName()
{
return TABLE_NAME;
}
}
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]