Merge remote-tracking branch 'origin/master' into jetty-8

This commit is contained in:
Jan Bartel 2012-03-02 10:39:17 +11:00
commit 959a4a2743
4 changed files with 94 additions and 48 deletions

View File

@ -685,6 +685,16 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
@Override
public void close() throws IOException
{
try
{
if (_key!=null)
_key.cancel();
}
catch (Throwable e)
{
LOG.ignore(e);
}
try
{
super.close();

View File

@ -71,6 +71,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
protected long _lastScavengeTime;
protected long _scavengeIntervalMs = 1000L * 60 * 10; //10mins
protected String _blobType; //if not set, is deduced from the type of the database at runtime
protected String _longType; //if not set, is deduced from the type of the database at runtime
protected String _createSessionIdTable;
protected String _createSessionTable;
@ -82,6 +83,13 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
protected String _deleteId;
protected String _queryId;
protected String _insertSession;
protected String _deleteSession;
protected String _selectSession;
protected String _updateSession;
protected String _updateSessionNode;
protected String _updateSessionAccessTime;
protected DatabaseAdaptor _dbAdaptor;
@ -146,6 +154,17 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
return "blob";
}
public String getLongType ()
{
if (_longType != null)
return _longType;
if (_dbName.startsWith("oracle"))
return "number(20)";
return "bigint";
}
public InputStream getBlobInputStream (ResultSet result, String columnName)
throws SQLException
{
@ -158,6 +177,18 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
Blob blob = result.getBlob(columnName);
return blob.getBinaryStream();
}
/**
* rowId is a reserved word for Oracle, so change the name of this column
* @return
*/
public String getRowIdColumnName ()
{
if (_dbName != null && _dbName.startsWith("oracle"))
return "srowId";
return "rowId";
}
}
@ -239,6 +270,18 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
return _blobType;
}
public String getLongType()
{
return _longType;
}
public void setLongType(String longType)
{
this._longType = longType;
}
public void setScavengeInterval (long sec)
{
if (sec<=0)
@ -528,7 +571,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
connection.setAutoCommit(true);
DatabaseMetaData metaData = connection.getMetaData();
_dbAdaptor = new DatabaseAdaptor(metaData);
_sessionTableRowId = (_dbAdaptor.getDBName() != null && _dbAdaptor.getDBName().contains("oracle") ? "srowId":_sessionTableRowId);
_sessionTableRowId = _dbAdaptor.getRowIdColumnName();
//checking for table existence is case-sensitive, but table creation is not
String tableName = _dbAdaptor.convertIdentifier(_sessionIdTable);
@ -546,10 +589,11 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
{
//table does not exist, so create it
String blobType = _dbAdaptor.getBlobType();
String longType = _dbAdaptor.getLongType();
_createSessionTable = "create table "+_sessionTable+" ("+_sessionTableRowId+" varchar(120), sessionId varchar(120), "+
" contextPath varchar(60), virtualHost varchar(60), lastNode varchar(60), accessTime bigint, "+
" lastAccessTime bigint, createTime bigint, cookieTime bigint, "+
" lastSavedTime bigint, expiryTime bigint, map "+blobType+", primary key("+_sessionTableRowId+"))";
" contextPath varchar(60), virtualHost varchar(60), lastNode varchar(60), accessTime "+longType+", "+
" lastAccessTime "+longType+", createTime "+longType+", cookieTime "+longType+", "+
" lastSavedTime "+longType+", expiryTime "+longType+", map "+blobType+", primary key("+_sessionTableRowId+"))";
connection.createStatement().executeUpdate(_createSessionTable);
}
@ -576,6 +620,28 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
if (!index2Exists)
statement.executeUpdate("create index "+index2+" on "+_sessionTable+" (sessionId, contextPath)");
}
//set up some strings representing the statements for session manipulation
_insertSession = "insert into "+_sessionTable+
" ("+_sessionTableRowId+", sessionId, contextPath, virtualHost, lastNode, accessTime, lastAccessTime, createTime, cookieTime, lastSavedTime, expiryTime, map) "+
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
_deleteSession = "delete from "+_sessionTable+
" where "+_sessionTableRowId+" = ?";
_selectSession = "select * from "+_sessionTable+
" where sessionId = ? and contextPath = ? and virtualHost = ?";
_updateSession = "update "+_sessionTable+
" set lastNode = ?, accessTime = ?, lastAccessTime = ?, lastSavedTime = ?, expiryTime = ?, map = ? where "+_sessionTableRowId+" = ?";
_updateSessionNode = "update "+_sessionTable+
" set lastNode = ? where "+_sessionTableRowId+" = ?";
_updateSessionAccessTime = "update "+_sessionTable+
" set lastNode = ?, accessTime = ?, lastAccessTime = ?, lastSavedTime = ?, expiryTime = ? where "+_sessionTableRowId+" = ?";
}
finally
{

View File

@ -70,15 +70,8 @@ public class JDBCSessionManager extends AbstractSessionManager
{
private static final Logger LOG = Log.getLogger(JDBCSessionManager.class);
protected String __insertSession;
protected String __deleteSession;
protected String __selectSession;
protected String __updateSession;
protected String __updateSessionNode;
protected String __updateSessionAccessTime;
protected String __sessionTableRowId;
private ConcurrentHashMap<String, AbstractSession> _sessions;
protected JDBCSessionIdManager _jdbcSessionIdMgr = null;
protected long _saveIntervalSec = 60; //only persist changes to session access times every 60 secs
/**
@ -605,8 +598,8 @@ public class JDBCSessionManager extends AbstractSessionManager
if (_sessionIdManager==null)
throw new IllegalStateException("No session id manager defined");
prepareTables();
_jdbcSessionIdMgr = (JDBCSessionIdManager)_sessionIdManager;
_sessions = new ConcurrentHashMap<String, AbstractSession>();
super.doStart();
}
@ -818,30 +811,6 @@ public class JDBCSessionManager extends AbstractSessionManager
}
protected void prepareTables ()
{
__sessionTableRowId = ((JDBCSessionIdManager)_sessionIdManager)._sessionTableRowId;
__insertSession = "insert into "+((JDBCSessionIdManager)_sessionIdManager)._sessionTable+
" ("+__sessionTableRowId+", sessionId, contextPath, virtualHost, lastNode, accessTime, lastAccessTime, createTime, cookieTime, lastSavedTime, expiryTime, map) "+
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
__deleteSession = "delete from "+((JDBCSessionIdManager)_sessionIdManager)._sessionTable+
" where "+__sessionTableRowId+" = ?";
__selectSession = "select * from "+((JDBCSessionIdManager)_sessionIdManager)._sessionTable+
" where sessionId = ? and contextPath = ? and virtualHost = ?";
__updateSession = "update "+((JDBCSessionIdManager)_sessionIdManager)._sessionTable+
" set lastNode = ?, accessTime = ?, lastAccessTime = ?, lastSavedTime = ?, expiryTime = ?, map = ? where "+__sessionTableRowId+" = ?";
__updateSessionNode = "update "+((JDBCSessionIdManager)_sessionIdManager)._sessionTable+
" set lastNode = ? where "+__sessionTableRowId+" = ?";
__updateSessionAccessTime = "update "+((JDBCSessionIdManager)_sessionIdManager)._sessionTable+
" set lastNode = ?, accessTime = ?, lastAccessTime = ?, lastSavedTime = ?, expiryTime = ? where "+__sessionTableRowId+" = ?";
}
/**
* Load a session from the database
* @param id
@ -864,7 +833,7 @@ public class JDBCSessionManager extends AbstractSessionManager
try
{
connection = getConnection();
statement = connection.prepareStatement(__selectSession);
statement = connection.prepareStatement(_jdbcSessionIdMgr._selectSession);
statement.setString(1, id);
statement.setString(2, canonicalContextPath);
statement.setString(3, vhost);
@ -872,7 +841,7 @@ public class JDBCSessionManager extends AbstractSessionManager
if (result.next())
{
data = new SessionData(id);
data.setRowId(result.getString(__sessionTableRowId));
data.setRowId(result.getString(_jdbcSessionIdMgr._sessionTableRowId));
data.setCookieSet(result.getLong("cookieTime"));
data.setLastAccessed(result.getLong("lastAccessTime"));
data.setAccessed (result.getLong("accessTime"));
@ -941,7 +910,7 @@ public class JDBCSessionManager extends AbstractSessionManager
long now = System.currentTimeMillis();
connection.setAutoCommit(true);
statement = connection.prepareStatement(__insertSession);
statement = connection.prepareStatement(_jdbcSessionIdMgr._insertSession);
statement.setString(1, rowId); //rowId
statement.setString(2, data.getId()); //session id
statement.setString(3, data.getCanonicalContext()); //context path
@ -996,7 +965,7 @@ public class JDBCSessionManager extends AbstractSessionManager
{
long now = System.currentTimeMillis();
connection.setAutoCommit(true);
statement = connection.prepareStatement(__updateSession);
statement = connection.prepareStatement(_jdbcSessionIdMgr._updateSession);
statement.setString(1, getSessionIdManager().getWorkerName());//my node id
statement.setLong(2, data.getAccessed());//accessTime
statement.setLong(3, data.getLastAccessed()); //lastAccessTime
@ -1040,7 +1009,7 @@ public class JDBCSessionManager extends AbstractSessionManager
try
{
connection.setAutoCommit(true);
statement = connection.prepareStatement(__updateSessionNode);
statement = connection.prepareStatement(_jdbcSessionIdMgr._updateSessionNode);
statement.setString(1, nodeId);
statement.setString(2, data.getRowId());
statement.executeUpdate();
@ -1070,7 +1039,7 @@ public class JDBCSessionManager extends AbstractSessionManager
{
long now = System.currentTimeMillis();
connection.setAutoCommit(true);
statement = connection.prepareStatement(__updateSessionAccessTime);
statement = connection.prepareStatement(_jdbcSessionIdMgr._updateSessionAccessTime);
statement.setString(1, getSessionIdManager().getWorkerName());
statement.setLong(2, data.getAccessed());
statement.setLong(3, data.getLastAccessed());
@ -1108,7 +1077,7 @@ public class JDBCSessionManager extends AbstractSessionManager
try
{
connection.setAutoCommit(true);
statement = connection.prepareStatement(__deleteSession);
statement = connection.prepareStatement(_jdbcSessionIdMgr._deleteSession);
statement.setString(1, data.getRowId());
statement.executeUpdate();
if (LOG.isDebugEnabled())

View File

@ -131,10 +131,11 @@ public abstract class AbstractClientCrossContextSessionTest
{
HttpSession session = request.getSession(false);
if (session == null)
{
session = request.getSession(true);
sessionId = session.getId();
}
sessionId = session.getId();
// Add something to the session
session.setAttribute("B", "B");