/// <summary>Returns a versioned value. </summary> /// <param name="parameters">getter and indexes</param> /// <returns>value</returns> public Object GetVersionedValue(RevisionGetterParameters parameters) { int propertyNumber = parameters.PropertyNumber; if (_overlay != null) { var value = _overlay[propertyNumber]; if (value != null) { return(value.Value); } } var getter = parameters.BaseGetter; if (getter == null) { return(null); // The property was added by a delta event and only exists on a delta } if (LastBaseEvent != null) { return(getter.Get(LastBaseEvent)); } return(null); }
private readonly Object propertyType; // Can be the {Type|Map|EventType} /// <summary>Ctor. </summary> /// <param name="revisionGetter">getter to use</param> /// <param name="revisionGetterParams">getter parameters</param> /// <param name="propertyType">type of the property</param> public RevisionPropertyTypeDesc(EventPropertyGetter revisionGetter, RevisionGetterParameters revisionGetterParams, Type propertyType) { this.revisionGetter = revisionGetter; this.revisionGetterParams = revisionGetterParams; this.propertyType = propertyType; }
/// <summary>Ctor. </summary> /// <param name="revisionGetter">getter to use</param> /// <param name="revisionGetterParams">getter parameters</param> /// <param name="propertyType">type of the property</param> public RevisionPropertyTypeDesc( EventPropertyGetterSPI revisionGetter, RevisionGetterParameters revisionGetterParams, Type propertyType) { RevisionGetter = revisionGetter; RevisionGetterParams = revisionGetterParams; PropertyType = propertyType; }
/// <summary>Returns a versioned value. </summary> /// <param name="parameters">getter parameters</param> /// <returns>value</returns> public Object GetVersionedValue(RevisionGetterParameters parameters) { RevisionBeanHolder holderMostRecent = null; if (Holders != null) { foreach (int numSet in parameters.PropertyGroups) { RevisionBeanHolder holder = Holders[numSet]; if (holder != null) { if (holderMostRecent == null) { holderMostRecent = holder; } else { if (holder.Version > holderMostRecent.Version) { holderMostRecent = holder; } } } } } // none found, use last full event if (holderMostRecent == null) { if (LastBaseEvent == null) { return(null); } return(parameters.BaseGetter.Get(LastBaseEvent)); } return(holderMostRecent.GetValueForProperty(parameters.PropertyNumber)); }
/// <summary>Creates property descriptors for revision. </summary> /// <param name="spec">specifies revision</param> /// <param name="groups">the groups that group properties</param> /// <returns>map of property and descriptor</returns> public static IDictionary <String, RevisionPropertyTypeDesc> CreatePropertyDescriptors(RevisionSpec spec, PropertyGroupDesc[] groups) { IDictionary <String, int[]> propsPerGroup = PropertyUtility.GetGroupsPerProperty(groups); IDictionary <String, RevisionPropertyTypeDesc> propertyDesc = new Dictionary <String, RevisionPropertyTypeDesc>(); int count = 0; foreach (String property in spec.ChangesetPropertyNames) { var fullGetter = spec.BaseEventType.GetGetter(property); var propertyNumber = count; var propGroupsProperty = propsPerGroup.Get(property); var paramList = new RevisionGetterParameters(property, propertyNumber, fullGetter, propGroupsProperty); // if there are no groups (full event property only), then simply use the full event getter EventPropertyGetter revisionGetter = new ProxyEventPropertyGetter( eventBean => ((RevisionEventBeanDeclared)eventBean).GetVersionedValue(paramList), eventBean => null, eventBean => true); var type = spec.BaseEventType.GetPropertyType(property); var propertyTypeDesc = new RevisionPropertyTypeDesc(revisionGetter, paramList, type); propertyDesc.Put(property, propertyTypeDesc); count++; } foreach (String property in spec.BaseEventOnlyPropertyNames) { EventPropertyGetter fullGetter = spec.BaseEventType.GetGetter(property); // if there are no groups (full event property only), then simply use the full event getter EventPropertyGetter revisionGetter = new ProxyEventPropertyGetter( eventBean => { var riv = (RevisionEventBeanDeclared)eventBean; var bean = riv.LastBaseEvent; return(bean == null ? null : fullGetter.Get(bean)); }, eventBean => null, eventBean => true); var type = spec.BaseEventType.GetPropertyType(property); var propertyTypeDesc = new RevisionPropertyTypeDesc(revisionGetter, null, type); propertyDesc.Put(property, propertyTypeDesc); count++; } count = 0; foreach (String property in spec.KeyPropertyNames) { int keyPropertyNumber = count; EventPropertyGetter revisionGetter; if (spec.KeyPropertyNames.Length == 1) { revisionGetter = new ProxyEventPropertyGetter { ProcGet = eventBean => ((RevisionEventBeanDeclared)eventBean).Key, ProcIsExistsProperty = eventBean => true, ProcGetFragment = eventBean => null }; } else { revisionGetter = new ProxyEventPropertyGetter { ProcGet = eventBean => { var riv = (RevisionEventBeanDeclared)eventBean; return(((MultiKeyUntyped)riv.Key).Keys[keyPropertyNumber]); }, ProcIsExistsProperty = eventBean => true, ProcGetFragment = eventBean => null }; } var type = spec.BaseEventType.GetPropertyType(property); var propertyTypeDesc = new RevisionPropertyTypeDesc(revisionGetter, null, type); propertyDesc.Put(property, propertyTypeDesc); count++; } return(propertyDesc); }
/// <summary>Returns base event value. </summary> /// <param name="parameters">supplies getter</param> /// <returns>value</returns> public Object GetBaseEventValue(RevisionGetterParameters parameters) { return(parameters.BaseGetter.Get(LastBaseEvent)); }
/// <summary>Creates property descriptors for revision. </summary> /// <param name="spec">specifies revision</param> /// <param name="groups">the groups that group properties</param> /// <returns>map of property and descriptor</returns> public static IDictionary <string, RevisionPropertyTypeDesc> CreatePropertyDescriptors( RevisionSpec spec, PropertyGroupDesc[] groups) { var propsPerGroup = PropertyUtility.GetGroupsPerProperty(groups); IDictionary <string, RevisionPropertyTypeDesc> propertyDesc = new Dictionary <string, RevisionPropertyTypeDesc>(); var count = 0; foreach (var property in spec.ChangesetPropertyNames) { var fullGetter = spec.BaseEventType.GetGetter(property); var propertyNumber = count; var propGroupsProperty = propsPerGroup.Get(property); var paramList = new RevisionGetterParameters(property, propertyNumber, fullGetter, propGroupsProperty); // if there are no groups (full event property only), then simply use the full event getter var revisionGetter = new VAERevisionEventPropertyGetterDeclaredGetVersioned(paramList); var type = spec.BaseEventType.GetPropertyType(property); var propertyTypeDesc = new RevisionPropertyTypeDesc(revisionGetter, paramList, type); propertyDesc.Put(property, propertyTypeDesc); count++; } foreach (var property in spec.BaseEventOnlyPropertyNames) { var fullGetter = ((EventTypeSPI)spec.BaseEventType).GetGetterSPI(property); // if there are no groups (full event property only), then simply use the full event getter var revisionGetter = new VAERevisionEventPropertyGetterDeclaredLast(fullGetter); var type = spec.BaseEventType.GetPropertyType(property); var propertyTypeDesc = new RevisionPropertyTypeDesc(revisionGetter, null, type); propertyDesc.Put(property, propertyTypeDesc); count++; } count = 0; foreach (var property in spec.KeyPropertyNames) { var keyPropertyNumber = count; EventPropertyGetterSPI revisionGetter; if (spec.KeyPropertyNames.Length == 1) { revisionGetter = new VAERevisionEventPropertyGetterDeclaredOneKey(); } else { revisionGetter = new VAERevisionEventPropertyGetterDeclaredNKey(keyPropertyNumber); } var type = spec.BaseEventType.GetPropertyType(property); var propertyTypeDesc = new RevisionPropertyTypeDesc(revisionGetter, null, type); propertyDesc.Put(property, propertyTypeDesc); count++; } return(propertyDesc); }
/// <summary> /// Ctor. /// </summary> /// <param name="revisioneventTypeName">name</param> /// <param name="spec">specification</param> /// <param name="statementStopService">for stop handling</param> /// <param name="eventAdapterService">for nested property handling</param> /// <param name="eventTypeIdGenerator">The event type id generator.</param> public VAERevisionProcessorMerge(String revisioneventTypeName, RevisionSpec spec, StatementStopService statementStopService, EventAdapterService eventAdapterService, EventTypeIdGenerator eventTypeIdGenerator) : base(spec, revisioneventTypeName, eventAdapterService) { // on statement stop, remove versions statementStopService.StatementStopped += () => _statePerKey.Clear(); _statePerKey = new Dictionary <Object, RevisionStateMerge>(); // For all changeset properties, add type descriptors (property number, getter etc) var propertyDesc = new Dictionary <String, RevisionPropertyTypeDesc>(); var count = 0; foreach (String property in spec.ChangesetPropertyNames) { var fullGetter = spec.BaseEventType.GetGetter(property); var propertyNumber = count; var paramList = new RevisionGetterParameters(property, propertyNumber, fullGetter, null); // if there are no groups (full event property only), then simply use the full event getter EventPropertyGetter revisionGetter = new ProxyEventPropertyGetter( eventBean => { var riv = (RevisionEventBeanMerge)eventBean; return(riv.GetVersionedValue(paramList)); }, eventBean => null, eventBean => true); var type = spec.BaseEventType.GetPropertyType(property); if (type == null) { foreach (EventType deltaType in spec.DeltaTypes) { var dtype = deltaType.GetPropertyType(property); if (dtype != null) { type = dtype; break; } } } var propertyTypeDesc = new RevisionPropertyTypeDesc(revisionGetter, paramList, type); propertyDesc.Put(property, propertyTypeDesc); count++; } count = 0; foreach (String property in spec.KeyPropertyNames) { var keyPropertyNumber = count; EventPropertyGetter revisionGetter; if (spec.KeyPropertyNames.Length == 1) { revisionGetter = new ProxyEventPropertyGetter { ProcGet = eventBean => ((RevisionEventBeanMerge)eventBean).Key, ProcIsExistsProperty = eventBean => true, ProcGetFragment = eventBean => null }; } else { revisionGetter = new ProxyEventPropertyGetter { ProcGet = eventBean => { var riv = (RevisionEventBeanMerge)eventBean; return(((MultiKeyUntyped)riv.Key).Keys[keyPropertyNumber]); }, ProcIsExistsProperty = eventBean => true, ProcGetFragment = eventBean => null }; } var type = spec.BaseEventType.GetPropertyType(property); if (type == null) { foreach (EventType deltaType in spec.DeltaTypes) { var dtype = deltaType.GetPropertyType(property); if (dtype != null) { type = dtype; break; } } } var propertyTypeDesc = new RevisionPropertyTypeDesc(revisionGetter, null, type); propertyDesc.Put(property, propertyTypeDesc); count++; } // compile for each event type a list of getters and indexes within the overlay foreach (EventType deltaType in spec.DeltaTypes) { RevisionTypeDesc typeDesc = MakeTypeDesc(deltaType, spec.PropertyRevision); TypeDescriptors.Put(deltaType, typeDesc); } _infoFullType = MakeTypeDesc(spec.BaseEventType, spec.PropertyRevision); // how to handle updates to a full event if (spec.PropertyRevision == PropertyRevisionEnum.MERGE_DECLARED) { _updateStrategy = new UpdateStrategyDeclared(spec); } else if (spec.PropertyRevision == PropertyRevisionEnum.MERGE_NON_NULL) { _updateStrategy = new UpdateStrategyNonNull(spec); } else if (spec.PropertyRevision == PropertyRevisionEnum.MERGE_EXISTS) { _updateStrategy = new UpdateStrategyExists(spec); } else { throw new ArgumentException("Unknown revision type '" + spec.PropertyRevision + "'"); } EventTypeMetadata metadata = EventTypeMetadata.CreateValueAdd(revisioneventTypeName, TypeClass.REVISION); RevisionEventType = new RevisionEventType(metadata, eventTypeIdGenerator.GetTypeId(revisioneventTypeName), propertyDesc, eventAdapterService); }
public VAERevisionEventPropertyGetterMerge(RevisionGetterParameters parameters) { _parameters = parameters; }
public VAERevisionEventPropertyGetterDeclaredGetVersioned(RevisionGetterParameters parameters) { _parameters = parameters; }