You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bi...@apache.org on 2001/04/26 05:15:01 UTC

cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session JDBCStore.java StoreBase.java

bip         01/04/25 20:15:01

  Modified:    catalina/src/share/org/apache/catalina/session
                        JDBCStore.java StoreBase.java
  Log:
  Changed subclassing of start()/stop().
  Cosmetic changes, tabs to spaces.
  
  Revision  Changes    Path
  1.2       +383 -378  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/JDBCStore.java
  
  Index: JDBCStore.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/JDBCStore.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCStore.java	2001/04/26 01:37:59	1.1
  +++ JDBCStore.java	2001/04/26 03:14:59	1.2
  @@ -1,8 +1,8 @@
   /*
    * JDBCStore.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/JDBCStore.java,v 1.1 2001/04/26 01:37:59 bip Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/04/26 01:37:59 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/JDBCStore.java,v 1.2 2001/04/26 03:14:59 bip Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/04/26 03:14:59 $
    *
    * ====================================================================
    *
  @@ -81,6 +81,7 @@
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import org.apache.catalina.Container;
  +import org.apache.catalina.LifecycleException;
   import org.apache.catalina.Loader;
   import org.apache.catalina.Session;
   import org.apache.catalina.Store;
  @@ -92,7 +93,7 @@
    * saved are still subject to being expired based on inactivity.
    *
    * @author Bip Thelin
  - * @version $Revision: 1.1 $, $Date: 2001/04/26 01:37:59 $
  + * @version $Revision: 1.2 $, $Date: 2001/04/26 03:14:59 $
    */
   
   public class JDBCStore
  @@ -198,21 +199,21 @@
        * Return the info for this Store.
        */
       public String getInfo() {
  -	return(info);
  +        return(info);
       }
   
       /**
        * Return the thread name for this Store.
        */
       public String getThreadName() {
  -	return(threadName);
  +        return(threadName);
       }
   
       /**
        * Return the name for this Store, used for logging.
        */
       public String getStoreName() {
  -	return(storeName);
  +        return(storeName);
       }
   
       /**
  @@ -221,19 +222,19 @@
        * @param driverName The new driver
        */
       public void setDriverName(String driverName) {
  -	String oldDriverName = this.driverName;
  -	this.driverName = driverName;
  -	support.firePropertyChange("driverName",
  -				   oldDriverName,
  -				   this.driverName);
  -	this.driverName = driverName;
  +        String oldDriverName = this.driverName;
  +        this.driverName = driverName;
  +        support.firePropertyChange("driverName",
  +                                   oldDriverName,
  +                                   this.driverName);
  +        this.driverName = driverName;
       }
   
       /**
        * Return the driver for this Store.
        */
       public String getDriverName() {
  -	return(this.driverName);
  +        return(this.driverName);
       }
   
       /**
  @@ -242,18 +243,18 @@
        * @param connectionURL The new Connection URL
        */
       public void setConnectionURL(String connectionURL) {
  -	String oldConnString = this.connString;
  -	this.connString = connectionURL;
  -	support.firePropertyChange("connString",
  -				   oldConnString,
  -				   this.connString);
  +        String oldConnString = this.connString;
  +        this.connString = connectionURL;
  +        support.firePropertyChange("connString",
  +                                   oldConnString,
  +                                   this.connString);
       }
   
       /**
        * Return the Connection URL for this Store.
        */
       public String getConnectionURL() {
  -	return(this.connString);
  +        return(this.connString);
       }
   
       /**
  @@ -262,18 +263,18 @@
        * @param sessionTable The new table
        */
       public void setSessionTable(String sessionTable) {
  -	String oldSessionTable = this.sessionTable;
  -	this.sessionTable = sessionTable;
  -	support.firePropertyChange("sessionTable",
  -				   oldSessionTable,
  -				   this.sessionTable);
  +        String oldSessionTable = this.sessionTable;
  +        this.sessionTable = sessionTable;
  +        support.firePropertyChange("sessionTable",
  +                                   oldSessionTable,
  +                                   this.sessionTable);
       }
   
       /**
        * Return the table for this Store.
        */
       public String getSessionTable() {
  -	return(this.sessionTable);
  +        return(this.sessionTable);
       }
   
       /**
  @@ -282,18 +283,18 @@
        * @param sessionIdCol the column name
        */
       public void setSessionIdCol(String sessionIdCol) {
  -	String oldSessionIdCol = this.sessionIdCol;
  -	this.sessionIdCol = sessionIdCol;
  -	support.firePropertyChange("sessionIdCol",
  -				   oldSessionIdCol,
  -				   this.sessionIdCol);
  +        String oldSessionIdCol = this.sessionIdCol;
  +        this.sessionIdCol = sessionIdCol;
  +        support.firePropertyChange("sessionIdCol",
  +                                   oldSessionIdCol,
  +                                   this.sessionIdCol);
       }
   
       /**
        * Return the Id column for the table.
        */
       public String getSessionIdCol() {
  -	return(this.sessionIdCol);
  +        return(this.sessionIdCol);
       }
   
       /**
  @@ -302,18 +303,18 @@
        * @param sessionDataCol the column name
        */
       public void setSessionDataCol(String sessionDataCol) {
  -	String oldSessionDataCol = this.sessionDataCol;
  -	this.sessionDataCol = sessionDataCol;
  -	support.firePropertyChange("sessionDataCol",
  -				   oldSessionDataCol,
  -				   this.sessionDataCol);
  +        String oldSessionDataCol = this.sessionDataCol;
  +        this.sessionDataCol = sessionDataCol;
  +        support.firePropertyChange("sessionDataCol",
  +                                   oldSessionDataCol,
  +                                   this.sessionDataCol);
       }
   
       /**
        * Return the data column for the table
        */
       public String getSessionDataCol() {
  -	return(this.sessionDataCol);
  +        return(this.sessionDataCol);
       }
   
       /**
  @@ -322,18 +323,18 @@
        * @param sessionValidCol The column name
        */
       public void setSessionValidCol(String sessionValidCol) {
  -	String oldSessionValidCol = this.sessionValidCol;
  -	this.sessionValidCol = sessionValidCol;
  -	support.firePropertyChange("sessionValidCol",
  -				   oldSessionValidCol,
  -				   this.sessionValidCol);
  +        String oldSessionValidCol = this.sessionValidCol;
  +        this.sessionValidCol = sessionValidCol;
  +        support.firePropertyChange("sessionValidCol",
  +                                   oldSessionValidCol,
  +                                   this.sessionValidCol);
       }
   
       /**
        * Return the Is Valid column
        */
       public String getSessionValidCol() {
  -	return(this.sessionValidCol);
  +        return(this.sessionValidCol);
       }
   
       /**
  @@ -342,18 +343,18 @@
        * @param sessionMaxInactiveCol The column name
        */
       public void setSessionMaxInactiveCol(String sessionMaxInactiveCol) {
  -	String oldSessionMaxInactiveCol = this.sessionMaxInactiveCol;
  -	this.sessionMaxInactiveCol = sessionMaxInactiveCol;
  -	support.firePropertyChange("sessionMaxInactiveCol",
  -				   oldSessionMaxInactiveCol,
  -				   this.sessionMaxInactiveCol);
  +        String oldSessionMaxInactiveCol = this.sessionMaxInactiveCol;
  +        this.sessionMaxInactiveCol = sessionMaxInactiveCol;
  +        support.firePropertyChange("sessionMaxInactiveCol",
  +                                   oldSessionMaxInactiveCol,
  +                                   this.sessionMaxInactiveCol);
       }
   
       /**
        * Return the Max Inactive column
        */
       public String getSessionMaxInactiveCol() {
  -	return(this.sessionMaxInactiveCol);
  +        return(this.sessionMaxInactiveCol);
       }
   
       /**
  @@ -362,18 +363,18 @@
        * @param sessionLastAccessedCol The column name
        */
       public void setSessionLastAccessedCol(String sessionLastAccessedCol) {
  -	String oldSessionLastAccessedCol = this.sessionLastAccessedCol;
  -	this.sessionLastAccessedCol = sessionLastAccessedCol;
  -	support.firePropertyChange("sessionLastAccessedCol",
  -				   oldSessionLastAccessedCol,
  -				   this.sessionLastAccessedCol);
  +        String oldSessionLastAccessedCol = this.sessionLastAccessedCol;
  +        this.sessionLastAccessedCol = sessionLastAccessedCol;
  +        support.firePropertyChange("sessionLastAccessedCol",
  +                                   oldSessionLastAccessedCol,
  +                                   this.sessionLastAccessedCol);
       }
   
       /**
        * Return the Last Accessed column
        */
       public String getSessionLastAccessedCol() {
  -	return(this.sessionLastAccessedCol);
  +        return(this.sessionLastAccessedCol);
       }
   
       // --------------------------------------------------------- Public Methods
  @@ -386,51 +387,51 @@
        * @exception IOException if an input/output error occurred
        */
       public String[] keys() throws IOException {
  -	String keysSql =
  -	    "SELECT c.size, s."+sessionIdCol+
  -	    " FROM "+sessionTable+" s, "+
  -	    "(SELECT COUNT("+sessionIdCol+
  -	    ") AS size FROM "+sessionTable+") c";
  -	Connection _conn = getConnection();
  -	ResultSet rst = null;
  -	String keys[] = null;
  -	int i;
  -
  -	if(_conn == null)
  -	    return(new String[0]);
  -
  -	try {
  -	    if(preparedKeysSql == null)
  -		preparedKeysSql = _conn.prepareStatement(keysSql);
  -
  -	    rst = preparedKeysSql.executeQuery();
  -	    if (rst != null && rst.next()) {
  -		keys = new String[rst.getInt(1)];
  -		keys[0] = rst.getString(2);
  -		i=1;
  -
  -		while(rst.next())
  -		    keys[i++] = rst.getString(2);
  -	    } else {
  -		keys = new String[0];
  -	    }
  -	} catch(SQLException e) {
  -	    log(sm.getString(getStoreName()+".SQLException", e));
  -	} finally {
  -	    try {
  -		if(rst != null)
  -		    rst.close();
  -	    } catch(SQLException e) {
  -		;
  -	    }
  -
  -	    release(_conn);
  -	    _conn = null;
  -	}	
  +        String keysSql =
  +            "SELECT c.size, s."+sessionIdCol+
  +            " FROM "+sessionTable+" s, "+
  +            "(SELECT COUNT("+sessionIdCol+
  +            ") AS size FROM "+sessionTable+") c";
  +        Connection _conn = getConnection();
  +        ResultSet rst = null;
  +        String keys[] = null;
  +        int i;
   
  -	return(keys);
  -    }
  +        if(_conn == null)
  +            return(new String[0]);
  +
  +        try {
  +            if(preparedKeysSql == null)
  +                preparedKeysSql = _conn.prepareStatement(keysSql);
   
  +            rst = preparedKeysSql.executeQuery();
  +            if (rst != null && rst.next()) {
  +                keys = new String[rst.getInt(1)];
  +                keys[0] = rst.getString(2);
  +                i=1;
  +
  +                while(rst.next())
  +                    keys[i++] = rst.getString(2);
  +            } else {
  +                keys = new String[0];
  +            }
  +        } catch(SQLException e) {
  +            log(sm.getString(getStoreName()+".SQLException", e));
  +        } finally {
  +            try {
  +                if(rst != null)
  +                    rst.close();
  +            } catch(SQLException e) {
  +                ;
  +            }
  +            
  +            release(_conn);
  +            _conn = null;
  +        }	
  +        
  +        return(keys);
  +    }
  +    
       /**
        * Return an integer containing a count of all Sessions
        * currently saved in this Store.  If there are no Sessions,
  @@ -439,39 +440,39 @@
        * @exception IOException if an input/output error occurred
        */
       public int getSize() throws IOException {
  -	int size = 0;
  -	String sizeSql = "SELECT COUNT("+sessionIdCol+
  -	    ") FROM ".concat(sessionTable);
  -	Connection _conn = getConnection();
  -	ResultSet rst = null;
  -
  -	if(_conn == null)
  -	    return(size);
  -
  -	try {
  -	    if(preparedSizeSql == null)
  -		preparedSizeSql = _conn.prepareStatement(sizeSql);
  -
  -	    rst = preparedSizeSql.executeQuery();
  -	    if (rst.next())
  -		size = rst.getInt(1);
  -	} catch(SQLException e) {
  -	    log(sm.getString(getStoreName()+".SQLException", e));
  -	} finally {
  -	    try {
  -		if(rst != null)
  -		    rst.close();
  -	    } catch(SQLException e) {
  -		;
  -	    }
  -
  -	    release(_conn);
  -	    _conn = null;
  -	}
  -
  -	return(size);
  +        int size = 0;
  +        String sizeSql = "SELECT COUNT("+sessionIdCol+
  +            ") FROM ".concat(sessionTable);
  +        Connection _conn = getConnection();
  +        ResultSet rst = null;
  +        
  +        if(_conn == null)
  +            return(size);
  +        
  +        try {
  +            if(preparedSizeSql == null)
  +                preparedSizeSql = _conn.prepareStatement(sizeSql);
  +            
  +            rst = preparedSizeSql.executeQuery();
  +            if (rst.next())
  +                size = rst.getInt(1);
  +        } catch(SQLException e) {
  +            log(sm.getString(getStoreName()+".SQLException", e));
  +        } finally {
  +            try {
  +                if(rst != null)
  +                    rst.close();
  +            } catch(SQLException e) {
  +                ;
  +            }
  +            
  +            release(_conn);
  +            _conn = null;
  +        }
  +        
  +        return(size);
       }
  -
  +    
       /**
        * Load the Session associated with the id <code>id</code>.
        * If no such session is found <code>null</code> is returned.
  @@ -482,78 +483,78 @@
        * @exception IOException if an input/output error occurred
        */
       public Session load(String id)
  -	throws ClassNotFoundException, IOException {
  -	ResultSet rst = null;
  -	Connection _conn = getConnection();
  -	StandardSession _session = null;
  -	Loader loader = null;
  -	ClassLoader classLoader = null;
  -	ObjectInputStream ois = null;
  -	BufferedInputStream bis = null;
  -	Container container = manager.getContainer();
  -	String loadSql = "SELECT "+sessionIdCol+
  -	    ", "+sessionDataCol+" FROM "+sessionTable+
  -	    " WHERE "+sessionIdCol+" = ?";
  -
  -	if(_conn == null)
  -	    return(null);
  -
  -	try {
  -	    if(preparedLoadSql == null)
  -		preparedLoadSql = _conn.prepareStatement(loadSql);
  -
  -	    preparedLoadSql.setString(1, id);
  -	    rst = preparedLoadSql.executeQuery();
  -	    if (rst.next()) {
  -		bis = new BufferedInputStream(rst.getBinaryStream(2));
  -
  -		if (container != null)
  -		    loader = container.getLoader();
  -
  -		if (loader != null)
  -		    classLoader = loader.getClassLoader();
  -
  -		if (classLoader != null)
  -		    ois = new CustomObjectInputStream(bis,
  -						      classLoader);
  -		else
  -		    ois = new ObjectInputStream(bis);
  -	    } else if (debug > 0) {
  -		    log(getStoreName()+": No persisted data object found");
  -	    }
  -	} catch(SQLException e) {
  -	    log(sm.getString(getStoreName()+".SQLException", e));
  -	} finally {
  -	    try {
  -		if(rst != null)
  -		    rst.close();
  -	    } catch(SQLException e) {
  -		;
  -	    }
  -
  -	    release(_conn);
  -	    _conn = null;
  -	}
  -
  -	try {
  -	    _session = (StandardSession) manager.createSession();
  +        throws ClassNotFoundException, IOException {
  +        ResultSet rst = null;
  +        Connection _conn = getConnection();
  +        StandardSession _session = null;
  +        Loader loader = null;
  +        ClassLoader classLoader = null;
  +        ObjectInputStream ois = null;
  +        BufferedInputStream bis = null;
  +        Container container = manager.getContainer();
  +        String loadSql = "SELECT "+sessionIdCol+
  +            ", "+sessionDataCol+" FROM "+sessionTable+
  +            " WHERE "+sessionIdCol+" = ?";
  +        
  +        if(_conn == null)
  +            return(null);
  +        
  +        try {
  +            if(preparedLoadSql == null)
  +                preparedLoadSql = _conn.prepareStatement(loadSql);
  +            
  +            preparedLoadSql.setString(1, id);
  +            rst = preparedLoadSql.executeQuery();
  +            if (rst.next()) {
  +                bis = new BufferedInputStream(rst.getBinaryStream(2));
  +                
  +                if (container != null)
  +                    loader = container.getLoader();
  +                
  +                if (loader != null)
  +                    classLoader = loader.getClassLoader();
  +                
  +                if (classLoader != null)
  +                    ois = new CustomObjectInputStream(bis,
  +                                                      classLoader);
  +                else
  +                    ois = new ObjectInputStream(bis);
  +            } else if (debug > 0) {
  +                log(getStoreName()+": No persisted data object found");
  +            }
  +        } catch(SQLException e) {
  +            log(sm.getString(getStoreName()+".SQLException", e));
  +        } finally {
  +            try {
  +                if(rst != null)
  +                    rst.close();
  +            } catch(SQLException e) {
  +                ;
  +            }
  +            
  +            release(_conn);
  +            _conn = null;
  +        }
  +        
  +        try {
  +            _session = (StandardSession) manager.createSession();
               _session.readObjectData(ois);
  -	    _session.setManager(manager);
  -	} finally {
  -	    if (ois != null) {
  -		try {
  -		    ois.close();
  -		    bis = null;
  -		} catch (IOException e) {
  -		    ;
  -		}
  -	    }
  -	}
  -
  -	if (debug > 0)
  -	    log(sm.getString(getStoreName()+".loading",
  -			     id, sessionTable));
  -	return(_session);
  +            _session.setManager(manager);
  +        } finally {
  +            if (ois != null) {
  +                try {
  +                    ois.close();
  +                    bis = null;
  +                } catch (IOException e) {
  +                    ;
  +                }
  +            }
  +        }
  +        
  +        if (debug > 0)
  +            log(sm.getString(getStoreName()+".loading",
  +                             id, sessionTable));
  +        return(_session);
       }
   
       /**
  @@ -566,55 +567,55 @@
        * @exception IOException if an input/output error occurs
        */
       public void remove(String id) throws IOException {
  -	Connection _conn = getConnection();
  -	String removeSql = "DELETE FROM "+sessionTable+" WHERE "+
  -	    sessionIdCol+" = ?";
  -
  -	if(_conn == null)
  -	    return;
  -
  -	try {
  -	    if(preparedRemoveSql == null)
  -		preparedRemoveSql = _conn.prepareStatement(removeSql);
  -
  -	    preparedRemoveSql.setString(1, id);
  -	    preparedRemoveSql.execute();
  -	} catch(SQLException e) {
  -	    log(sm.getString(getStoreName()+".SQLException", e));
  -	} finally {
  -	    release(_conn);
  -	    _conn = null;
  -	}
  -
  -	if (debug > 0)
  -	    log(sm.getString(getStoreName()+".removing", id, sessionTable));
  +        Connection _conn = getConnection();
  +        String removeSql = "DELETE FROM "+sessionTable+" WHERE "+
  +            sessionIdCol+" = ?";
  +        
  +        if(_conn == null)
  +            return;
  +        
  +        try {
  +            if(preparedRemoveSql == null)
  +                preparedRemoveSql = _conn.prepareStatement(removeSql);
  +            
  +            preparedRemoveSql.setString(1, id);
  +            preparedRemoveSql.execute();
  +        } catch(SQLException e) {
  +            log(sm.getString(getStoreName()+".SQLException", e));
  +        } finally {
  +            release(_conn);
  +            _conn = null;
  +        }
  +        
  +        if (debug > 0)
  +            log(sm.getString(getStoreName()+".removing", id, sessionTable));
       }
  -
  +    
       /**
        * Remove all of the Sessions in this Store.
        *
        * @exception IOException if an input/output error occurs
        */
       public void clear() throws IOException {
  -	Connection _conn = getConnection();
  -	String clearSql = "DELETE FROM ".concat(sessionTable);
  -
  -	if(_conn == null)
  -	    return;
  -
  -	try {
  -	    if(preparedClearSql == null)
  -		preparedClearSql = _conn.prepareStatement(clearSql);
  -
  -	    preparedClearSql.execute();
  -	} catch(SQLException e) {
  -	    log(sm.getString(getStoreName()+".SQLException", e));
  -	} finally {
  -	    release(_conn);
  -	    _conn = null;
  -	}
  +        Connection _conn = getConnection();
  +        String clearSql = "DELETE FROM ".concat(sessionTable);
  +        
  +        if(_conn == null)
  +            return;
  +        
  +        try {
  +            if(preparedClearSql == null)
  +                preparedClearSql = _conn.prepareStatement(clearSql);
  +            
  +            preparedClearSql.execute();
  +        } catch(SQLException e) {
  +            log(sm.getString(getStoreName()+".SQLException", e));
  +        } finally {
  +            release(_conn);
  +            _conn = null;
  +        }
       }
  -
  +    
       /**
        * Save a session to the Store.
        *
  @@ -622,69 +623,69 @@
        * @exception IOException if an input/output error occurs
        */
       public void save(Session session) throws IOException {
  -	String saveSql = "INSERT INTO "+sessionTable+" ("+
  -	    sessionIdCol+", "+
  -	    sessionDataCol+", "+
  -	    sessionValidCol+", "+
  -	    sessionMaxInactiveCol+", "+
  -	    sessionLastAccessedCol+") VALUES (?, ?, ?, ?, ?)";
  -	Connection _conn = getConnection();
  -	ObjectOutputStream oos = null;
  -	ByteArrayOutputStream bos = null;
  -	ByteArrayInputStream bis = null;
  -	InputStream in = null;
  -
  -	if(_conn == null)
  -	    return;
  -
  -	// If sessions already exist in DB, remove and insert again.
  -	// TODO:
  -	// * Check if ID exists in database and if so use UPDATE.
  -	remove(session.getId());
  -
  -	try {
  -	    bos = new ByteArrayOutputStream();
  -	    oos = new ObjectOutputStream(new BufferedOutputStream(bos));
  -
  -	    ((StandardSession)session).writeObjectData(oos);
  -	    oos.close();
  -
  -	    byte[] obs = bos.toByteArray();
  -	    int size = obs.length;
  -	    bis = new ByteArrayInputStream(obs, 0, size);
  -	    in = new BufferedInputStream(bis, size);
  -	    
  -	    if(preparedSaveSql == null)
  -		preparedSaveSql = _conn.prepareStatement(saveSql);
  -
  -	    preparedSaveSql.setString(1, session.getId());
  -	    preparedSaveSql.setBinaryStream(2, in, size);
  -	    preparedSaveSql.setString(3, session.isValid()?"1":"0");
  -	    preparedSaveSql.setInt(4, session.getMaxInactiveInterval());
  -	    preparedSaveSql.setLong(5, session.getLastAccessedTime());
  -	    preparedSaveSql.execute();
  -	} catch(SQLException e) {
  -	    log(sm.getString(getStoreName()+".SQLException", e));
  -	} catch (IOException e) {
  -	    ;
  -	} finally {
  -	    if(bis != null)
  -		bis.close();
  -
  -	    if(in != null)
  -		in.close();
  -
  -	    bis = null;
  -	    bos = null;
  -	    oos = null;
  -	    in = null;
  -
  -	    release(_conn);
  -	    _conn = null;
  -	}
  -	if (debug > 0)
  -	    log(sm.getString(getStoreName()+".saving",
  -			     session.getId(), sessionTable));
  +        String saveSql = "INSERT INTO "+sessionTable+" ("+
  +            sessionIdCol+", "+
  +            sessionDataCol+", "+
  +            sessionValidCol+", "+
  +            sessionMaxInactiveCol+", "+
  +            sessionLastAccessedCol+") VALUES (?, ?, ?, ?, ?)";
  +        Connection _conn = getConnection();
  +        ObjectOutputStream oos = null;
  +        ByteArrayOutputStream bos = null;
  +        ByteArrayInputStream bis = null;
  +        InputStream in = null;
  +        
  +        if(_conn == null)
  +            return;
  +        
  +        // If sessions already exist in DB, remove and insert again.
  +        // TODO:
  +        // * Check if ID exists in database and if so use UPDATE.
  +        remove(session.getId());
  +        
  +        try {
  +            bos = new ByteArrayOutputStream();
  +            oos = new ObjectOutputStream(new BufferedOutputStream(bos));
  +            
  +            ((StandardSession)session).writeObjectData(oos);
  +            oos.close();
  +            
  +            byte[] obs = bos.toByteArray();
  +            int size = obs.length;
  +            bis = new ByteArrayInputStream(obs, 0, size);
  +            in = new BufferedInputStream(bis, size);
  +            
  +            if(preparedSaveSql == null)
  +                preparedSaveSql = _conn.prepareStatement(saveSql);
  +            
  +            preparedSaveSql.setString(1, session.getId());
  +            preparedSaveSql.setBinaryStream(2, in, size);
  +            preparedSaveSql.setString(3, session.isValid()?"1":"0");
  +            preparedSaveSql.setInt(4, session.getMaxInactiveInterval());
  +            preparedSaveSql.setLong(5, session.getLastAccessedTime());
  +            preparedSaveSql.execute();
  +        } catch(SQLException e) {
  +            log(sm.getString(getStoreName()+".SQLException", e));
  +        } catch (IOException e) {
  +            ;
  +        } finally {
  +            if(bis != null)
  +                bis.close();
  +            
  +            if(in != null)
  +                in.close();
  +            
  +            bis = null;
  +            bos = null;
  +            oos = null;
  +            in = null;
  +            
  +            release(_conn);
  +            _conn = null;
  +        }
  +        if (debug > 0)
  +            log(sm.getString(getStoreName()+".saving",
  +                             session.getId(), sessionTable));
       }
   
       // --------------------------------------------------------- Protected Methods
  @@ -701,23 +702,23 @@
               if(conn == null || conn.isClosed()) {
                   Class.forName(driverName);
                   log(sm.getString(getStoreName()+".checkConnectionDBClosed"));
  -		conn = DriverManager.getConnection(connString);
  -		conn.setAutoCommit(true);
  -
  +                conn = DriverManager.getConnection(connString);
  +                conn.setAutoCommit(true);
  +                
                   if(conn == null || conn.isClosed())
  -                  log(sm.getString(getStoreName()+".checkConnectionDBReOpenFail"));
  -	    }
  +                    log(sm.getString(getStoreName()+".checkConnectionDBReOpenFail"));
  +            }
           } catch (SQLException ex){
               log(sm.getString(getStoreName()+".checkConnectionSQLException",
  -			     ex.toString()));
  +                             ex.toString()));
           } catch (ClassNotFoundException ex) {
               log(sm.getString(getStoreName()+".checkConnectionClassNotFoundException",
  -			     ex.toString()));
  +                             ex.toString()));
           }
  -
  -	return conn;
  +        
  +        return conn;
       }
  -
  +    
       /**
        * Release the connection, not needed here since the
        * connection is not associated with a connection pool.
  @@ -731,9 +732,11 @@
       /**
        * Called once when this Store is first started.
        */
  -    public void storeStart() {
  -	// Open connection to the database
  -	this.conn = getConnection();
  +    public void start() throws LifecycleException {
  +        super.start();
  +
  +        // Open connection to the database
  +        this.conn = getConnection();
       }
   
       /**
  @@ -741,64 +744,66 @@
        * Called once when this Store is stoping.
        *
        */
  -    protected void storeStop() {
  -	// Close and release everything associated with our db.
  -	if(conn != null) {
  -	    try {
  -		conn.commit();
  -	    } catch (SQLException e) {
  -		;
  -	    }
  -
  -	    try {
  -		preparedSizeSql.close();
  -	    } catch (SQLException e) {
  -		;
  -	    }
  -
  -	    try {
  -		preparedKeysSql.close();
  -	    } catch (SQLException e) {
  -		;
  -	    }
  -
  -	    try {
  -		preparedSaveSql.close();
  -	    } catch (SQLException e) {
  -		;
  -	    }
  -
  -	    try {
  -		preparedClearSql.close();
  -	    } catch (SQLException e) {
  -		;
  -	    }
  -
  -	    try {
  -		preparedRemoveSql.close();
  -	    } catch (SQLException e) {
  -		;
  -	    }
  -
  -	    try {
  -		preparedLoadSql.close();
  -	    } catch (SQLException e) {
  -		;
  -	    }
  -
  -	    try {
  -		conn.close();
  -	    } catch (SQLException e) {
  -		;
  -	    }
  -
  -	    this.preparedSizeSql = null;
  -	    this.preparedKeysSql = null;
  -	    this.preparedSaveSql = null;
  -	    this.preparedClearSql = null;
  -	    this.preparedRemoveSql = null;
  -	    this.preparedLoadSql = null;
  -	    this.conn = null;
  -	}
  +    public void stop() throws LifecycleException {
  +        super.stop();
  +
  +        // Close and release everything associated with our db.
  +        if(conn != null) {
  +            try {
  +                conn.commit();
  +            } catch (SQLException e) {
  +                ;
  +            }
  +            
  +            try {
  +                preparedSizeSql.close();
  +            } catch (SQLException e) {
  +                ;
  +            }
  +            
  +            try {
  +                preparedKeysSql.close();
  +            } catch (SQLException e) {
  +                ;
  +            }
  +            
  +            try {
  +                preparedSaveSql.close();
  +            } catch (SQLException e) {
  +                ;
  +            }
  +            
  +            try {
  +                preparedClearSql.close();
  +            } catch (SQLException e) {
  +                ;
  +            }
  +            
  +            try {
  +                preparedRemoveSql.close();
  +            } catch (SQLException e) {
  +                ;
  +            }
  +            
  +            try {
  +                preparedLoadSql.close();
  +            } catch (SQLException e) {
  +                ;
  +            }
  +            
  +            try {
  +                conn.close();
  +            } catch (SQLException e) {
  +                ;
  +            }
  +            
  +            this.preparedSizeSql = null;
  +            this.preparedKeysSql = null;
  +            this.preparedSaveSql = null;
  +            this.preparedClearSql = null;
  +            this.preparedRemoveSql = null;
  +            this.preparedLoadSql = null;
  +            this.conn = null;
  +        }
       }
   }
  
  
  
  1.2       +122 -147  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StoreBase.java
  
  Index: StoreBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StoreBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StoreBase.java	2001/04/26 01:36:05	1.1
  +++ StoreBase.java	2001/04/26 03:15:00	1.2
  @@ -1,8 +1,8 @@
   /*
    * StoreBase.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StoreBase.java,v 1.1 2001/04/26 01:36:05 bip Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/04/26 01:36:05 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StoreBase.java,v 1.2 2001/04/26 03:15:00 bip Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/04/26 03:15:00 $
    *
    * ====================================================================
    *
  @@ -71,7 +71,6 @@
   import org.apache.catalina.Lifecycle;
   import org.apache.catalina.LifecycleEvent;
   import org.apache.catalina.LifecycleException;
  -import org.apache.catalina.LifecycleException;
   import org.apache.catalina.LifecycleListener;
   import org.apache.catalina.Logger;
   import org.apache.catalina.Manager;
  @@ -84,7 +83,7 @@
    * support most of the functionality required by a Store.
    *
    * @author Bip Thelin
  - * @version $Revision: 1.1 $, $Date: 2001/04/26 01:36:05 $
  + * @version $Revision: 1.2 $, $Date: 2001/04/26 03:15:00 $
    */
   
   public abstract class StoreBase
  @@ -158,21 +157,21 @@
        * Return the info for this Store.
        */
       public String getInfo() {
  -	return(info);
  +        return(info);
       }
   
       /**
        * Return the thread name for this Store.
        */
       public String getThreadName() {
  -	return(threadName);
  +        return(threadName);
       }
   
       /**
        * Return the name for this Store, used for logging.
        */
       public String getStoreName() {
  -	return(storeName);
  +        return(storeName);
       }
   
       /**
  @@ -181,14 +180,14 @@
        * @param debug The new debugging detail level
        */
       public void setDebug(int debug) {
  -	this.debug = debug;
  +        this.debug = debug;
       }
   
       /**
        * Return the debugging detail level for this Store.
        */
       public int getDebug() {
  -	return(this.debug);
  +        return(this.debug);
       }
   
   
  @@ -198,18 +197,18 @@
        * @param checkInterval The new check interval
        */
       public void setCheckInterval(int checkInterval) {
  -	int oldCheckInterval = this.checkInterval;
  -	this.checkInterval = checkInterval;
  -	support.firePropertyChange("checkInterval",
  -				   new Integer(oldCheckInterval),
  -				   new Integer(this.checkInterval));
  +        int oldCheckInterval = this.checkInterval;
  +        this.checkInterval = checkInterval;
  +        support.firePropertyChange("checkInterval",
  +                                   new Integer(oldCheckInterval),
  +                                   new Integer(this.checkInterval));
       }
   
       /**
        * Return the check interval (in seconds) for this Store.
        */
       public int getCheckInterval() {
  -	return(this.checkInterval);
  +        return(this.checkInterval);
       }
   
       /**
  @@ -218,9 +217,9 @@
        * @param manager The newly associated Manager
        */
       public void setManager(Manager manager) {
  -	Manager oldManager = this.manager;
  -	this.manager = manager;
  -	support.firePropertyChange("manager", oldManager, this.manager);
  +        Manager oldManager = this.manager;
  +        this.manager = manager;
  +        support.firePropertyChange("manager", oldManager, this.manager);
       }
   
       /**
  @@ -238,7 +237,7 @@
        * @param listener The listener to add
        */
       public void addLifecycleListener(LifecycleListener listener) {
  -	lifecycle.addLifecycleListener(listener);
  +        lifecycle.addLifecycleListener(listener);
       }
   
       /**
  @@ -247,7 +246,7 @@
        * @param listener The listener to add
        */
       public void removeLifecycleListener(LifecycleListener listener) {
  -	lifecycle.removeLifecycleListener(listener);
  +        lifecycle.removeLifecycleListener(listener);
       }
   
       /**
  @@ -256,7 +255,7 @@
        * @param listener a value of type 'PropertyChangeListener'
        */
       public void addPropertyChangeListener(PropertyChangeListener listener) {
  -	support.addPropertyChangeListener(listener);
  +        support.addPropertyChangeListener(listener);
       }
   
       /**
  @@ -265,7 +264,7 @@
        * @param listener The listener to remove
        */
       public void removePropertyChangeListener(PropertyChangeListener listener) {
  -	support.removePropertyChangeListener(listener);
  +        support.removePropertyChangeListener(listener);
       }
   
       // --------------------------------------------------------- Protected Methods
  @@ -277,42 +276,42 @@
        *
        */
       protected void processExpires() {
  -	long timeNow = System.currentTimeMillis();
  -	String[] keys = null;
  -
  +        long timeNow = System.currentTimeMillis();
  +        String[] keys = null;
  +        
       	if(!started)
       	    return;
  -	
  -	try {
  -	    keys = keys();
  -	} catch (IOException e) {
  -	    log (e.toString());
  -	    e.printStackTrace();
  -	    return;
  -	}
  -	
  -	for (int i = 0; i < keys.length; i++) {
  -	    try {
  -		StandardSession session = (StandardSession) load(keys[i]);
  -		if (!session.isValid())
  -		    continue;
  -		int maxInactiveInterval = session.getMaxInactiveInterval();
  -		if (maxInactiveInterval < 0)
  -		    continue;
  -		int timeIdle = // Truncate, do not round up
  -		(int) ((timeNow - session.getLastAccessedTime()) / 1000L);
  -		if (timeIdle >= maxInactiveInterval) {
  -		    session.expire();
  -		    remove(session.getId());
  -		}
  -	    } catch (IOException e) {
  -	    	log (e.toString());
  -	    	e.printStackTrace();
  -	    } catch (ClassNotFoundException e) {
  -	    	log (e.toString());
  -	    	e.printStackTrace();
  -	    }
  -	}
  +        
  +        try {
  +            keys = keys();
  +        } catch (IOException e) {
  +            log (e.toString());
  +            e.printStackTrace();
  +            return;
  +        }
  +        
  +        for (int i = 0; i < keys.length; i++) {
  +            try {
  +                StandardSession session = (StandardSession) load(keys[i]);
  +                if (!session.isValid())
  +                    continue;
  +                int maxInactiveInterval = session.getMaxInactiveInterval();
  +                if (maxInactiveInterval < 0)
  +                    continue;
  +                int timeIdle = // Truncate, do not round up
  +                    (int) ((timeNow - session.getLastAccessedTime()) / 1000L);
  +                if (timeIdle >= maxInactiveInterval) {
  +                    session.expire();
  +                    remove(session.getId());
  +                }
  +            } catch (IOException e) {
  +                log (e.toString());
  +                e.printStackTrace();
  +            } catch (ClassNotFoundException e) {
  +                log (e.toString());
  +                e.printStackTrace();
  +            }
  +        }
       }
   
       /**
  @@ -321,40 +320,22 @@
        * @param message Message to be logged
        */
       protected void log(String message) {
  -	Logger logger = null;
  -	Container container = manager.getContainer();
  -
  -	if (container != null)
  -	    logger = container.getLogger();
  -
  -	if (logger != null) {
  -	    logger.log(getStoreName()+"[" + container.getName() + "]: "
  -		       + message);
  -	} else {
  -	    String containerName = null;
  -	    if (container != null)
  -		containerName = container.getName();
  -	    System.out.println(getStoreName()+"[" + containerName
  -			       + "]: " + message);
  -	}
  -    }
  -
  -    /**
  -     * Called from <b>start()</b> and used for concrete Store
  -     * implementations that need to add their own <b>start()</b> code.
  -     *
  -     */
  -    protected void storeStart() {
  -	;
  -    }
  -
  -    /**
  -     * Called from <b>stop()</b> and used for concrete Store
  -     * implementations that need to add their own <b>stop()</b> code.
  -     *
  -     */
  -    protected void storeStop() {
  -	;
  +        Logger logger = null;
  +        Container container = manager.getContainer();
  +        
  +        if (container != null)
  +            logger = container.getLogger();
  +        
  +        if (logger != null) {
  +            logger.log(getStoreName()+"[" + container.getName() + "]: "
  +                       + message);
  +        } else {
  +            String containerName = null;
  +            if (container != null)
  +                containerName = container.getName();
  +            System.out.println(getStoreName()+"[" + containerName
  +                               + "]: " + message);
  +        }
       }
   
       // --------------------------------------------------------- Thread Methods
  @@ -363,11 +344,11 @@
        * The background thread that checks for session timeouts and shutdown.
        */
       public void run() {
  -	// Loop until the termination semaphore is set
  -	while (!threadDone) {
  -	    threadSleep();
  -	    processExpires();
  -	}
  +        // Loop until the termination semaphore is set
  +        while (!threadDone) {
  +            threadSleep();
  +            processExpires();
  +        }
       }
   
       /**
  @@ -381,18 +362,15 @@
        *  that prevents this component from being used
        */
       public void start() throws LifecycleException {
  -	// Validate and update our current component state
  -	if (started)
  -	    throw new LifecycleException
  -		(sm.getString(getStoreName()+".alreadyStarted"));
  -	lifecycle.fireLifecycleEvent(START_EVENT, null);
  -	started = true;
  -
  -	// Start the background reaper thread
  -	threadStart();
  -
  -	// Start the Store
  -	storeStart();
  +        // Validate and update our current component state
  +        if (started)
  +            throw new LifecycleException
  +                (sm.getString(getStoreName()+".alreadyStarted"));
  +        lifecycle.fireLifecycleEvent(START_EVENT, null);
  +        started = true;
  +        
  +        // Start the background reaper thread
  +        threadStart();
       }
   
       /**
  @@ -405,62 +383,59 @@
        *  that needs to be reported
        */
       public void stop() throws LifecycleException {
  -	// Validate and update our current component state
  -	if (!started)
  -	    throw new LifecycleException
  -		(sm.getString(getStoreName()+".notStarted"));
  -	lifecycle.fireLifecycleEvent(STOP_EVENT, null);
  -	started = false;
  -
  -	// Stop the background reaper thread
  -	threadStop();
  -
  -	// Stop the Store.
  -	storeStop();
  +        // Validate and update our current component state
  +        if (!started)
  +            throw new LifecycleException
  +                (sm.getString(getStoreName()+".notStarted"));
  +        lifecycle.fireLifecycleEvent(STOP_EVENT, null);
  +        started = false;
  +        
  +        // Stop the background reaper thread
  +        threadStop();
       }
  -
  +    
       /**
        * Start the background thread that will periodically check for
        * session timeouts.
        */
       protected void threadStart() {
  -	if (thread != null)
  -	    return;
  -
  -	threadDone = false;
  -	thread = new Thread(this, getThreadName());
  -	thread.setDaemon(true);
  -	thread.start();
  +        if (thread != null)
  +            return;
  +        
  +        threadDone = false;
  +        thread = new Thread(this, getThreadName());
  +        thread.setDaemon(true);
  +        thread.start();
       }
  -
  +    
       /**
        * Sleep for the duration specified by the <code>checkInterval</code>
        * property.
        */
       protected void threadSleep() {
  -	try {
  -	    Thread.sleep(checkInterval * 1000L);
  -	} catch (InterruptedException e) {
  -	    ;
  -	}
  +        try {
  +            Thread.sleep(checkInterval * 1000L);
  +        } catch (InterruptedException e) {
  +            ;
  +        }
       }
  -
  +    
       /**
        * Stop the background thread that is periodically checking for
        * session timeouts.
        */
       protected void threadStop() {
  -	if (thread == null)
  -	    return;
  -
  -	threadDone = true;
  -	thread.interrupt();
  -	try {
  -	    thread.join();
  -	} catch (InterruptedException e) {
  -	    ;
  -	}
  -
  -	thread = null;
  +        if (thread == null)
  +            return;
  +        
  +        threadDone = true;
  +        thread.interrupt();
  +        try {
  +            thread.join();
  +        } catch (InterruptedException e) {
  +            ;
  +        }
  +        
  +        thread = null;
       }
   }