408167 Complex object as session attribute not necessarily persisted.

This commit is contained in:
Jan Bartel 2014-01-20 10:40:05 +11:00
parent f735fe834b
commit 5f7a34e590
2 changed files with 28 additions and 13 deletions

View File

@ -95,49 +95,49 @@ public class JDBCSessionManager extends AbstractSessionManager
/**
* If dirty, session needs to be (re)persisted
*/
private boolean _dirty=false;
protected boolean _dirty=false;
/**
* Time in msec since the epoch that a session cookie was set for this session
*/
private long _cookieSet;
protected long _cookieSet;
/**
* Time in msec since the epoch that the session will expire
*/
private long _expiryTime;
protected long _expiryTime;
/**
* Time in msec since the epoch that the session was last persisted
*/
private long _lastSaved;
protected long _lastSaved;
/**
* Unique identifier of the last node to host the session
*/
private String _lastNode;
protected String _lastNode;
/**
* Virtual host for context (used to help distinguish 2 sessions with same id on different contexts)
*/
private String _virtualHost;
protected String _virtualHost;
/**
* Unique row in db for session
*/
private String _rowId;
protected String _rowId;
/**
* Mangled context name (used to help distinguish 2 sessions with same id on different contexts)
*/
private String _canonicalContext;
protected String _canonicalContext;
/**
@ -246,7 +246,8 @@ public class JDBCSessionManager extends AbstractSessionManager
@Override
public void setAttribute (String name, Object value)
{
_dirty = (updateAttribute(name, value) || _dirty);
updateAttribute(name, value);
_dirty = true;
}
@Override
@ -769,6 +770,20 @@ public class JDBCSessionManager extends AbstractSessionManager
{
return new Session(request);
}
/**
* @param sessionId
* @param rowId
* @param created
* @param accessed
* @param maxInterval
* @return
*/
protected AbstractSession newSession (String sessionId, String rowId, long created, long accessed, long maxInterval)
{
return new Session(sessionId, rowId, created, accessed, maxInterval);
}
/* ------------------------------------------------------------ */
/** Remove session from manager
@ -892,7 +907,7 @@ public class JDBCSessionManager extends AbstractSessionManager
{
maxInterval = getMaxInactiveInterval(); //if value not saved for maxInactiveInterval, use current value from sessionmanager
}
session = new Session(id, result.getString(_sessionTableSchema.getRowIdColumn()),
session = (Session)newSession(id, result.getString(_sessionTableSchema.getRowIdColumn()),
result.getLong(_sessionTableSchema.getCreateTimeColumn()),
result.getLong(_sessionTableSchema.getAccessTimeColumn()),
maxInterval);

View File

@ -58,7 +58,7 @@ public class DirtyAttributeTest
public static int SCAVENGE = 1;
@Test
public void testDiryWrite() throws Exception
public void testDirtyWrite() throws Exception
{
AbstractTestServer server = new JdbcTestServer(0,INACTIVE,SCAVENGE);
@ -98,8 +98,8 @@ public class DirtyAttributeTest
request.header("Cookie", sessionCookie);
response = request.send();
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
A_VALUE.assertPassivatesEquals(1);
A_VALUE.assertActivatesEquals(1);
A_VALUE.assertPassivatesEquals(2);
A_VALUE.assertActivatesEquals(2);
A_VALUE.assertBindsEquals(1);
A_VALUE.assertUnbindsEquals(0);