protected void ReallocateObjRefsAndCacheValues(CacheWalkerResult entry, IObjRef[] objRefs, HashMap <IObjRef, int?> allObjRefs) { IObjRef[] oldObjRefs = entry.objRefs; Object[] oldCacheValues = entry.cacheValues; Object[] newCacheValues = new Object[objRefs.Length]; for (int oldIndex = oldObjRefs.Length; oldIndex-- > 0;) { IObjRef oldObjRef = oldObjRefs[oldIndex]; int? newIndex = allObjRefs.Get(oldObjRef); newCacheValues[newIndex.Value] = oldCacheValues[oldIndex]; } entry.cacheValues = newCacheValues; entry.objRefs = objRefs; entry.UpdatePendingChanges(); Object childEntries = entry.childEntries; if (childEntries == null) { return; } if (childEntries.GetType().IsArray) { foreach (CacheWalkerResult childEntry in (CacheWalkerResult[])childEntries) { ReallocateObjRefsAndCacheValues(childEntry, objRefs, allObjRefs); } } else { ReallocateObjRefsAndCacheValues((CacheWalkerResult)childEntries, objRefs, allObjRefs); } }
protected IObjRef ExtractAndMergeObjRef(IDataChangeEntry dataChangeEntry, IDictionary <IObjRef, IObjRef> touchedObjRefSet) { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(dataChangeEntry.EntityType); IObjRef objRef = GetObjRef(dataChangeEntry, metaData); IObjRef existingObjRef = DictionaryExtension.ValueOrDefault(touchedObjRefSet, objRef); if (existingObjRef == null) { touchedObjRefSet.Add(objRef, objRef); return(objRef); } Object newVersion = objRef.Version; Object existingVersion = existingObjRef.Version; if (newVersion == null) { return(existingObjRef); } if (existingVersion == null || ((IComparable)newVersion).CompareTo(existingVersion) >= 0) { existingObjRef.Version = newVersion; } return(existingObjRef); }
public void AddObject(IObjRef objRef, IPrimitiveUpdateItem[] primitiveUpdates, IRelationUpdateItem[] relationUpdates, String changedBy, long changedOn) { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(objRef.RealType); Object[] primitives = new Object[metaData.PrimitiveMembers.Length]; IObjRef[][] relations = new IObjRef[metaData.RelationMembers.Length][]; for (int a = relations.Length; a-- > 0;) { relations[a] = ObjRef.EMPTY_ARRAY; } LoadContainer loadContainer = new LoadContainer(); loadContainer.Reference = new ObjRef(objRef.RealType, objRef.Id, null); loadContainer.Primitives = primitives; loadContainer.Relations = relations; writeLock.Lock(); try { refToObjectDict.Add(loadContainer.Reference, loadContainer); ChangeObject(objRef, primitiveUpdates, relationUpdates, changedBy, changedOn); } finally { writeLock.Unlock(); } }
protected void WriteChangeContainer(IChangeContainer changeContainer, IWriter writer, IncrementalMergeState incrementalState) { IObjRef objRef = changeContainer.Reference; writer.WriteStartElement("Entity"); writer.WriteAttribute("type", objRef.RealType.FullName); writer.WriteAttribute("id", ConversionHelper.ConvertValueToType <String>(objRef.Id)); if (objRef.Version != null) { writer.WriteAttribute("version", ConversionHelper.ConvertValueToType <String>(objRef.Version)); } StateEntry stateEntry = incrementalState.objRefToStateMap.Get(objRef); if (stateEntry == null) { throw new Exception(); } writer.WriteAttribute("idx", stateEntry.index); if (changeContainer is DeleteContainer) { writer.WriteEndElement(); return; } ICreateOrUpdateContainer createOrUpdate = (ICreateOrUpdateContainer)changeContainer; WritePUIs(createOrUpdate.GetFullPUIs(), writer); WriteRUIs(createOrUpdate.GetFullRUIs(), writer, incrementalState); writer.WriteCloseElement("Entity"); }
public bool WritesCustom(Object obj, Type type, IWriter writer) { if (SyncToAsyncUtil.IsLowLevelSerializationType(type)) { // Those types can never be an entity return(false); } IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(type, true); if (metaData == null) { return(false); } int idValue = writer.GetIdOfObject(obj); if (idValue != 0) { writer.WriteStartElement(XmlDictionary.RefElement); writer.WriteAttribute(XmlDictionary.IdAttribute, idValue); writer.WriteEndElement(); } else { writer.AddSubstitutedEntity(obj); IObjRef ori = ObjRefHelper.EntityToObjRef(obj, true); WriteOpenElement(ori, obj, writer); writer.WriteObject(ori.RealType); writer.WriteObject(ori.Id); writer.WriteObject(ori.Version); writer.WriteCloseElement(XmlDictionary.OriWrapperElement); } return(true); }
public void RemoveObjRef(IObjRef objRef) { if (((ICollection)removedORIs).Count == 0) { removedORIs = new CHashSet <IObjRef>(); } removedORIs.Add(objRef); }
public void AddObjRef(IObjRef objRef) { if (((ICollection)addedORIs).Count == 0) { addedORIs = new CHashSet <IObjRef>(); } addedORIs.Add(objRef); }
public IList <ILoadContainer> GetEntities(IList <IObjRef> orisToLoad) { bool isTransaction = false; if (TransactionState != null) { isTransaction = TransactionState.IsTransactionActive; } List <ILoadContainer> result = new List <ILoadContainer>(); if (!isTransaction) { // Allow committed root cache only OUT OF transactions to retrieve data by itself IList <Object> loadContainers = CommittedRootCache.GetObjects(orisToLoad, loadContainerResultCD); for (int a = loadContainers.Count; a-- > 0;) { result.Add((ILoadContainer)loadContainers[a]); } InternStrings(result); return(result); } List <IObjRef> orisToLoadWithVersion = new List <IObjRef>(); List <IObjRef> missedOris = new List <IObjRef>(); for (int i = orisToLoad.Count; i-- > 0;) { IObjRef ori = orisToLoad[i]; if (ori.Version != null) { orisToLoadWithVersion.Add(ori); } else { missedOris.Add(ori); } } IList <Object> loadContainers2 = CommittedRootCache.GetObjects(orisToLoadWithVersion, committedRootCacheCD); for (int a = loadContainers2.Count; a-- > 0;) { ILoadContainer loadContainer = (ILoadContainer)loadContainers2[a]; if (loadContainer == null) { missedOris.Add(orisToLoadWithVersion[a]); } else { result.Add(loadContainer); } } if (missedOris.Count > 0) { IList <ILoadContainer> uncommittedLoadContainer = UncommittedCacheRetriever.GetEntities(missedOris); result.AddRange(uncommittedLoadContainer); } InternStrings(result); return(result); }
public override IObjRef Dup(IObjRef objRef) { IPreparedObjRefFactory objRefConstructorDelegate = constructorDelegateMap.Get(objRef.RealType, objRef.IdNameIndex); if (objRefConstructorDelegate == null) { objRefConstructorDelegate = BuildDelegate(objRef.RealType, objRef.IdNameIndex); } return(objRefConstructorDelegate.CreateObjRef(objRef.Id, objRef.Version)); }
public void Handle(IList <IObjectFuture> objectFutures) { IEntityFactory entityFactory = EntityFactory; IList <IObjRef> oris = new List <IObjRef>(objectFutures.Count); // ObjectFutures have to be handled in order for (int i = 0, size = objectFutures.Count; i < size; i++) { IObjectFuture objectFuture = objectFutures[i]; if (!(objectFuture is ObjRefFuture)) { throw new ArgumentException("'" + GetType().Name + "' cannot handle " + typeof(IObjectFuture).Name + " implementations of type '" + objectFuture.GetType().Name + "'"); } if (objectFuture.Value != null) { continue; } ObjRefFuture objRefFuture = (ObjRefFuture)objectFuture; IObjRef ori = objRefFuture.Ori; if (ori.Id != null && !Object.Equals(ori.Id, 0)) { oris.Add(ori); } else if (ori is IDirectObjRef && ((IDirectObjRef)ori).Direct != null) { Object entity = ((IDirectObjRef)ori).Direct; objRefFuture.Value = entity; oris.Add(null); } else { Object newEntity = entityFactory.CreateEntity(ori.RealType); objRefFuture.Value = newEntity; oris.Add(null); } } IList <Object> objects = Cache.GetObjects(oris, CacheDirective.ReturnMisses); for (int i = 0, size = objectFutures.Count; i < size; i++) { if (oris[i] == null) { continue; } ObjRefFuture objRefFuture = (ObjRefFuture)objectFutures[i]; Object obj = objects[i]; objRefFuture.Value = obj; } }
protected void CheckCascadeRefreshNeeded(CacheDependencyNode node) { CacheChangeItem[] cacheChangeItems = node.cacheChangeItems; if (cacheChangeItems == null) { return; } HashMap <IObjRef, CacheValueAndPrivilege> objRefToCacheValueMap = node.objRefToCacheValueMap; for (int c = cacheChangeItems.Length; c-- > 0;) { CacheChangeItem cci = cacheChangeItems[c]; if (cci == null) { continue; } IList <IObjRef> objectRefsToUpdate = cci.UpdatedObjRefs; IList <Object> objectsToUpdate = cci.UpdatedObjects; for (int a = objectRefsToUpdate.Count; a-- > 0;) { IObjRef objRefToUpdate = objectRefsToUpdate[a]; Object objectToUpdate = objectsToUpdate[a]; CacheValueAndPrivilege cacheValueAndPrivilege = objRefToCacheValueMap.Get(objRefToUpdate); if (cacheValueAndPrivilege == null) { // Current value in childCache is not in our interest here continue; } IEntityMetaData metaData = ((IEntityMetaDataHolder)objectToUpdate).Get__EntityMetaData(); RelationMember[] relationMembers = metaData.RelationMembers; if (relationMembers.Length == 0) { continue; } RootCacheValue cacheValue = cacheValueAndPrivilege.cacheValue; IObjRefContainer vhc = (IObjRefContainer)objectToUpdate; for (int relationIndex = relationMembers.Length; relationIndex-- > 0;) { if (ValueHolderState.INIT != vhc.Get__State(relationIndex)) { continue; } // the object which has to be updated has initialized relations. So we have to ensure // that these relations are in the RootCache at the time the target object will be updated. // This is because initialized relations have to remain initialized after update but the relations // may have been updated, too BatchPendingRelations(cacheValue, relationMembers[relationIndex], cacheValue.GetRelation(relationIndex), node); } } } }
protected IObjRef[] CloneObjRefs(IObjRef[] original) { if (original == null || original.Length == 0) { return(original); } IObjRef[] clone = new IObjRef[original.Length]; for (int a = original.Length; a-- > 0;) { clone[a] = CloneObjRef(original[a], true); } return(clone); }
public void ProcessRead(IPostProcessReader reader) { reader.NextTag(); ICommandTypeRegistry commandTypeRegistry = reader.CommandTypeRegistry; ICommandTypeExtendable commandTypeExtendable = reader.CommandTypeExtendable; commandTypeExtendable.RegisterOverridingCommandType(typeof(MergeArraySetterCommand), typeof(ArraySetterCommand)); Object result = reader.ReadObject(); commandTypeExtendable.UnregisterOverridingCommandType(typeof(MergeArraySetterCommand), typeof(ArraySetterCommand)); if (!(result is CUDResult)) { throw new Exception("Can only handle results of type '" + typeof(CUDResult).Name + "'. Result of type '" + result.GetType().Name + "' given."); } ICommandBuilder commandBuilder = CommandBuilder; Member directObjRefDirectMember = this.directObjRefDirectMember; CUDResult cudResult = (CUDResult)result; IList <IChangeContainer> changes = cudResult.AllChanges; for (int i = 0, size = changes.Count; i < size; i++) { IChangeContainer changeContainer = changes[i]; if (!(changeContainer is CreateContainer)) { continue; } IObjRef ori = changeContainer.Reference; if (ori == null) { continue; } else if (ori is DirectObjRef) { IObjectFuture objectFuture = new ObjRefFuture(ori); IObjectCommand setterCommand = commandBuilder.Build(commandTypeRegistry, objectFuture, ori, directObjRefDirectMember); reader.AddObjectCommand(setterCommand); IObjectCommand mergeCommand = commandBuilder.Build(commandTypeRegistry, objectFuture, changeContainer); reader.AddObjectCommand(mergeCommand); } else { throw new Exception("Not implemented yet"); } } }
protected void WriteOpenElement(IObjRef ori, Object obj, IWriter writer) { writer.WriteStartElement(XmlDictionary.OriWrapperElement); int id = writer.AcquireIdForObject(obj); writer.WriteAttribute(XmlDictionary.IdAttribute, id); sbyte idIndex = ori.IdNameIndex; if (idIndex != ObjRef.PRIMARY_KEY_INDEX) { writer.WriteAttribute(idNameIndex, idIndex.ToString()); } writer.WriteStartElementEnd(); }
public virtual void WriteObjRefs() { IObjRef[] allOris = new IObjRef[4]; ObjRef ori = new ObjRef(typeof(String), 2, 4); allOris[0] = ori; String xml = CyclicXmlHandler.Write(ori); Assert.AssertEquals(XmlTestConstants.XmlOutput[15], xml, "Wrong xml"); Object actual = CyclicXmlHandler.Read(xml); Assert.AssertSame(typeof(ObjRef), actual.GetType(), "Wrong class"); AssertObjRefEquals(ori, (ObjRef)actual); ori = new ObjRef(typeof(String), -1, 2, 4); allOris[1] = ori; xml = CyclicXmlHandler.Write(ori); Assert.AssertEquals(XmlTestConstants.XmlOutput[15], xml, "Wrong xml"); actual = CyclicXmlHandler.Read(xml); Assert.AssertSame(typeof(ObjRef), actual.GetType(), "Wrong class"); AssertObjRefEquals(ori, (ObjRef)actual); ori = new ObjRef(typeof(String), 0, "zwei", 4); allOris[2] = ori; xml = CyclicXmlHandler.Write(ori); Assert.AssertEquals(XmlTestConstants.XmlOutput[16], xml, "Wrong xml"); actual = CyclicXmlHandler.Read(xml); Assert.AssertSame(typeof(ObjRef), actual.GetType(), "Wrong class"); AssertObjRefEquals(ori, (ObjRef)actual); ori = new ObjRef(typeof(String), 1, "zwei", 4); allOris[3] = ori; xml = CyclicXmlHandler.Write(ori); Assert.AssertEquals(XmlTestConstants.XmlOutput[17], xml, "Wrong xml"); actual = CyclicXmlHandler.Read(xml); Assert.AssertSame(typeof(ObjRef), actual.GetType(), "Wrong class"); AssertObjRefEquals(ori, (ObjRef)actual); xml = CyclicXmlHandler.Write(allOris); actual = CyclicXmlHandler.Read(xml); Assert.AssertEquals(allOris.GetType(), actual.GetType()); IObjRef[] actualArray = (IObjRef[])actual; Assert.AssertEquals(allOris.Length, actualArray.Length); for (int i = 0; i < allOris.Length; i++) { AssertObjRefEquals((ObjRef)allOris[i], (ObjRef)actualArray[i]); } }
protected IObjRef ResolveObjRefOfCache(IObjRef objRef, CloneState cloneState) { StateEntry stateEntry = cloneState.incrementalState.objRefToStateMap.Get(objRef); if (stateEntry != null) { return(stateEntry.objRef); } stateEntry = cloneState.newObjRefToStateEntryMap.Get(objRef); if (stateEntry != null) { return(stateEntry.objRef); } return(objRef); }
public static OptimisticLockException ThrowModified(IObjRef objRef, Object givenVersion, Object obj) { String givenVersionString = ""; if (givenVersion != null) { givenVersionString = " - given version: " + givenVersion; } if (obj != null) { throw new OptimisticLockException("Object outdated: " + objRef + " has been modified concurrently" + givenVersionString, null, obj); } throw new OptimisticLockException("Object outdated: " + objRef + " has been modified concurrently" + givenVersionString, null, new ObjRef( objRef.RealType, objRef.IdNameIndex, objRef.Id, givenVersion)); }
public virtual bool WritesCustom(Object obj, Type type, IWriter writer) { if (!typeof(IObjRef).IsAssignableFrom(type) || typeof(IDirectObjRef).IsAssignableFrom(type)) { return(false); } IObjRef ori = (IObjRef)obj; WriteOpenElement(ori, writer); writer.WriteObject(ori.RealType); writer.WriteObject(ori.Id); writer.WriteObject(ori.Version); writer.WriteCloseElement(XmlDictionary.EntityRefElement); return(true); }
protected int WaitForConcurrentReadFinish(IList <IObjRef> orisToGet, IList <IObjRef> orisToLoad) { Lock readLock = ReadLock; bool releaseReadLock = true; HashSet <IObjRef> objRefsAlreadyQueried = null; readLock.Lock(); try { for (int a = 0, size = orisToGet.Count; a < size; a++) { IObjRef oriToGet = orisToGet[a]; if (oriToGet == null || (oriToGet is IDirectObjRef && ((IDirectObjRef)oriToGet).Direct != null)) { continue; } Object cacheValue = ExistsValue(oriToGet); if (cacheValue != null) { // Cache hit, but not relevant at this step, so we continue continue; } if (objRefsAlreadyQueried == null) { objRefsAlreadyQueried = new HashSet <IObjRef>(); } if (!objRefsAlreadyQueried.Add(oriToGet)) { // Object has been already queried from parent // It makes no sense to query it multiple times continue; } orisToLoad.Add(oriToGet); } if (orisToLoad.Count == 0) { releaseReadLock = false; } return(changeVersion); } finally { if (releaseReadLock) { readLock.Unlock(); } } }
public void ObjRefToString(IObjRef objRef, StringBuilder sb) { sb.Append("ObjRef "); sbyte idIndex = objRef.IdNameIndex; if (idIndex == ObjRef.PRIMARY_KEY_INDEX) { sb.Append("PK="); } else { sb.Append("AK").Append(idIndex).Append('='); } StringBuilderUtil.AppendPrintable(sb, objRef.Id); sb.Append(" version=").Append(objRef.Version).Append(" type=").Append(objRef.RealType.FullName); }
public virtual Object ReadObject(Type returnType, String elementName, int id, IReader reader) { if (!XmlDictionary.EntityRefElement.Equals(elementName)) { throw new Exception("Element '" + elementName + "' not supported"); } String idIndexValue = reader.GetAttributeValue(idNameIndex); sbyte idIndex = idIndexValue != null?SByte.Parse(idIndexValue) : ObjRef.PRIMARY_KEY_INDEX; reader.NextTag(); Type realType = (Type)reader.ReadObject(); Object objId = reader.ReadObject(); Object version = reader.ReadObject(); if (objId != null || version != null) { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(realType, true); if (metaData != null) { if (objId != null) { PrimitiveMember idMember = metaData.GetIdMemberByIdIndex(idIndex); if (objId.Equals(idMember.NullEquivalentValue)) { objId = null; } } if (version != null) { PrimitiveMember versionMember = metaData.VersionMember; if (versionMember != null) { if (version.Equals(versionMember.NullEquivalentValue)) { version = null; } } } } } IObjRef obj = ObjRefFactory.CreateObjRef(realType, idIndex, objId, version); return(obj); }
public Object GetObject(IObjRef oriToGet, ICacheIntern targetCache, CacheDirective cacheDirective) { CheckNotDisposed(); if (oriToGet == null) { return(null); } List <IObjRef> orisToGet = new List <IObjRef>(1); orisToGet.Add(oriToGet); IList <Object> objects = GetObjects(orisToGet, targetCache, cacheDirective); if (objects.Count == 0) { return(null); } return(objects[0]); }
protected IDictionary <Type, IList <IObjRef> > BucketSortObjRefs(IList <IObjRef> orisToLoad) { IDictionary <Type, IList <IObjRef> > sortedIObjRefs = new Dictionary <Type, IList <IObjRef> >(); for (int i = orisToLoad.Count; i-- > 0;) { IObjRef oriToLoad = orisToLoad[i]; Type type = oriToLoad.RealType; IList <IObjRef> objRefs = DictionaryExtension.ValueOrDefault(sortedIObjRefs, type); if (objRefs == null) { objRefs = new List <IObjRef>(); sortedIObjRefs.Add(type, objRefs); } objRefs.Add(oriToLoad); } return(sortedIObjRefs); }
public Object ProcessWrite(IPostProcessWriter writer) { ISet <Object> substitutedEntities = writer.SubstitutedEntities; if (substitutedEntities.Count == 0) { return(null); } IDisposableCache childCache = CacheFactory.Create(CacheFactoryDirective.NoDCE, "XmlMerge"); IServiceContext mergeContext = BeanContext.CreateService(delegate(IBeanContextFactory childContextFactory) { childContextFactory.RegisterBean(typeof(MergeHandle)).Autowireable <MergeHandle>().PropertyValue("Cache", childCache); }); try { IDictionary <Object, Int32> mutableToIdMap = writer.MutableToIdMap; IObjRefHelper objRefHelper = ObjRefHelper; MergeHandle mergeHandle = mergeContext.GetService <MergeHandle>(); IList <Object> toMerge = new List <Object>(substitutedEntities.Count); foreach (Object entity in substitutedEntities) { toMerge.Add(entity); IObjRef ori = objRefHelper.EntityToObjRef(entity); mergeHandle.objToOriDict.Add(entity, ori); Int32 id = mutableToIdMap[entity]; mutableToIdMap.Add(ori, id); } ICUDResult cudResult = MergeController.MergeDeep(toMerge, mergeHandle); if (cudResult.AllChanges.Count != 0) { return(cudResult); } else { return(null); } } finally { mergeContext.Dispose(); } }
protected IMap <Type, IList <IChangeContainer> > BucketSortChanges(IList <IChangeContainer> allChanges) { HashMap <Type, IList <IChangeContainer> > sortedChanges = new HashMap <Type, IList <IChangeContainer> >(); for (int i = allChanges.Count; i-- > 0;) { IChangeContainer changeContainer = allChanges[i]; IObjRef objRef = changeContainer.Reference; Type type = objRef.RealType; IList <IChangeContainer> changeContainers = sortedChanges.Get(type); if (changeContainers == null) { changeContainers = new List <IChangeContainer>(); sortedChanges.Put(type, changeContainers); } changeContainers.Add(changeContainer); } return(sortedChanges); }
public bool ObjRefEquals(IObjRef objRef, Object obj) { if (Object.ReferenceEquals(this, obj)) { return(true); } if (!(obj is IObjRef)) { return(false); } IObjRef other = (IObjRef)obj; if (objRef.IdNameIndex != other.IdNameIndex || !objRef.RealType.Equals(other.RealType)) { return(false); } Object id = objRef.Id; Object otherId = other.Id; if (id == null || otherId == null) { return(false); } if (!id.GetType().IsArray || !otherId.GetType().IsArray) { return(id.Equals(otherId)); } Object[] idArray = (Object[])id; Object[] otherIdArray = (Object[])otherId; if (idArray.Length != otherIdArray.Length) { return(false); } for (int a = idArray.Length; a-- > 0;) { if (!idArray[a].Equals(otherIdArray[a])) { return(false); } } return(true); }
public IRelationUpdateItem CreateRUI(String memberName, IList <IObjRef> oldOriList, IList <IObjRef> newOriList) { if (oldOriList.Count == 0 && newOriList.Count == 0) { return(null); } IISet <IObjRef> oldSet = oldOriList.Count > 0 ? new CHashSet <IObjRef>(oldOriList) : EmptySet.Empty <IObjRef>(); IISet <IObjRef> newSet = newOriList.Count > 0 ? new CHashSet <IObjRef>(newOriList) : EmptySet.Empty <IObjRef>(); IISet <IObjRef> smallerSet = ((ICollection)oldSet).Count > ((ICollection)newSet).Count ? newSet : oldSet; IISet <IObjRef> greaterSet = ((ICollection)oldSet).Count > ((ICollection)newSet).Count ? oldSet : newSet; // Check unchanged ORIs Iterator <IObjRef> smallerIter = smallerSet.Iterator(); while (smallerIter.MoveNext()) { // Old ORIs, which exist as new ORIs, too, are unchanged IObjRef objRef = smallerIter.Current; if (greaterSet.Remove(objRef)) { smallerIter.Remove(); } } if (((ICollection)oldSet).Count == 0 && ((ICollection)newSet).Count == 0) { return(null); } // Old ORIs are now handled as REMOVE, New ORIs as ADD RelationUpdateItem rui = new RelationUpdateItem(); rui.MemberName = memberName; if (((ICollection)oldSet).Count > 0) { rui.RemovedORIs = oldSet.ToArray(); } if (((ICollection)newSet).Count > 0) { rui.AddedORIs = newSet.ToArray(); } return(rui); }
public override bool Equals(IObjRef obj) { if (Object.ReferenceEquals(this, obj)) { return(true); } if (obj == null) { return(false); } if (Direct != null) { if (!(obj is IDirectObjRef)) { return(false); } return(Object.ReferenceEquals(Direct, ((IDirectObjRef)obj).Direct)); // Identity - not equals - intentionally here! } return(base.Equals(obj)); }
public Object ReadObject(Type returnType, String elementName, int id, IReader reader) { if (!XmlDictionary.OriWrapperElement.Equals(elementName)) { throw new Exception("Element '" + elementName + "' not supported"); } String idIndexValue = reader.GetAttributeValue(idNameIndex); sbyte idIndex = idIndexValue != null?SByte.Parse(idIndexValue) : ObjRef.PRIMARY_KEY_INDEX; reader.NextTag(); Type realType = (Type)reader.ReadObject(); Object objId = reader.ReadObject(); Object version = reader.ReadObject(); IObjRef ori = ObjRefFactory.CreateObjRef(realType, idIndex, objId, version); Object obj = new ObjRefFuture(ori); return(obj); }
public void test_ValueHolderContainer() { MaterialType obj = EntityFactory.CreateEntity <MaterialType>(); obj.Id = 2; obj.Name = "name2"; obj.Version = 1; MaterialType obj2 = EntityFactory.CreateEntity <MaterialType>(); obj2.Id = 3; obj2.Name = "name3"; obj2.Version = 1; IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(typeof(Material)); int relationIndex = metaData.GetIndexByRelationName("Types"); Material parentEntity = EntityFactory.CreateEntity <Material>(); Assert.IsInstanceOfType(parentEntity, typeof(IValueHolderContainer)); Assert.AssertEquals(ValueHolderState.LAZY, ((IObjRefContainer)parentEntity).Get__State(relationIndex)); Assert.AssertEquals(0, ((IObjRefContainer)parentEntity).Get__ObjRefs(relationIndex).Length); parentEntity.Id = 1; parentEntity.Name = "name1"; parentEntity.Version = 1; parentEntity.Types.Add(obj); parentEntity.Types.Add(obj2); IObjRef typeObjRef = OriHelper.EntityToObjRef(obj); IDisposableCache cache = CacheFactory.Create(CacheFactoryDirective.NoDCE, "test"); ((ICacheIntern)cache).AssignEntityToCache(parentEntity); ((IObjRefContainer)parentEntity).Set__ObjRefs(relationIndex, new IObjRef[] { typeObjRef }); Assert.AssertEquals(ValueHolderState.INIT, ((IObjRefContainer)parentEntity).Get__State(relationIndex)); Assert.AssertEquals(1, ((IObjRefContainer)parentEntity).Get__ObjRefs(relationIndex).Length); Object value = ValueHolderContainerMixin.GetValue((IValueHolderContainer)parentEntity, relationIndex); }