* Proxy the held field if needed. Return true if the field needs to
* be replaced with the now-proxied instance.
*/
public boolean proxy(boolean reset, boolean replaceNull) {
FieldMetaData fmd = _sm.getMetaData().getField(field);
Proxy proxy = null;
boolean ret = false;
switch (fmd.getDeclaredTypeCode()) {
case JavaTypes.DATE:
if (objval == null)
return false;
proxy = checkProxy();
if (proxy == null) {
proxy = (Proxy) _sm.newFieldProxy(field);
((Date) proxy).setTime(((Date) objval).getTime());
if (proxy instanceof Timestamp
&& objval instanceof Timestamp)
((Timestamp) proxy).setNanos(((Timestamp) objval).
getNanos());
ret = true;
}
break;
case JavaTypes.CALENDAR:
if (objval == null)
return false;
proxy = checkProxy();
if (proxy == null) {
proxy = (Proxy) _sm.newFieldProxy(field);
((Calendar) proxy).setTime(((Calendar) objval).getTime());
ret = true;
}
break;
case JavaTypes.COLLECTION:
if (objval == null && !replaceNull)
return false;
proxy = checkProxy();
if (proxy == null) {
proxy = (Proxy) _sm.newFieldProxy(field);
if (objval != null)
((Collection) proxy).addAll((Collection) objval);
ret = true;
}
break;
case JavaTypes.MAP:
if (objval == null && !replaceNull)
return false;
proxy = checkProxy();
if (proxy == null) {
proxy = (Proxy) _sm.newFieldProxy(field);
if (objval != null)
((Map) proxy).putAll((Map) objval);
ret = true;
}
break;
case JavaTypes.OBJECT:
if (objval == null)
return false;
proxy = checkProxy();
if (proxy == null) {
proxy = getProxyManager().newCustomProxy(objval,
_sm.getBroker().getConfiguration().
getCompatibilityInstance().getAutoOff());
ret = proxy != null;
}
break;
}
if (proxy != null) {
proxy.setOwner(_sm, field);
ChangeTracker tracker = proxy.getChangeTracker();
if (reset && tracker != null) {
if (fmd.getDeclaredTypeCode() == JavaTypes.MAP) {
// track values if key is derived from value, else keys
boolean keys = fmd.getKey().getValueMappedBy() == null;
((MapChangeTracker) tracker).setTrackKeys(keys);