You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gc...@apache.org on 2011/04/30 04:01:53 UTC
svn commit: r1098036 - in
/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean:
PropertyKey.java util/PropertyArrayMap.java util/PropertyHashMap.java
Author: gcrawford
Date: Sat Apr 30 02:01:52 2011
New Revision: 1098036
URL: http://svn.apache.org/viewvc?rev=1098036&view=rev
Log:
TRINIDAD-2091 add mutable information to property key to support partial state saving
Modified:
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/PropertyKey.java
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/PropertyArrayMap.java
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/PropertyHashMap.java
Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/PropertyKey.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/PropertyKey.java?rev=1098036&r1=1098035&r2=1098036&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/PropertyKey.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/PropertyKey.java Sat Apr 30 02:01:52 2011
@@ -64,6 +64,15 @@ public class PropertyKey
* Capability indicating this property can use the PartialStateHolder API.
*/
static public final int CAP_PARTIAL_STATE_HOLDER = 16;
+
+ /**
+ * Capability indicating the type of this property is mutable.
+ * In partial state saving only the deltas are saved, and deltas are generated by sets on
+ * component attributes, without a set getting called an attribute will not be in the delta list,
+ * and therefore won't be state saved. This property can tell us whether the type of the property
+ * is mutable and if so it can be put into the delta list.
+ */
+ static public final int CAP_MUTABLE = 32;
/**
* Create a named PropertyKey, not attached to any type.
@@ -226,6 +235,14 @@ public class PropertyKey
{
return (_capabilities & CAP_LIST) != 0;
}
+
+ /**
+ * Returns true if the type of this property is mutable
+ */
+ public boolean isMutable()
+ {
+ return (_capabilities & CAP_MUTABLE) != 0;
+ }
/**
* Returns true if the property is used to store a PartialStateHolder.
@@ -409,7 +426,8 @@ public class PropertyKey
CAP_TRANSIENT |
CAP_LIST |
CAP_STATE_HOLDER|
- CAP_PARTIAL_STATE_HOLDER;
+ CAP_PARTIAL_STATE_HOLDER|
+ CAP_MUTABLE;
static private final Class<Object> _TYPE_DEFAULT = Object.class;
Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/PropertyArrayMap.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/PropertyArrayMap.java?rev=1098036&r1=1098035&r2=1098036&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/PropertyArrayMap.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/PropertyArrayMap.java Sat Apr 30 02:01:52 2011
@@ -54,64 +54,83 @@ public class PropertyArrayMap extends Ar
}
@Override
- public Object put(
- PropertyKey key,
- Object value)
- {
- Object retValue = super.put(key, value);
- if (_createDeltas())
- {
- if (!_equals(value, retValue))
- _deltas.put(key, value);
- }
-
- if (key.isPartialStateHolder())
- {
- _getPartialStateHolderTracker(true).addProperty(key);
- }
+ public Object put(
+ PropertyKey key,
+ Object value)
+ {
+ Object retValue = super.put(key, value);
+ if (_createDeltas())
+ {
+ if (!_equals(value, retValue))
+ _deltas.put(key, value);
+ }
+ else if (key.isMutable())
+ {
+ _getMutableTracker(true).addProperty(key);
+ }
+
+ if (key.isPartialStateHolder())
+ {
+ _getPartialStateHolderTracker(true).addProperty(key);
+ }
- return retValue;
- }
+ return retValue;
+ }
@Override
- public Object remove(
- Object key)
- {
- if (_createDeltas())
- {
- if (!super.containsKey(key))
- return null;
-
- // If this key is contained, it certainly must be a PropertyKey!
- assert(key instanceof PropertyKey);
- _deltas.put((PropertyKey) key, null);
- }
+ public Object remove(
+ Object key)
+ {
+ boolean useDeltas = _createDeltas();
- if (key instanceof PropertyKey)
- {
- PropertyKey propKey = (PropertyKey)key;
- if (propKey.isPartialStateHolder())
- {
- _getPartialStateHolderTracker(true).removeProperty(propKey);
- }
- }
+ if (useDeltas)
+ {
+ if (!super.containsKey(key))
+ return null;
+
+ // If this key is contained, it certainly must be a PropertyKey!
+ assert(key instanceof PropertyKey);
+ _deltas.put((PropertyKey) key, null);
+ }
+
+ if (key instanceof PropertyKey)
+ {
+ PropertyKey propKey = (PropertyKey)key;
+ if (propKey.isPartialStateHolder())
+ {
+ _getPartialStateHolderTracker(true).removeProperty(propKey);
+ }
+
+ if (!useDeltas && propKey.isMutable())
+ {
+ _getMutableTracker(true).removeProperty(propKey);
+ }
+ }
- return super.remove(key);
- }
+ return super.remove(key);
+ }
@Override
public void putAll(Map<? extends PropertyKey, ? extends Object> t)
{
- if (_createDeltas())
- _deltas.putAll(t);
+ boolean useDeltas =_createDeltas();
+ if (useDeltas)
+ _deltas.putAll(t);
+
Set<? extends PropertyKey> keys = t.keySet();
for (PropertyKey key: keys)
{
if (key.isPartialStateHolder())
{
_getPartialStateHolderTracker(true).addProperty(key);
+ }
+
+ if (!useDeltas && key.isMutable())
+ {
+ _getMutableTracker(true).addProperty(key);
}
+
}
super.putAll(t);
@@ -120,7 +139,7 @@ public class PropertyArrayMap extends Ar
public Object saveState(FacesContext context)
{
if (_initialStateMarked)
- {
+ {
if (_deltas == null)
return null;
@@ -144,6 +163,24 @@ public class PropertyArrayMap extends Ar
{
PropertyArrayMap map = new PropertyArrayMap(2);
map.setUseStateHolder(getUseStateHolder());
+ map.setType(_type);
+
+ PropertyTracker tracker = _getMutableTracker(false);
+
+ if (tracker != null)
+ {
+ for (PropertyKey key: tracker)
+ {
+ Object val = get(key);
+
+ if (val != null)
+ {
+ map.put(key, val);
+ }
+ }
+
+ _mutableTracker = null;
+ }
return map;
}
@@ -258,7 +295,19 @@ public class PropertyArrayMap extends Ar
}
return _tracker;
}
-
+
+ private PropertyTracker _getMutableTracker(boolean create)
+ {
+ if (_mutableTracker == null && create)
+ {
+ if (_type == null)
+ {
+ throw new IllegalStateException("FacesBean.TYPE is required to track properties");
+ }
+ _mutableTracker = new PropertyTracker(_type);
+ }
+ return _mutableTracker;
+ }
private transient boolean _initialStateMarked;
@@ -266,4 +315,5 @@ public class PropertyArrayMap extends Ar
private boolean _useStateHolder;
private FacesBean.Type _type;
private PropertyTracker _tracker;
+ private transient PropertyTracker _mutableTracker;
}
Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/PropertyHashMap.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/PropertyHashMap.java?rev=1098036&r1=1098035&r2=1098036&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/PropertyHashMap.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/PropertyHashMap.java Sat Apr 30 02:01:52 2011
@@ -19,6 +19,7 @@
package org.apache.myfaces.trinidad.bean.util;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -59,55 +60,68 @@ public class PropertyHashMap extends Has
}
@Override
- public Object put(
- PropertyKey key,
- Object value)
- {
- Object retValue = super.put(key, value);
- if (_createDeltas())
- {
- if (!_equals(value, retValue))
- _deltas.put(key, value);
- }
-
- if (key.isPartialStateHolder())
- {
- _getPartialStateHolderTracker(true).addProperty(key);
- }
+ public Object put(
+ PropertyKey key,
+ Object value)
+ {
+ Object retValue = super.put(key, value);
+ if (_createDeltas())
+ {
+ if (!_equals(value, retValue))
+ _deltas.put(key, value);
+ }
+ else if (key.isMutable())
+ {
+ _getMutableTracker(true).addProperty(key);
+ }
+
+ if (key.isPartialStateHolder())
+ {
+ _getPartialStateHolderTracker(true).addProperty(key);
+ }
- return retValue;
- }
+ return retValue;
+ }
@Override
- public Object remove(
- Object key)
- {
- if (_createDeltas())
- {
- if (!super.containsKey(key))
- return null;
-
- // If this key is contained, it certainly must be a PropertyKey!
- assert(key instanceof PropertyKey);
- _deltas.put((PropertyKey) key, null);
- }
+ public Object remove(
+ Object key)
+ {
+ boolean useDeltas = _createDeltas();
- if (key instanceof PropertyKey)
- {
- PropertyKey propKey = (PropertyKey)key;
- if (propKey.isPartialStateHolder())
- {
- _getPartialStateHolderTracker(true).removeProperty(propKey);
- }
- }
+ if (useDeltas)
+ {
+ if (!super.containsKey(key))
+ return null;
+
+ // If this key is contained, it certainly must be a PropertyKey!
+ assert(key instanceof PropertyKey);
+ _deltas.put((PropertyKey) key, null);
+ }
+
+ if (key instanceof PropertyKey)
+ {
+ PropertyKey propKey = (PropertyKey)key;
+ if (propKey.isPartialStateHolder())
+ {
+ _getPartialStateHolderTracker(true).removeProperty(propKey);
+ }
+
+ if (!useDeltas && propKey.isMutable())
+ {
+ _getMutableTracker(true).removeProperty(propKey);
+ }
+ }
- return super.remove(key);
- }
+ return super.remove(key);
+ }
@Override
public void putAll(Map<? extends PropertyKey, ? extends Object> t)
{
- if (_createDeltas())
+ boolean useDeltas =_createDeltas();
+
+ if (useDeltas)
_deltas.putAll(t);
Set<? extends PropertyKey> keys = t.keySet();
@@ -116,7 +130,13 @@ public class PropertyHashMap extends Has
if (key.isPartialStateHolder())
{
_getPartialStateHolderTracker(true).addProperty(key);
+ }
+
+ if (!useDeltas && key.isMutable())
+ {
+ _getMutableTracker(true).addProperty(key);
}
+
}
super.putAll(t);
@@ -125,7 +145,7 @@ public class PropertyHashMap extends Has
public Object saveState(FacesContext context)
{
if (_initialStateMarked)
- {
+ {
if (_deltas == null)
return null;
@@ -149,6 +169,25 @@ public class PropertyHashMap extends Has
{
PropertyHashMap map = new PropertyHashMap(2);
map.setUseStateHolder(getUseStateHolder());
+ map.setType(_type);
+
+ PropertyTracker tracker = _getMutableTracker(false);
+
+ if (tracker != null)
+ {
+ for (PropertyKey key: tracker)
+ {
+ Object val = get(key);
+
+ if (val != null)
+ {
+ map.put(key, val);
+ }
+ }
+
+ _mutableTracker = null;
+ }
+
return map;
}
@@ -259,12 +298,27 @@ public class PropertyHashMap extends Has
}
return _tracker;
}
+
+
+ private PropertyTracker _getMutableTracker(boolean create)
+ {
+ if (_mutableTracker == null && create)
+ {
+ if (_type == null)
+ {
+ throw new IllegalStateException("FacesBean.TYPE is required to track properties");
+ }
+ _mutableTracker = new PropertyTracker(_type);
+ }
+ return _mutableTracker;
+ }
private transient boolean _initialStateMarked;
private transient PropertyMap _deltas;
private boolean _useStateHolder;
private transient FacesBean.Type _type;
private transient PropertyTracker _tracker;
+ private transient PropertyTracker _mutableTracker;
private static final long serialVersionUID = 1L;