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); } }
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); }
protected override ITransientMap DoAssoc(object key, object val) { int i = IndexOf(key); if (i >= 0) { if (this._array[i + 1] != val) { this._array[i + 1] = val; } } else { if (this._length >= this._array.Length) { return(((ITransientMap)HashMap.Create(this._array).ToTransient()).Assoc(key, val)); } this._array[this._length++] = key; this._array[this._length++] = val; } return(this); }
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); }
protected PropertyInfoEntry GetPropertyEntry(Type type, SmartCopyMap <Type, PropertyInfoEntry> map, bool isOldIocMode, bool isIocMode) { ParamChecker.AssertParamNotNull(type, "type"); PropertyInfoEntry propertyEntry = map.Get(type); if (propertyEntry != null) { return(propertyEntry); } Object writeLock = map.GetWriteLock(); lock (writeLock) { propertyEntry = map.Get(type); if (propertyEntry != null) { // Concurrent thread might have been faster return(propertyEntry); } HashMap <String, HashMap <Type, HashMap <String, MethodInfo> > > sortedMethods = new HashMap <String, HashMap <Type, HashMap <String, MethodInfo> > >(); MethodInfo[] methods = ReflectUtil.GetDeclaredMethodsInHierarchy(type); foreach (MethodInfo method in methods) { if (method.DeclaringType.Equals(typeof(Object))) { continue; } if (method.IsStatic) { continue; } try { String propName = GetPropertyNameFor(method); if (propName.Length == 0) { continue; } HashMap <Type, HashMap <String, MethodInfo> > sortedMethod = sortedMethods.Get(propName); if (sortedMethod == null) { sortedMethod = HashMap <Type, HashMap <String, MethodInfo> > .Create(1); sortedMethods.Put(propName, sortedMethod); } ParameterInfo[] parameterInfos = method.GetParameters(); Type propertyType; String prefix; if (parameterInfos.Length == 1) { propertyType = parameterInfos[0].ParameterType; prefix = "set"; } else if (parameterInfos.Length == 0) { propertyType = method.ReturnType; prefix = "get"; } else { throw new Exception("Method is not an accessor: " + method); } HashMap <String, MethodInfo> methodPerType = sortedMethod.Get(propertyType); if (methodPerType == null) { methodPerType = HashMap <String, MethodInfo> .Create(2); sortedMethod.Put(propertyType, methodPerType); } methodPerType.Put(prefix, method); } catch (Exception e) { throw RuntimeExceptionUtil.Mask(e, "Error occured while processing " + method); } } HashMap <String, HashMap <String, MethodInfo> > filteredMethods = FilterOverriddenMethods(sortedMethods, type); HashMap <String, IPropertyInfo> propertyMap = new HashMap <String, IPropertyInfo>(0.5f); foreach (MapEntry <String, HashMap <String, MethodInfo> > propertyData in filteredMethods) { String propertyName = propertyData.Key; HashMap <String, MethodInfo> propertyMethods = propertyData.Value; MethodInfo getter = propertyMethods.Get("get"); MethodInfo setter = propertyMethods.Get("set"); if (isIocMode) { if (setter == null || (!setter.IsPublic && !AnnotationUtil.IsAnnotationPresent <AutowiredAttribute>(setter, false) && !AnnotationUtil.IsAnnotationPresent <PropertyAttribute>(setter, false))) { continue; } } MethodPropertyInfo propertyInfo = new MethodPropertyInfo(type, propertyName, getter, setter); propertyMap.Put(propertyInfo.Name, propertyInfo); } Type[] interfaces = type.GetInterfaces(); List <Type> typesToSearch = new List <Type>(interfaces); typesToSearch.Add(type); foreach (Type typeToSearch in typesToSearch) { PropertyInfo[] properties = typeToSearch.GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo property in properties) { if (property.GetGetMethod() != null && property.GetGetMethod().GetParameters().Length != 0) { continue; } if (property.GetSetMethod() != null && property.GetSetMethod().GetParameters().Length != 1) { continue; } MethodInfo getter = null; MethodInfo setter = null; MethodPropertyInfo propertyInfo = (MethodPropertyInfo)propertyMap.Get(property.Name); if (propertyInfo != null) { getter = propertyInfo.Getter; setter = propertyInfo.Setter; } if (getter == null) { getter = property.GetGetMethod(); } if (setter == null) { setter = property.GetSetMethod(); } if (isIocMode && setter == null) { continue; } propertyInfo = new MethodPropertyInfo(type, property.Name, getter, setter); propertyInfo.PutAnnotations(property); propertyMap.Put(propertyInfo.Name, propertyInfo); } } FieldInfo[] fields = ReflectUtil.GetDeclaredFieldsInHierarchy(type); foreach (FieldInfo field in fields) { if (field.IsStatic) { continue; } if (isOldIocMode) { if (!AnnotationUtil.IsAnnotationPresent <AutowiredAttribute>(field, false) && !AnnotationUtil.IsAnnotationPresent <PropertyAttribute>(field, false)) { continue; } } String propertyName = GetPropertyNameFor(field); IPropertyInfo existingProperty = propertyMap.Get(propertyName); if (existingProperty != null && existingProperty.IsWritable) { // Ignore field injection if the already resolved (method-)property is writable continue; } IPropertyInfo propertyInfo = new FieldPropertyInfo(type, propertyName, field); propertyMap.Put(propertyInfo.Name, propertyInfo); } propertyEntry = new PropertyInfoEntry(propertyMap); map.Put(type, propertyEntry); return(propertyEntry); } }
protected HashMap <String, HashMap <String, MethodInfo> > FilterOverriddenMethods(HashMap <String, HashMap <Type, HashMap <String, MethodInfo> > > sortedMethods, Type entityType) { HashMap <String, HashMap <String, MethodInfo> > filteredMethods = HashMap <String, HashMap <String, MethodInfo> > .Create(sortedMethods.Count); foreach (MapEntry <String, HashMap <Type, HashMap <String, MethodInfo> > > entry in sortedMethods) { String propName = entry.Key; HashMap <Type, HashMap <String, MethodInfo> > typedHashMap = entry.Value; if (typedHashMap.Count == 1) { IEnumerator <HashMap <String, MethodInfo> > iter = typedHashMap.Values().GetEnumerator(); iter.MoveNext(); HashMap <String, MethodInfo> accessorMap = iter.Current; filteredMethods.Put(propName, accessorMap); continue; } Type mostConcreteType = null; Type mostConcreteGetterType = null; Type mostConcreteSetterType = null; foreach (Entry <Type, HashMap <String, MethodInfo> > typedEntries in typedHashMap) { Type currentType = typedEntries.Key; HashMap <String, MethodInfo> accessorMap = typedEntries.Value; if (accessorMap.Count != 2) { if (accessorMap.Get("get") != null) { if (mostConcreteGetterType == null || mostConcreteGetterType.IsAssignableFrom(currentType)) { mostConcreteGetterType = currentType; } } else { if (mostConcreteSetterType == null || mostConcreteSetterType.IsAssignableFrom(currentType)) { mostConcreteSetterType = currentType; } } continue; } if (mostConcreteType == null || mostConcreteType.IsAssignableFrom(currentType)) { mostConcreteType = currentType; } } if (mostConcreteType != null) { HashMap <String, MethodInfo> accessorMap = typedHashMap.Get(mostConcreteType); filteredMethods.Put(propName, accessorMap); } else if (mostConcreteGetterType != null) { HashMap <String, MethodInfo> accessorMap = typedHashMap.Get(mostConcreteGetterType); filteredMethods.Put(propName, accessorMap); } else if (mostConcreteSetterType != null) { HashMap <String, MethodInfo> accessorMap = typedHashMap.Get(mostConcreteSetterType); filteredMethods.Put(propName, accessorMap); } } return(filteredMethods); }