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 HashMap <String, int?> GetOrCreateRelationMemberNameToIndexMap(Type entityType, IMap <Type, HashMap <String, int?> > typeToMemberNameToIndexMap) { HashMap <String, int?> memberNameToIndexMap = typeToMemberNameToIndexMap.Get(entityType); if (memberNameToIndexMap != null) { return(memberNameToIndexMap); } lock (writeLock) { memberNameToIndexMap = typeToMemberNameToIndexMap.Get(entityType); if (memberNameToIndexMap != null) { // concurrent thread might have been faster 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); } }
protected void HandleObjects(Object objects, ILinkedMap <Type, PrefetchPath[]> entityTypeToPrefetchPath, AlreadyHandledSet alreadyHandledSet, IdentityLinkedMap <ICacheIntern, IISet <IObjRef> > cacheToOrisLoadedHistory, IdentityLinkedMap <ICacheIntern, IISet <IObjRelation> > cacheToOrelsLoadedHistory, IdentityLinkedMap <ICacheIntern, IISet <IObjRef> > cacheToOrisToLoad, IdentityLinkedMap <ICacheIntern, IMap <IObjRelation, Boolean> > cacheToOrelsToLoad, List <PrefetchCommand> loadItems) { if (objects is IEnumerable && !objects.GetType().Equals(typeof(String))) { foreach (Object item in (IEnumerable)objects) { if (item == null) { continue; } HandleObjects(item, entityTypeToPrefetchPath, alreadyHandledSet, cacheToOrisLoadedHistory, cacheToOrelsLoadedHistory, cacheToOrisToLoad, cacheToOrelsToLoad, loadItems); } return; } PrefetchPath[] cachePaths = null; if (entityTypeToPrefetchPath != null) { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(objects.GetType()); cachePaths = entityTypeToPrefetchPath.Get(metaData.EntityType); if (cachePaths == null || cachePaths.Length == 0) { return; } } EnsureInitializedRelationsIntern3(objects, cachePaths, entityTypeToPrefetchPath, cacheToOrisToLoad, cacheToOrelsToLoad, cacheToOrisLoadedHistory, cacheToOrelsLoadedHistory, alreadyHandledSet, loadItems); }
public bool ObjectEquals(Object leftObject, Object rightObject) { if (leftObject == null) { return(rightObject == null); } if (rightObject == null) { return(false); } if (leftObject == rightObject) { return(true); } Type leftType = leftObject.GetType(), rightType = rightObject.GetType(); if (!leftType.Equals(rightType)) { // Real entity types are not equal return(false); } IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(leftType); Object leftId = metaData.IdMember.GetValue(leftObject, false); Object rightId = metaData.IdMember.GetValue(rightObject, false); if (leftId == null || rightId == null) { // Entities are never equal with anything beside themselves if they do not have a persistent id return(false); } return(Object.Equals(leftId, rightId)); }
public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors, IList <IBytecodeBehavior> cascadePendingBehaviors) { if (state.GetContext <EntityEnhancementHint>() == null && state.GetContext <EmbeddedEnhancementHint>() == null) { // ensure LazyRelationsBehavior was invoked return(visitor); } // DefaultPropertiesBehavior executes in this cascade IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(EntityUtil.GetEntityType(state.Context)); CascadeBehavior cascadeBehavior = BeanContext.RegisterBean <CascadeBehavior>().PropertyValue("MetaData", metaData).Finish(); cascadePendingBehaviors.Add(cascadeBehavior); // // NotifyPropertyChangedBehavior executes in this cascade // Type currentType = state.getCurrentType(); // if (!IPropertyChanged.class.isAssignableFrom(currentType)) // { // if (!isAnnotationPresent(currentType, PropertyChangeAspect.class) && !isAnnotationPresent(currentType, DataObjectAspect.class)) // { // // behavior not applied // return visitor; // } // // // add IPropertyChanged // visitor = new InterfaceAdder(visitor, Type.getInternalName(IPropertyChanged.class)); // } // // IPropertyInfo[] propertyInfos = propertyInfoProvider.getProperties(currentType); // visitor = new NotifyPropertyChangedMethodVisitor(visitor, propertyInfos, objectCollector); // visitor = new PublicConstructorVisitor(visitor); return(visitor); }
public override void Initialize() { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(typeof(Material)); LoadContainer lc = new LoadContainer(); lc.Reference = new ObjRef(typeof(Material), 1, 1); lc.Primitives = new Object[metaData.PrimitiveMembers.Length]; lc.Relations = new IObjRef[metaData.RelationMembers.Length][]; lc.Primitives[metaData.GetIndexByPrimitiveName("Name")] = "Name1"; databaseMap.Put(lc.Reference, lc); IEntityMetaData metaData2 = EntityMetaDataProvider.GetMetaData(typeof(MaterialType)); LoadContainer lc2 = new LoadContainer(); lc2.Reference = new ObjRef(typeof(MaterialType), 2, 1); lc2.Primitives = new Object[metaData2.PrimitiveMembers.Length]; lc2.Relations = new IObjRef[metaData2.RelationMembers.Length][]; lc2.Primitives[metaData2.GetIndexByPrimitiveName("Name")] = "Name2"; lc.Relations[metaData.GetIndexByRelationName("Types")] = new IObjRef[] { lc2.Reference }; databaseMap.Put(lc2.Reference, lc2); }
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); }
protected void ReadConfig(IOrmConfigGroup ormConfigGroup) { LinkedHashSet <IEntityConfig> entities = new LinkedHashSet <IEntityConfig>(); entities.AddAll(ormConfigGroup.GetLocalEntityConfigs()); entities.AddAll(ormConfigGroup.GetExternalEntityConfigs()); foreach (IEntityConfig entityConfig in entities) { Type entityType = entityConfig.EntityType; if (EntityMetaDataProvider.GetMetaData(entityType, true) != null) { continue; } Type realType = entityConfig.RealType; EntityMetaData metaData = new EntityMetaData(); metaData.EntityType = entityType; metaData.RealType = realType; metaData.LocalEntity = entityConfig.Local; EntityMetaDataReader.AddMembers(metaData, entityConfig); managedEntityMetaData.Add(metaData); lock (EntityMetaDataExtendable) { EntityMetaDataExtendable.RegisterEntityMetaData(metaData); } } }
public void BuildCachePath(Type entityType, String memberToInitialize, CHashSet <AppendableCachePath> cachePaths) { Type currentType = entityType; String requestedMemberName = memberToInitialize; AppendableCachePath currentCachePath = null; CHashSet <AppendableCachePath> currentCachePaths = cachePaths; while (true) { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(currentType); Member widenedMember = metaData.GetWidenedMatchingMember(requestedMemberName); if (widenedMember == null) { throw new ArgumentException("No member found to resolve path " + entityType.FullName + "." + memberToInitialize); } String widenedMemberName = widenedMember.Name; if (widenedMember is PrimitiveMember) { if (widenedMemberName.Equals(memberToInitialize)) { // this member does not need to be prefetched return; } // widened member has been found but not the full path of the requested member name throw new ArgumentException("No member found to resolve path " + entityType.FullName + "." + memberToInitialize); } AppendableCachePath childCachePath = null; if (currentCachePaths == null) { currentCachePaths = new CHashSet <AppendableCachePath>(); currentCachePath.children = currentCachePaths; } foreach (AppendableCachePath cachePath in currentCachePaths) { if (widenedMemberName.Equals(cachePath.memberName)) { childCachePath = cachePath; break; } } if (childCachePath == null) { int relationIndex = metaData.GetIndexByRelation(widenedMember); childCachePath = new AppendableCachePath(widenedMember.ElementType, relationIndex, widenedMemberName); currentCachePaths.Add(childCachePath); } if (widenedMemberName.Equals(requestedMemberName)) { // we have travered the full path of the requested member name return; } requestedMemberName = requestedMemberName.Substring(widenedMemberName.Length + 1); currentCachePath = childCachePath; currentType = currentCachePath.memberType; currentCachePaths = currentCachePath.children; } }
protected IEntityMetaData GetSpecifiedMetaData(MethodInfo method, Type annotation, Type entityType) { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(entityType); if (metaData == null) { throw new Exception("Please specify a valid returnType for the " + annotation.Name + " annotation on method " + method.ToString() + ". The current value " + entityType.FullName + " is not a valid entity"); } return(metaData); }
public ValueHolderContainerEntry GetVhcEntry(Type targetType) { ValueHolderContainerEntry vhcEntry = typeToVhcEntryMap.Get(targetType); if (vhcEntry == null) { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(targetType); vhcEntry = new ValueHolderContainerEntry(targetType, metaData.RelationMembers, BytecodeEnhancer, PropertyInfoProvider, MemberTypeProvider); typeToVhcEntryMap.Put(targetType, vhcEntry); } return(vhcEntry); }
protected ITypePrivilege CreateTypePrivilegeFromServiceResult(Type entityType, ITypePrivilegeOfService privilegeOfService) { ITypePropertyPrivilegeOfService[] propertyPrivilegesOfService = privilegeOfService.PropertyPrivileges; ITypePropertyPrivilege defaultPropertyPrivilege = TypePropertyPrivilegeImpl.CreateFrom(privilegeOfService); if (propertyPrivilegesOfService == null || propertyPrivilegesOfService.Length == 0) { return(new SimpleTypePrivilegeImpl(privilegeOfService.CreateAllowed, privilegeOfService.ReadAllowed, privilegeOfService.UpdateAllowed, privilegeOfService.DeleteAllowed, privilegeOfService.ExecuteAllowed, defaultPropertyPrivilege)); } String[] propertyPrivilegeNames = privilegeOfService.PropertyPrivilegeNames; IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(entityType); ITypePropertyPrivilege[] primitivePropertyPrivileges = new ITypePropertyPrivilege[metaData.PrimitiveMembers.Length]; ITypePropertyPrivilege[] relationPropertyPrivileges = new ITypePropertyPrivilege[metaData.RelationMembers.Length]; for (int a = primitivePropertyPrivileges.Length; a-- > 0;) { primitivePropertyPrivileges[a] = defaultPropertyPrivilege; } for (int a = relationPropertyPrivileges.Length; a-- > 0;) { relationPropertyPrivileges[a] = defaultPropertyPrivilege; } for (int b = propertyPrivilegesOfService.Length; b-- > 0;) { ITypePropertyPrivilegeOfService propertyPrivilegeOfService = propertyPrivilegesOfService[b]; String propertyName = InterningFeature.Intern(propertyPrivilegeNames[b]); ITypePropertyPrivilege propertyPrivilege; if (propertyPrivilegeOfService != null) { propertyPrivilege = TypePropertyPrivilegeImpl.Create(propertyPrivilegeOfService.CreateAllowed, propertyPrivilegeOfService.ReadAllowed, propertyPrivilegeOfService.UpdateAllowed, propertyPrivilegeOfService.DeleteAllowed); } else { propertyPrivilege = TypePropertyPrivilegeImpl.Create(null, null, null, null); } if (metaData.IsRelationMember(propertyName)) { relationPropertyPrivileges[metaData.GetIndexByRelationName(propertyName)] = propertyPrivilege; } if (metaData.IsPrimitiveMember(propertyName)) { primitivePropertyPrivileges[metaData.GetIndexByPrimitiveName(propertyName)] = propertyPrivilege; } } return(EntityTypePrivilegeFactoryProvider.GetEntityTypePrivilegeFactory(metaData.EntityType, privilegeOfService.CreateAllowed, privilegeOfService.ReadAllowed, privilegeOfService.UpdateAllowed, privilegeOfService.DeleteAllowed, privilegeOfService.ExecuteAllowed).CreatePrivilege(privilegeOfService.CreateAllowed, privilegeOfService.ReadAllowed, privilegeOfService.UpdateAllowed, privilegeOfService.DeleteAllowed, privilegeOfService.ExecuteAllowed, primitivePropertyPrivileges, relationPropertyPrivileges)); }
protected void CallMethod(Object entity, String message) { try { Method.Invoke(entity, EMPTY_ARGS); } catch (Exception e) { Type entityType = EntityMetaDataProvider.GetMetaData(entity.GetType()).EntityType; throw RuntimeExceptionUtil.Mask(e, "Error occured while handling " + message + " method of entity type " + entityType.FullName); } }
public IPrefetchConfig Add(Type entityType, params String[] propertyPaths) { entityType = EntityMetaDataProvider.GetMetaData(entityType).EntityType; List <String> membersToInitialize = entityTypeToPrefetchPaths.Get(entityType); if (membersToInitialize == null) { membersToInitialize = new List <String>(); entityTypeToPrefetchPaths.Put(entityType, membersToInitialize); } membersToInitialize.AddRange(propertyPaths); return(this); }
protected void FetchMetaData() { IList <Type> types = new List <Type>(); foreach (Type type in rootElementClasses) { if (type.IsInterface || ImmutableTypeSet.IsImmutableType(type)) { continue; } types.Add(type); } EntityMetaDataProvider.GetMetaData(types); }
public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors, IList <IBytecodeBehavior> cascadePendingBehaviors) { Type entityType = EntityUtil.GetEntityType(state.Context); if (entityType == null) { return(visitor); } IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(entityType); String memberPath = EmbeddedEnhancementHint.GetMemberPath(state.Context); visitor = new InitializeEmbeddedMemberVisitor(visitor, metaData, memberPath, PropertyInfoProvider); return(visitor); }
protected void InternStrings(IList <ILoadContainer> loadContainers) { if (InterningFeature == null) { // Feature is optional return; } for (int a = loadContainers.Count; a-- > 0;) { ILoadContainer loadContainer = loadContainers[a]; IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(loadContainer.Reference.RealType); Object[] primitives = loadContainer.Primitives; InternPrimitiveMember(metaData, primitives, metaData.CreatedByMember); InternPrimitiveMember(metaData, primitives, metaData.UpdatedByMember); } }
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 override void Initialize() { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(typeof(Material)); LoadContainer lc = new LoadContainer(); lc.Reference = new ObjRef(typeof(Material), 1, 1); lc.Primitives = new Object[metaData.PrimitiveMembers.Length]; lc.Relations = new IObjRef[metaData.RelationMembers.Length][]; lc.Primitives[metaData.GetIndexByPrimitiveName("Buid")] = "Material 1"; lc.Primitives[metaData.GetIndexByPrimitiveName("Name")] = "Material 1"; databaseMap.Put(lc.Reference, lc); IEntityMetaData metaData2 = EntityMetaDataProvider.GetMetaData(typeof(MaterialGroup)); LoadContainer lc2 = new LoadContainer(); lc2.Reference = new ObjRef(typeof(MaterialGroup), "1", 1); lc2.Primitives = new Object[metaData2.PrimitiveMembers.Length]; lc2.Relations = new IObjRef[metaData2.RelationMembers.Length][]; lc2.Primitives[metaData2.GetIndexByPrimitiveName("Buid")] = "MaterialGroup 1"; lc2.Primitives[metaData2.GetIndexByPrimitiveName("Name")] = "MaterialGroup 1"; databaseMap.Put(lc2.Reference, lc2); lc.Relations[metaData.GetIndexByRelationName("MaterialGroup")] = new IObjRef[] { lc2.Reference }; IEntityMetaData metaData3 = EntityMetaDataProvider.GetMetaData(typeof(EntityA)); LoadContainer lc3 = new LoadContainer(); lc3.Reference = new ObjRef(typeof(EntityA), 1, 1); lc3.Primitives = new Object[metaData3.PrimitiveMembers.Length]; lc3.Relations = new IObjRef[metaData3.RelationMembers.Length][]; databaseMap.Put(lc3.Reference, lc3); IEntityMetaData metaData4 = EntityMetaDataProvider.GetMetaData(typeof(EntityB)); LoadContainer lc4 = new LoadContainer(); lc4.Reference = new ObjRef(typeof(EntityB), 1, 1); lc4.Primitives = new Object[metaData4.PrimitiveMembers.Length]; lc4.Relations = new IObjRef[metaData4.RelationMembers.Length][]; lc4.Relations[metaData4.GetIndexByRelationName("EntityA")] = new IObjRef[] { lc3.Reference }; databaseMap.Put(lc4.Reference, lc4); lc3.Relations[metaData3.GetIndexByRelationName("EntityBs")] = new IObjRef[] { lc4.Reference }; }
public void AfterStarted() { if (configsToConsume == null) { return; } foreach (Entry <Type, IList <XElement> > entry in configsToConsume) { Type entityType = entry.Key; IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(entityType, true); if (metaData == null) { if (Log.InfoEnabled) { Log.Info("Could not resolve entity meta data for '" + entityType.Name + "'"); } } } }
protected virtual void EnsureMetaDataIsLoaded(ISet <Type> occuringTypes, ISet <Type> directRelatingTypes) { ISet <Type> wholeRelatedTypes = new HashSet <Type>(occuringTypes); List <Type> additionalTypes = new List <Type>(); { // Own code scope IList <IEntityMetaData> occuringMetaData = EntityMetaDataProvider.GetMetaData(ListUtil.ToList(occuringTypes)); foreach (IEntityMetaData metaData in occuringMetaData) { Type[] typesRelatingToThis = metaData.TypesRelatingToThis; for (int a = typesRelatingToThis.Length; a-- > 0;) { Type type = typesRelatingToThis[a]; directRelatingTypes.Add(type); if (wholeRelatedTypes.Add(type)) { // Additional related type in this whole datachange additionalTypes.Add(type); } } } } while (additionalTypes.Count > 0) { IList <IEntityMetaData> additionalMetaData = EntityMetaDataProvider.GetMetaData(additionalTypes); additionalTypes.Clear(); foreach (IEntityMetaData metaData in additionalMetaData) { Type[] typesRelatingToThis = metaData.TypesRelatingToThis; for (int a = typesRelatingToThis.Length; a-- > 0;) { Type type = typesRelatingToThis[a]; if (wholeRelatedTypes.Add(type)) { // Additional related type in this whole datachange additionalTypes.Add(type); } } } } }
public void HandleEvent(Object eventObject, DateTime dispatchTime, long sequenceId) { if (!(eventObject is EntityMetaDataAddedEvent)) { return; } if (configsToConsume == null) { return; } foreach (Type entityType in ((EntityMetaDataAddedEvent)eventObject).EntityTypes) { IList <XElement> configs = configsToConsume.Get(entityType); if (configs == null) { continue; } IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(entityType); ConsumeConfigs(metaData, configs); } }
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); }
protected IDictionary <Type, IList <IObjRelation> > BucketSortObjRels(IList <IObjRelation> orisToLoad) { IDictionary <Type, IList <IObjRelation> > sortedIObjRefs = new Dictionary <Type, IList <IObjRelation> >(); for (int i = orisToLoad.Count; i-- > 0;) { IObjRelation orelToLoad = orisToLoad[i]; Type typeOfContainerBO = orelToLoad.RealType; IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(typeOfContainerBO); Member relationMember = metaData.GetMemberByName(orelToLoad.MemberName); Type type = relationMember.ElementType; IList <IObjRelation> objRefs = DictionaryExtension.ValueOrDefault(sortedIObjRefs, type); if (objRefs == null) { objRefs = new List <IObjRelation>(); sortedIObjRefs.Add(type, objRefs); } objRefs.Add(orelToLoad); } return(sortedIObjRefs); }
protected IPrivilege CreatePrivilegeFromServiceResult(IObjRef objRef, IPrivilegeOfService privilegeOfService) { IPropertyPrivilegeOfService[] propertyPrivilegesOfService = privilegeOfService.PropertyPrivileges; if (propertyPrivilegesOfService == null || propertyPrivilegesOfService.Length == 0) { return(SimplePrivilegeImpl.CreateFrom(privilegeOfService)); } String[] propertyPrivilegeNames = privilegeOfService.PropertyPrivilegeNames; IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(objRef.RealType); IPropertyPrivilege[] primitivePropertyPrivileges = new IPropertyPrivilege[metaData.PrimitiveMembers.Length]; IPropertyPrivilege[] relationPropertyPrivileges = new IPropertyPrivilege[metaData.RelationMembers.Length]; IPropertyPrivilege defaultPropertyPrivilege = PropertyPrivilegeImpl.CreateFrom(privilegeOfService); Arrays.Fill(primitivePropertyPrivileges, defaultPropertyPrivilege); Arrays.Fill(relationPropertyPrivileges, defaultPropertyPrivilege); for (int b = propertyPrivilegesOfService.Length; b-- > 0;) { IPropertyPrivilegeOfService propertyPrivilegeOfService = propertyPrivilegesOfService[b]; String propertyName = InterningFeature.Intern(propertyPrivilegeNames[b]); IPropertyPrivilege propertyPrivilege = PropertyPrivilegeImpl.Create(propertyPrivilegeOfService.CreateAllowed, propertyPrivilegeOfService.ReadAllowed, propertyPrivilegeOfService.UpdateAllowed, propertyPrivilegeOfService.DeleteAllowed); if (metaData.IsRelationMember(propertyName)) { relationPropertyPrivileges[metaData.GetIndexByRelationName(propertyName)] = propertyPrivilege; } if (metaData.IsPrimitiveMember(propertyName)) { primitivePropertyPrivileges[metaData.GetIndexByPrimitiveName(propertyName)] = propertyPrivilege; } } return(EntityPrivilegeFactoryProvider.GetEntityPrivilegeFactory(metaData.EntityType, privilegeOfService.CreateAllowed, privilegeOfService.ReadAllowed, privilegeOfService.UpdateAllowed, privilegeOfService.DeleteAllowed, privilegeOfService.ExecuteAllowed).CreatePrivilege(privilegeOfService.CreateAllowed, privilegeOfService.ReadAllowed, privilegeOfService.UpdateAllowed, privilegeOfService.DeleteAllowed, privilegeOfService.ExecuteAllowed, primitivePropertyPrivileges, relationPropertyPrivileges)); }
protected IList <Object> CreateResult(IList <IObjRef> orisToGet, CacheDirective cacheDirective, bool checkVersion) { List <Object> result = new List <Object>(orisToGet.Count); bool returnMisses = cacheDirective.HasFlag(CacheDirective.ReturnMisses); for (int a = 0, size = orisToGet.Count; a < size; a++) { IObjRef oriToGet = orisToGet[a]; if (oriToGet == null) { if (returnMisses) { result.Add(null); } continue; } if (oriToGet is IDirectObjRef) { IDirectObjRef dori = (IDirectObjRef)oriToGet; Object entity = dori.Direct; if (entity != null) { result.Add(entity); continue; } } IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(oriToGet.RealType); Object cacheValue = GetCacheValue(metaData, oriToGet, checkVersion); if (cacheValue != null || returnMisses) { result.Add(cacheValue); } } return(result); }
public override Object CreateEntity(Type entityType) { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(entityType); return(CreateEntityIntern(metaData, true)); }
public void RemoveObject(IObjRef objRef) { writeLock.Lock(); try { ILoadContainer deletedContainer = refToObjectDict[objRef]; refToObjectDict.Remove(objRef); Type deletedType = objRef.RealType; IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(deletedType); if (metaData.TypesRelatingToThis.Length == 0) { return; } ISet <Type> typesRelatingToThis = new HashSet <Type>(metaData.TypesRelatingToThis); DictionaryExtension.Loop(refToObjectDict, delegate(IObjRef key, ILoadContainer value) { if (!typesRelatingToThis.Contains(key.RealType)) { // This object does not refer to instances of deleted type } IEntityMetaData typeRelatingMetaData = EntityMetaDataProvider.GetMetaData(key.RealType); RelationMember[] relationMembers = typeRelatingMetaData.RelationMembers; for (int a = relationMembers.Length; a-- > 0;) { RelationMember relationMember = relationMembers[a]; if (!deletedType.Equals(relationMember.ElementType)) { continue; } IObjRef[] relationsOfMember = value.Relations[a]; if (relationsOfMember.Length == 0) { continue; } bool contains = false; for (int b = relationsOfMember.Length; b-- > 0;) { IObjRef relationOfMember = relationsOfMember[b]; if (objRef.Equals(relationOfMember)) { contains = true; break; } } if (!contains) { continue; } if (relationsOfMember.Length == 1) { value.Relations[a] = ObjRef.EMPTY_ARRAY; continue; } List <IObjRef> newRelationsOfMember = new List <IObjRef>(); for (int b = relationsOfMember.Length; b-- > 0;) { IObjRef relationOfMember = relationsOfMember[b]; if (!objRef.Equals(relationOfMember)) { newRelationsOfMember.Add(relationOfMember); } } value.Relations[a] = newRelationsOfMember.ToArray(); } }); } finally { writeLock.Unlock(); } }
public Object Plan(Type entityType) { return(PlanIntern(entityType, null, EntityMetaDataProvider.GetMetaData(entityType))); }
public void ChangeObject(IObjRef objRef, IPrimitiveUpdateItem[] primitiveUpdates, IRelationUpdateItem[] relationUpdates, String changedBy, long changedOn) { writeLock.Lock(); try { ILoadContainer loadContainer = refToObjectDict[objRef]; IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(objRef.RealType); Object[] primitives = loadContainer.Primitives; if (loadContainer.Reference.Version == null) { if (metaData.CreatedByMember != null) { primitives[GetPrimitiveMemberIndex(metaData, metaData.CreatedByMember.Name)] = changedBy; } if (metaData.CreatedOnMember != null) { primitives[GetPrimitiveMemberIndex(metaData, metaData.CreatedOnMember.Name)] = changedOn; } } else { if (metaData.UpdatedByMember != null) { primitives[GetPrimitiveMemberIndex(metaData, metaData.UpdatedByMember.Name)] = changedBy; } if (metaData.UpdatedOnMember != null) { primitives[GetPrimitiveMemberIndex(metaData, metaData.UpdatedOnMember.Name)] = changedOn; } } loadContainer.Reference.Version = objRef.Version; if (primitiveUpdates != null) { PrimitiveMember[] primitiveMembers = metaData.PrimitiveMembers; for (int a = primitiveUpdates.Length; a-- > 0;) { IPrimitiveUpdateItem pui = primitiveUpdates[a]; Member member = metaData.GetMemberByName(pui.MemberName); for (int b = primitiveMembers.Length; b-- > 0;) { if (primitiveMembers[b] == member) { primitives[b] = pui.NewValue; break; } } } } if (relationUpdates != null) { IObjRef[][] relations = loadContainer.Relations; for (int a = relationUpdates.Length; a-- > 0;) { IRelationUpdateItem rui = relationUpdates[a]; int memberIndex = metaData.GetIndexByRelationName(rui.MemberName); IObjRef[] relation = relations[memberIndex]; List <IObjRef> newRelation = new List <IObjRef>(); if (relation != null) { for (int b = relation.Length; b-- > 0;) { newRelation.Add(relation[b]); } } if (rui.RemovedORIs != null) { for (int b = rui.RemovedORIs.Length; b-- > 0;) { newRelation.Remove(rui.RemovedORIs[b]); } } if (rui.AddedORIs != null) { for (int b = rui.AddedORIs.Length; b-- > 0;) { newRelation.Add(rui.AddedORIs[b]); } } if (newRelation.Count == 0) { relations[a] = ObjRef.EMPTY_ARRAY; } else { relations[memberIndex] = newRelation.ToArray(); } } } } finally { writeLock.Unlock(); } }