/** * public boolean hasPendingChanges() { return isToBeUpdated() || isToBeCreated() || isToBeDeleted(); } */ protected void ImplementHasPendingChanges(PropertyInstance p_hasPendingChanges, PropertyInstance p_ToBeUpdated, PropertyInstance p_ToBeCreated, PropertyInstance p_ToBeDeleted) { IMethodVisitor mg = VisitMethod(p_hasPendingChanges.Getter); p_hasPendingChanges = PropertyInstance.FindByTemplate(p_hasPendingChanges, false); p_hasPendingChanges.AddAnnotation(c_ignoreToBeUpdated); p_hasPendingChanges.AddAnnotation(c_fireThisOPC, p_ToBeCreated.Name); p_hasPendingChanges.AddAnnotation(c_fireThisOPC, p_ToBeUpdated.Name); p_hasPendingChanges.AddAnnotation(c_fireThisOPC, p_ToBeDeleted.Name); Label trueLabel = mg.NewLabel(); mg.LoadThis(); mg.InvokeVirtual(p_ToBeUpdated.Getter); mg.IfZCmp(CompareOperator.NE, trueLabel); mg.LoadThis(); mg.InvokeVirtual(p_ToBeCreated.Getter); mg.IfZCmp(CompareOperator.NE, trueLabel); mg.LoadThis(); mg.InvokeVirtual(p_ToBeDeleted.Getter); mg.IfZCmp(CompareOperator.NE, trueLabel); mg.Push(false); mg.ReturnValue(); mg.Mark(trueLabel); mg.Push(true); mg.ReturnValue(); mg.EndMethod(); }
public override void VisitEnd() { PropertyInstance p_toBeCreated = ImplementToBeCreated(template_p_toBeCreated); PropertyInstance p_toBeUpdated = ImplementToBeUpdated(); // ToBeDeleted FieldInstance f_toBeDeleted = ImplementField(new FieldInstance(FieldAttributes.Private, "toBeDeleted", template_p_toBeDeleted.PropertyType)); PropertyInstance p_toBeDeleted = ImplementProperty(template_p_toBeDeleted, delegate(IMethodVisitor mv) { mv.GetThisField(f_toBeDeleted); mv.ReturnValue(); }, delegate(IMethodVisitor mv) { mv.PutThisField(f_toBeDeleted, delegate(IMethodVisitor mv2) { mv2.LoadArg(0); }); mv.ReturnValue(); }); p_toBeDeleted.AddAnnotation(c_ignoreToBeUpdated); ImplementHasPendingChanges(p_hasPendingChanges, p_toBeUpdated, p_toBeCreated, p_toBeDeleted); base.VisitEnd(); }
public virtual PropertyInstance HideFromDebug(PropertyInstance property) { if (HideFromDebugActive) { property.AddAnnotation(c_hideFromDebug, DebuggerBrowsableState.Never); } return(property); }
public virtual PropertyInstance FireThisOnPropertyChange(PropertyInstance property, params String[] propertyNames) { property = State.GetProperty(property.Name, property.PropertyType); foreach (String propertyName in propertyNames) { property.AddAnnotation(c_ftopc, propertyName); } return(property); }
/** * public boolean isToBeCreated() { return get__Id() == null; } * * @param owner */ protected PropertyInstance ImplementToBeCreated(PropertyInstance p_toBeCreated) { IMethodVisitor mg = VisitMethod(p_toBeCreated.Getter); p_toBeCreated = PropertyInstance.FindByTemplate(p_toBeCreated, false); Member idMember = metaData.IdMember; if (idMember is CompositeIdMember) { List <String> names = new List <String>(); foreach (Member itemMember in ((CompositeIdMember)idMember).Members) { names.Add(itemMember.Name); } p_toBeCreated.AddAnnotation(c_fireThisOPC, new Object[] { names.ToArray() }); } else { p_toBeCreated.AddAnnotation(c_fireThisOPC, idMember.Name); } Label trueLabel = mg.NewLabel(); mg.LoadThis(); mg.InvokeVirtual(GetIdMethodCreator.GetGetId()); mg.IfNull(trueLabel); mg.Push(false); mg.ReturnValue(); mg.Mark(trueLabel); mg.Push(true); mg.ReturnValue(); mg.EndMethod(); return(p_toBeCreated); }
protected PropertyInstance ImplementToBeUpdated() { PropertyInstance p_dataObjectTemplate = GetDataObjectTemplatePI(this); FieldInstance f_toBeUpdated = ImplementField(new FieldInstance(FieldAttributes.Private, "$toBeUpdated", template_p_toBeUpdated.PropertyType)); bool atLeastOneToManyMember = false; List <RelationMember> parentChildMembers = new List <RelationMember>(); foreach (RelationMember relationMember in metaData.RelationMembers) { if (relationMember.GetAnnotation(typeof(ParentChild)) != null) { parentChildMembers.Add(relationMember); if (relationMember.IsToMany) { atLeastOneToManyMember = true; } } } bool fAtLeastOneToManyMember = atLeastOneToManyMember; PropertyInstance p_toBeUpdated = ImplementProperty(template_p_toBeUpdated, delegate(IMethodVisitor mg) { if (parentChildMembers.Count == 0) { mg.GetThisField(f_toBeUpdated); mg.ReturnValue(); } else { LocalVariableInfo loc_iterator = null; if (fAtLeastOneToManyMember) { loc_iterator = mg.NewLocal(typeof(IEnumerator)); } // we have to check the toBeUpdated-State for our "parentChild" members to decide our own toBeUpdate-State by OR-concatenation LocalVariableInfo loc_parentChildValue = mg.NewLocal(typeof(Object)); Label trueLabel = mg.NewLabel(); mg.GetThisField(f_toBeUpdated); mg.IfZCmp(CompareOperator.NE, trueLabel); foreach (RelationMember parentChildMember in parentChildMembers) { int relationIndex = metaData.GetIndexByRelationName(parentChildMember.Name); Label l_valueIsNull = mg.NewLabel(); // load this RelationMember at runtime to be able to call its "getValue(Object obj)" mg.LoadThis(); mg.Push(relationIndex); mg.InvokeVirtual(MethodInstance.FindByTemplate(RelationsGetterVisitor.m_template_isInitialized_Member, false)); mg.IfZCmp(CompareOperator.EQ, l_valueIsNull); // skip this member if it is not initialized mg.LoadThis(); mg.Push(relationIndex); mg.InvokeVirtual(MethodInstance.FindByTemplate(RelationsGetterVisitor.m_template_getValueDirect_Member, false)); mg.StoreLocal(loc_parentChildValue); mg.LoadLocal(loc_parentChildValue); mg.IfNull(l_valueIsNull); mg.LoadLocal(loc_parentChildValue); if (parentChildMember.IsToMany) { Label l_startLoop = mg.NewLabel(); Label l_endLoop = mg.NewLabel(); mg.CheckCast(typeof(IEnumerable)); mg.InvokeInterface(new MethodInstance(null, typeof(IEnumerable), typeof(IEnumerator), "GetEnumerator")); mg.StoreLocal(loc_iterator); mg.Mark(l_startLoop); mg.LoadLocal(loc_iterator); mg.InvokeInterface(new MethodInstance(null, typeof(IEnumerator), typeof(bool), "MoveNext")); mg.IfZCmp(CompareOperator.EQ, l_endLoop); mg.LoadLocal(loc_iterator); mg.InvokeInterface(new MethodInstance(null, typeof(IEnumerator), typeof(Object), "get_Current")); mg.CheckCast(typeof(IDataObject)); mg.InvokeInterface(template_p_toBeUpdated.Getter); mg.IfZCmp(CompareOperator.NE, trueLabel); mg.GoTo(l_startLoop); mg.Mark(l_endLoop); } else { mg.CheckCast(typeof(IDataObject)); mg.InvokeInterface(template_p_toBeUpdated.Getter); mg.IfZCmp(CompareOperator.NE, trueLabel); } mg.Mark(l_valueIsNull); } mg.Push(false); mg.ReturnValue(); mg.Mark(trueLabel); mg.Push(true); mg.ReturnValue(); } }, delegate(IMethodVisitor mv) { LocalVariableInfo loc_existingValue = mv.NewLocal(typeof(bool)); Label l_finish = mv.NewLabel(); mv.GetThisField(f_toBeUpdated); mv.StoreLocal(loc_existingValue); mv.LoadLocal(loc_existingValue); mv.LoadArg(0); mv.IfCmp(typeof(bool), CompareOperator.EQ, l_finish); mv.PutThisField(f_toBeUpdated, delegate(IMethodVisitor mg2) { mg2.LoadArg(0); }); // call dataObjectTemplate mv.CallThisGetter(p_dataObjectTemplate); // "this" argument mv.LoadThis(); // oldValue argument mv.LoadLocal(loc_existingValue); // newValue argument mv.LoadArg(0); mv.InvokeVirtual(m_toBeUpdatedChanged); mv.Mark(l_finish); mv.ReturnValue(); }); p_toBeUpdated.AddAnnotation(c_ignoreToBeUpdated); return(p_toBeUpdated); }
protected void ImplementRelationGetter(String propertyName, MethodInstance m_getMethod_template, MethodInstance m_setMethod, int relationIndex, PropertyInstance p_valueHolderContainerTemplate, PropertyInstance p_targetCache, PropertyInstance p_relationMembers, FieldInstance f_initialized, FieldInstance f_objRefs) { // public String getPropertyName() // { // if (!PropertyName$initialized) // { // setPropertyName(RelationsGetterVisitor.valueHolderContainer_getValue(this, $relationMembers, get__IndexOfPropertyName(), $targetCache, $beanContext, // propertyName$objRefs)); // } // return super.getPropertyName(); // } Script script_getVHC; if (EmbeddedEnhancementHint.HasMemberPath(State.Context)) { PropertyInstance p_rootEntity = EmbeddedTypeVisitor.GetRootEntityProperty(this); script_getVHC = delegate(IMethodVisitor mv) { mv.CallThisGetter(p_rootEntity); }; } else { script_getVHC = delegate(IMethodVisitor mv) { // this mv.LoadThis(); }; } MethodInstance m_getMethod; { PropertyInstance p_cacheModification = SetCacheModificationMethodCreator.GetCacheModificationPI(this); MethodInstance m_getMethod_scoped = new MethodInstance(State.NewType, MethodAttributes.HideBySig | MethodAttributes.Private | MethodAttributes.Final, NewType.VOID_TYPE, propertyName + "$DoInitialize"); { IMethodVisitor mg = VisitMethod(m_getMethod_scoped); // this => for this.setPropertyName(...) mg.LoadThis(); // call template.getValue(..) mg.CallThisGetter(p_valueHolderContainerTemplate); // getVhc() script_getVHC.Invoke(mg); // $relationMembers mg.CallThisGetter(p_relationMembers); // get__IndexOfPropertyName() mg.Push(relationIndex); // $targetCache mg.CallThisGetter(p_targetCache); // propertyName$objRefs mg.GetThisField(f_objRefs); mg.InvokeVirtual(m_template_getValue); mg.CheckCast(m_setMethod.Parameters[0].Type); mg.InvokeVirtual(m_setMethod); mg.ReturnValue(); mg.EndMethod(); } { IMethodVisitor mg = base.VisitMethod(m_getMethod_template); m_getMethod = mg.Method; HideFromDebug(m_getMethod); Label l_initialized = mg.NewLabel(); mg.GetThisField(f_initialized); mg.PushEnum(ValueHolderState.INIT); mg.IfCmp(typeof(ValueHolderState), CompareOperator.EQ, l_initialized); SetCacheModificationMethodCreator.CacheModificationInternalUpdate(p_cacheModification, mg, delegate(IMethodVisitor mv2) { mv2.LoadThis(); mv2.InvokeOnExactOwner(m_getMethod_scoped); }); mg.Mark(l_initialized); mg.LoadThis(); mg.InvokeSuperOfCurrentMethod(); mg.ReturnValue(); mg.EndMethod(); } } // public String getPropertyName$NoInit() // { // return super.getPropertyName(); // } { MethodInstance m_getNoInit = m_getMethod_template.DeriveName(ValueHolderIEC.GetGetterNameOfRelationPropertyWithNoInit(propertyName)); IMethodVisitor mg = base.VisitMethod(m_getNoInit); PropertyInstance p_getNoInit = PropertyInstance.FindByTemplate(propertyName + ValueHolderIEC.GetNoInitSuffix(), m_getNoInit.ReturnType, false); p_getNoInit.AddAnnotation(c_fireThisOPC, propertyName); p_getNoInit.AddAnnotation(c_fireTargetOPC, propertyName); mg.LoadThis(); mg.InvokeSuper(m_getMethod); mg.ReturnValue(); mg.EndMethod(); } }