protected bool IsPrio2Member(IEntityMetaData rootMetaData, IEntityMetaData metaData, PrefetchPath[] prefetchPaths, ILinkedMap <Type, PrefetchPath[]> entityTypeToPrefetchSteps, Tuple2KeyHashMap <Type, PrefetchPath[], bool?> alreadyVisited, MergePrefetchPathsCache mergePrefetchPathsCache) { IEntityMetaDataProvider entityMetaDataProvider = this.entityMetaDataProvider; foreach (PrefetchPath prefetchPath in prefetchPaths) { if (!alreadyVisited.PutIfNotExists(prefetchPath.memberType, prefetchPath.children, true)) { continue; } PrefetchPath[] children = mergePrefetchPathsCache.MergePrefetchPaths(prefetchPath.memberType, prefetchPath.children, entityTypeToPrefetchSteps); if (children == null) { continue; } IEntityMetaData childMetaData = entityMetaDataProvider.GetMetaData(prefetchPath.memberType); if (metaData == childMetaData) { // prio1 case at a later stage continue; } if (rootMetaData == childMetaData) { // prio1 in a transitive manner (current stage) return(true); } if (IsPrio2Member(rootMetaData, childMetaData, children, entityTypeToPrefetchSteps, alreadyVisited, mergePrefetchPathsCache)) { return(true); } } return(false); }
protected void ImplementGetEntityType(IPropertyInfo[] property) { IMethodVisitor mv = VisitMethod(template_m_getEntityType); Type entityType = this.entityType; IEntityMetaData metaData = entityMetaDataProvider.GetMetaData(entityType, true); if (metaData != null) { entityType = metaData.EntityType; } mv.Push(entityType); mv.ReturnValue(); mv.EndMethod(); }
protected HashMap <String, int?> GetOrCreateRelationMemberNameToIndexMap(Type entityType) { if (typeToMemberNameToIndexMap == null) { typeToMemberNameToIndexMap = new HashMap <Type, HashMap <String, int?> >(); } HashMap <String, int?> memberNameToIndexMap = typeToMemberNameToIndexMap.Get(entityType); if (memberNameToIndexMap != null) { return(memberNameToIndexMap); } IEntityMetaData metaData = entityMetaDataProvider.GetMetaData(entityType); RelationMember[] relationMembers = metaData.RelationMembers; memberNameToIndexMap = HashMap <String, int?> .Create(relationMembers.Length); for (int a = relationMembers.Length; a-- > 0;) { memberNameToIndexMap.Put(relationMembers[a].Name, a); } typeToMemberNameToIndexMap.Put(entityType, memberNameToIndexMap); return(memberNameToIndexMap); }
public PrefetchPath[] MergePrefetchPaths(Type entityType, PrefetchPath[] relativePrefetchPath, IMap <Type, PrefetchPath[]> entityTypeToPrefetchPaths) { if (entityTypeToPrefetchPaths == null) { return(EMPTY_PREFETCH_PATHS); } if (relativePrefetchPath == null) { relativePrefetchPath = EMPTY_PREFETCH_PATHS; } PrefetchPath[] prefetchPaths = prefetchPathsMap.Get(entityType, relativePrefetchPath, entityTypeToPrefetchPaths); if (prefetchPaths != null) { return(prefetchPaths); } IEntityMetaData metaData = entityMetaDataProvider.GetMetaData(entityType, true); if (metaData == null) { prefetchPathsMap.Put(entityType, relativePrefetchPath, entityTypeToPrefetchPaths, relativePrefetchPath); return(relativePrefetchPath); } PrefetchPath[] absolutePrefetchPath = entityTypeToPrefetchPaths.Get(metaData.EntityType); if (absolutePrefetchPath == null) { prefetchPathsMap.Put(entityType, relativePrefetchPath, entityTypeToPrefetchPaths, relativePrefetchPath); return(relativePrefetchPath); } if (relativePrefetchPath.Length == 0) { prefetchPathsMap.Put(entityType, relativePrefetchPath, entityTypeToPrefetchPaths, absolutePrefetchPath); return(absolutePrefetchPath); } HashMap <String, PrefetchPath> tempPrefetchPaths = HashMap <String, PrefetchPath> .Create(relativePrefetchPath.Length + absolutePrefetchPath.Length); foreach (PrefetchPath prefetchPath in relativePrefetchPath) { tempPrefetchPaths.PutIfNotExists(prefetchPath.memberName, prefetchPath); } foreach (PrefetchPath prefetchPath in absolutePrefetchPath) { tempPrefetchPaths.PutIfNotExists(prefetchPath.memberName, prefetchPath); } prefetchPaths = tempPrefetchPaths.ToArray(); prefetchPathsMap.Put(entityType, relativePrefetchPath, entityTypeToPrefetchPaths, prefetchPaths); return(prefetchPaths); }
public ICUDResult CreateCUDResult(MergeHandle mergeHandle) { ILinkedMap <Type, ICUDResultExtension> typeToCudResultExtension = extensions.GetExtensions(); foreach (Entry <Type, ICUDResultExtension> entry in typeToCudResultExtension) { entry.Value.Extend(mergeHandle); } IdentityLinkedMap <Object, IList <IUpdateItem> > objToModDict = mergeHandle.objToModDict; IdentityHashSet <Object> objToDeleteSet = mergeHandle.objToDeleteSet; HashMap <Type, IPrimitiveUpdateItem[]> entityTypeToFullPuis = new HashMap <Type, IPrimitiveUpdateItem[]>(); HashMap <Type, IRelationUpdateItem[]> entityTypeToFullRuis = new HashMap <Type, IRelationUpdateItem[]>(); List <IChangeContainer> allChanges = new List <IChangeContainer>(objToModDict.Count); List <Object> originalRefs = new List <Object>(objToModDict.Count); foreach (Object objToDelete in objToDeleteSet) { IObjRef ori = OriHelper.GetCreateObjRef(objToDelete, mergeHandle); DeleteContainer deleteContainer = new DeleteContainer(); deleteContainer.Reference = ori; allChanges.Add(deleteContainer); originalRefs.Add(objToDelete); } IEntityMetaDataProvider entityMetaDataProvider = this.EntityMetaDataProvider; foreach (Entry <Object, IList <IUpdateItem> > entry in objToModDict) { Object obj = entry.Key; IList <IUpdateItem> modItems = entry.Value; IEntityMetaData metaData = entityMetaDataProvider.GetMetaData(obj.GetType()); IPrimitiveUpdateItem[] fullPuis = GetEnsureFullPUIs(metaData, entityTypeToFullPuis); IRelationUpdateItem[] fullRuis = GetEnsureFullRUIs(metaData, entityTypeToFullRuis); int puiCount = 0, ruiCount = 0; for (int a = modItems.Count; a-- > 0;) { IUpdateItem modItem = modItems[a]; Member member = metaData.GetMemberByName(modItem.MemberName); if (modItem is IRelationUpdateItem) { fullRuis[metaData.GetIndexByRelation(member)] = (IRelationUpdateItem)modItem; ruiCount++; } else { fullPuis[metaData.GetIndexByPrimitive(member)] = (IPrimitiveUpdateItem)modItem; puiCount++; } } IRelationUpdateItem[] ruis = CompactRUIs(fullRuis, ruiCount); IPrimitiveUpdateItem[] puis = CompactPUIs(fullPuis, puiCount); IObjRef ori = OriHelper.GetCreateObjRef(obj, mergeHandle); originalRefs.Add(obj); if (ori is IDirectObjRef) { CreateContainer createContainer = new CreateContainer(); ((IDirectObjRef)ori).CreateContainerIndex = allChanges.Count; createContainer.Reference = ori; createContainer.Primitives = puis; createContainer.Relations = ruis; allChanges.Add(createContainer); } else { UpdateContainer updateContainer = new UpdateContainer(); updateContainer.Reference = ori; updateContainer.Primitives = puis; updateContainer.Relations = ruis; allChanges.Add(updateContainer); } } return(new CUDResult(allChanges, originalRefs)); }
protected override List <IMember> BuildMemberList() { List <IMember> list = new List <IMember>(); if (_target == null) { return(list); } if (Context == null) { return(base.BuildMemberList()); } IEntityMetaDataProvider entityMetaDataProvider = Context.GetService <IEntityMetaDataProvider>(); Type type = _target.GetType(); IEntityMetaData metaData = entityMetaDataProvider.GetMetaData(type, true); if (metaData == null) { return(base.BuildMemberList()); } HashSet <String> suppressedPropertyNames = new HashSet <String>(); foreach (RelationMember member in metaData.RelationMembers) { suppressedPropertyNames.Add(ValueHolderIEC.GetObjRefsFieldName(member.Name)); suppressedPropertyNames.Add(ValueHolderIEC.GetInitializedFieldName(member.Name)); } HashMap <String, RelationMember> nameToRelationMap = new HashMap <String, RelationMember>(); foreach (RelationMember member in metaData.RelationMembers) { nameToRelationMap.Put(member.Name + ValueHolderIEC.GetNoInitSuffix(), member); } ITypeInfoItem[] members = Context.GetService <ITypeInfoProvider>().GetTypeInfo(type).Members; foreach (ITypeInfoItem member in members) { if (!member.CanRead) { continue; } DebuggerBrowsableAttribute att = member.GetAnnotation <DebuggerBrowsableAttribute>(); if (att != null && att.State == DebuggerBrowsableState.Never) { continue; } String propertyName = member.Name; if (suppressedPropertyNames.Contains(propertyName)) { continue; } RelationMember relMember = nameToRelationMap.Get(propertyName); Object value = null; if (relMember != null) { propertyName = relMember.Name; int relationIndex = metaData.GetIndexByRelationName(propertyName); ValueHolderState state = ((IObjRefContainer)_target).Get__State(relationIndex); if (!ValueHolderState.INIT.Equals(state)) { IObjRef[] objRefs = ((IObjRefContainer)_target).Get__ObjRefs(relationIndex); if (objRefs == null) { list.Add(new LazyUnknownMember(propertyName, state, member.RealType)); } else { list.Add(new LazyMember(propertyName, state, objRefs, member.RealType)); } continue; } } if (value == null) { try { value = member.GetValue(_target); } catch (Exception ex) { value = ex; } } list.Add(new FHPMember(propertyName, value, member.RealType)); } return(list.OrderBy(m => m.Name).ToList()); }
protected virtual void Merge(Object obj, Object clone, MergeHandle handle) { IEntityMetaDataProvider entityMetaDataProvider = this.EntityMetaDataProvider; IEntityMetaData metaData = ((IEntityMetaDataHolder)obj).Get__EntityMetaData(); bool fieldBasedMergeActive = handle.FieldBasedMergeActive; bool oneChangeOccured = false; try { RelationMember[] relationMembers = metaData.RelationMembers; if (relationMembers.Length > 0) { IObjRefContainer vhc = (IObjRefContainer)obj; for (int relationIndex = relationMembers.Length; relationIndex-- > 0;) { RelationMember relationMember = relationMembers[relationIndex]; if (!metaData.IsMergeRelevant(relationMember)) { continue; } if (ValueHolderState.INIT != vhc.Get__State(relationIndex)) { // v2 valueholder is not initialized. so a change is impossible continue; } Object objMember = relationMember.GetValue(obj, false); Object cloneMember = relationMember.GetValue(clone, false); if (objMember is IDataObject && !((IDataObject)objMember).HasPendingChanges) { IEntityMetaData relationMetaData = entityMetaDataProvider.GetMetaData(relationMember.RealType); if (EqualsReferenceOrId(objMember, cloneMember, handle, relationMetaData)) { continue; } } IEntityMetaData childMetaData = entityMetaDataProvider.GetMetaData(relationMember.ElementType); if (IsMemberModified(objMember, cloneMember, handle, childMetaData)) { oneChangeOccured = true; AddOriModification(obj, relationMember.Name, objMember, cloneMember, handle); } } } if (fieldBasedMergeActive) { MergePrimitivesFieldBased(metaData, obj, clone, handle); return; } bool additionalRound; do { additionalRound = !oneChangeOccured; foreach (PrimitiveMember primitiveMember in metaData.PrimitiveMembers) { if (!metaData.IsMergeRelevant(primitiveMember)) { continue; } Object objValue = primitiveMember.GetValue(obj, true); if (oneChangeOccured) { AddModification(obj, primitiveMember.Name, primitiveMember.ElementType, objValue, null, handle); continue; } Object cloneValue = primitiveMember.GetValue(clone, true); if (!ArePrimitivesEqual(metaData, primitiveMember, objValue, cloneValue, handle)) { oneChangeOccured = true; break; } } }while (additionalRound && oneChangeOccured); } finally { PrimitiveMember versionMember = metaData.VersionMember; if (oneChangeOccured && versionMember != null) { // Check for early optimistic locking (Another, later level is directly on persistence layer) Object versionToMerge = versionMember.GetValue(obj, true); Object currentVersion = versionMember.GetValue(clone, true); int compareResult = ((IComparable)versionToMerge).CompareTo(currentVersion); if (ExactVersionForOptimisticLockingRequired ? compareResult != 0 : compareResult < 0) { throw new OptimisticLockException(currentVersion, versionToMerge, obj); } } } }
protected void LoadAndAddOrels(ICacheIntern cache, IMap <IObjRelation, bool> orelsToLoad, IList <Object> hardRefList, IMap <ICacheIntern, IISet <IObjRelation> > cacheToOrelsLoadedHistory, ILinkedMap <ICacheIntern, IISet <IObjRef> > cacheToOrisToLoad, IdentityLinkedSet <Member> prioMembers) { IList <IObjRelation> objRelList; if (prioMembers.Count > 0) { objRelList = new List <IObjRelation>(orelsToLoad.Count); IEntityMetaDataProvider entityMetaDataProvider = this.EntityMetaDataProvider; foreach (Entry <IObjRelation, Boolean> entry in orelsToLoad) { IObjRelation objRel = entry.Key; IEntityMetaData metaData = entityMetaDataProvider.GetMetaData(objRel.RealType); RelationMember memberByName = (RelationMember)metaData.GetMemberByName(objRel.MemberName); if (!prioMembers.Contains(memberByName)) { continue; } objRelList.Add(objRel); } } else { objRelList = orelsToLoad.KeyList(); } IList <IObjRelationResult> objRelResults = cache.GetObjRelations(objRelList, cache, CacheDirective.ReturnMisses); IISet <IObjRef> orisToLoad = null; for (int a = 0, size = objRelResults.Count; a < size; a++) { IObjRelation objRel = objRelList[a]; IObjRelationResult objRelResult = objRelResults[a]; bool objRefsOnly = orelsToLoad.Remove(objRel); if (objRelResult == null) { continue; } if (orelsToLoad.Get(objRel)) { // fetch only the objRefs, not the objects themselves continue; } IObjRef[] relations = objRelResult.Relations; if (relations.Length == 0 || objRefsOnly) { // fetch only the objRefs, not the objects themselves continue; } if (orisToLoad == null) { orisToLoad = cacheToOrisToLoad.Get(cache); if (orisToLoad == null) { orisToLoad = new CHashSet <IObjRef>(); cacheToOrisToLoad.Put(cache, orisToLoad); } } orisToLoad.AddAll(relations); } IISet <IObjRelation> orelsLoadedHistory = cacheToOrelsLoadedHistory.Get(cache); if (orelsLoadedHistory == null) { orelsLoadedHistory = new CHashSet <IObjRelation>(); cacheToOrelsLoadedHistory.Put(cache, orelsLoadedHistory); } orelsLoadedHistory.AddAll(objRelList); }