429357 JDBCSessionManager.Session.removeAttribute don't set dirty flag if attribute already removed

This commit is contained in:
Jan Bartel 2014-03-13 16:13:16 +11:00
parent 4de73d508b
commit b405ad8c4f
3 changed files with 67 additions and 29 deletions

View File

@ -77,7 +77,11 @@ public class NoSqlSession extends AbstractSession
@Override
public void setAttribute(String name, Object value)
{
if ( updateAttribute(name,value) )
Object old = changeAttribute(name,value);
if (value == null && old == null)
return; //not dirty, no change
if (value==null || !value.equals(old))
{
if (_dirty==null)
{
@ -96,30 +100,7 @@ public class NoSqlSession extends AbstractSession
super.timeout();
}
/*
* a boolean version of the setAttribute method that lets us manage the _dirty set
*/
protected boolean updateAttribute (String name, Object value)
{
Object old=null;
synchronized (this)
{
checkValid();
old=doPutOrRemove(name,value);
}
if (value==null || !value.equals(old))
{
if (old!=null)
unbindValue(name,old);
if (value!=null)
bindValue(name,value);
_manager.doSessionAttributeListeners(this,name,old,value);
return true;
}
return false;
}
/* ------------------------------------------------------------ */
@Override

View File

@ -443,7 +443,7 @@ public abstract class AbstractSession implements AbstractSessionManager.SessionI
@Override
public void putValue(java.lang.String name, java.lang.Object value) throws IllegalStateException
{
setAttribute(name,value);
changeAttribute(name,value);
}
/* ------------------------------------------------------------ */
@ -481,10 +481,16 @@ public abstract class AbstractSession implements AbstractSessionManager.SessionI
@Override
public void setAttribute(String name, Object value)
{
updateAttribute(name,value);
changeAttribute(name,value);
}
/* ------------------------------------------------------------ */
/**
* @param name
* @param value
* @deprecated use changeAttribute(String,Object) instead
* @return
*/
protected boolean updateAttribute (String name, Object value)
{
Object old=null;
@ -506,6 +512,53 @@ public abstract class AbstractSession implements AbstractSessionManager.SessionI
}
return false;
}
/* ------------------------------------------------------------ */
/**
* Either set (perhaps replace) or remove the value of the attribute
* in the session. The appropriate session attribute listeners are
* also called.
*
* @param name
* @param value
* @return
*/
protected Object changeAttribute (String name, Object value)
{
Object old=null;
synchronized (this)
{
checkValid();
old=doPutOrRemove(name,value);
}
callSessionAttributeListeners(name, value, old);
return old;
}
/* ------------------------------------------------------------ */
/**
* Call binding and attribute listeners based on the new and old
* values of the attribute.
*
* @param name name of the attribute
* @param newValue new value of the attribute
* @param oldValue previous value of the attribute
*/
protected void callSessionAttributeListeners (String name, Object newValue, Object oldValue)
{
if (newValue==null || !newValue.equals(oldValue))
{
if (oldValue!=null)
unbindValue(name,oldValue);
if (newValue!=null)
bindValue(name,newValue);
_manager.doSessionAttributeListeners(this,name,oldValue,newValue);
}
}
/* ------------------------------------------------------------ */
protected void addAttributes(Map<String,Object> map)

View File

@ -246,15 +246,19 @@ public class JDBCSessionManager extends AbstractSessionManager
@Override
public void setAttribute (String name, Object value)
{
updateAttribute(name, value);
Object old = changeAttribute(name, value);
if (value == null && old == null)
return; //if same as remove attribute but attribute was already removed, no change
_dirty = true;
}
@Override
public void removeAttribute (String name)
{
super.removeAttribute(name);
_dirty=true;
Object old = changeAttribute(name, null);
if (old != null) //only dirty if there was a previous value
_dirty=true;
}
@Override