Mercurial > pub > bltoolkit
comparison Source/Mapping/MapResultSet.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 using System; | |
2 using System.Collections; | |
3 using System.Collections.Generic; | |
4 | |
5 namespace BLToolkit.Mapping | |
6 { | |
7 public class MapResultSet | |
8 { | |
9 public MapResultSet(Type objectType) | |
10 { | |
11 _objectType = objectType; | |
12 } | |
13 | |
14 public MapResultSet(Type objectType, IList list) | |
15 { | |
16 _objectType = objectType; | |
17 _list = list; | |
18 } | |
19 | |
20 public MapResultSet(Type objectType, object[] parameters) | |
21 { | |
22 _objectType = objectType; | |
23 _parameters = parameters; | |
24 } | |
25 | |
26 public MapResultSet(Type objectType, IList list, object[] parameters) | |
27 { | |
28 _objectType = objectType; | |
29 _parameters = parameters; | |
30 _list = list; | |
31 } | |
32 | |
33 internal MapResultSet(MapResultSet resultSet) | |
34 { | |
35 _objectType = resultSet._objectType; | |
36 _parameters = resultSet._parameters; | |
37 | |
38 if (resultSet._relationList != null) | |
39 { | |
40 _relationList = new List<MapRelation>(resultSet._relationList.Count); | |
41 _relationList.AddRange(resultSet._relationList); | |
42 } | |
43 } | |
44 | |
45 private readonly Type _objectType; | |
46 internal Type ObjectType | |
47 { | |
48 get { return _objectType; } | |
49 } | |
50 | |
51 private object[] _parameters; | |
52 public object[] Parameters | |
53 { | |
54 get { return _parameters; } | |
55 set { _parameters = value; } | |
56 } | |
57 | |
58 private IList _list; | |
59 public IList List | |
60 { | |
61 get { return _list ?? (_list = new List<object>()); } | |
62 set { _list = value; } | |
63 } | |
64 | |
65 private MapRelation[] _relations; | |
66 internal MapRelation[] Relations | |
67 { | |
68 get | |
69 { | |
70 if (_relationList != null && (_relations == null || _relations.Length != _relationList.Count)) | |
71 _relations = _relationList.ToArray(); | |
72 | |
73 return _relations; | |
74 } | |
75 | |
76 set { _relations = value; } | |
77 } | |
78 | |
79 private List<MapRelation> _relationList; | |
80 | |
81 public void AddRelation( | |
82 MapResultSet slaveResultSet, | |
83 MapIndex slaveIndex, | |
84 MapIndex masterIndex, | |
85 string containerName) | |
86 { | |
87 if (_relationList == null) | |
88 _relationList = new List<MapRelation>(); | |
89 | |
90 _relationList.Add(new MapRelation(slaveResultSet, slaveIndex, masterIndex, containerName)); | |
91 } | |
92 | |
93 public void AddRelation( | |
94 MapResultSet slaveResultSet, | |
95 string slaveIndex, | |
96 string masterIndex, | |
97 string containerName) | |
98 { | |
99 AddRelation( slaveResultSet, new MapIndex(slaveIndex), new MapIndex(masterIndex),containerName); | |
100 } | |
101 | |
102 public void AddRelation(MapResultSet slaveResultSet, MapRelationBase relation) | |
103 { | |
104 AddRelation(slaveResultSet, relation.SlaveIndex, relation.MasterIndex, relation.ContainerName); | |
105 } | |
106 | |
107 readonly Dictionary<string,IDictionary<object,IList>> _indexies = new Dictionary<string,IDictionary<object,IList>>(); | |
108 | |
109 public IDictionary<object,IList> GetIndex(MappingSchema ms, MapIndex masterIndex) | |
110 { | |
111 var indexId = masterIndex.ID; | |
112 | |
113 IDictionary<object,IList> indexHash; | |
114 | |
115 if (_indexies.TryGetValue(indexId, out indexHash)) | |
116 return indexHash; | |
117 | |
118 var masterMapper = ms.GetObjectMapper(ObjectType); | |
119 | |
120 indexHash = new Dictionary<object, IList>(); | |
121 | |
122 foreach (var o in List) | |
123 { | |
124 var key = masterIndex.GetValueOrIndex(masterMapper, o); | |
125 | |
126 if (ms.IsNull(key)) | |
127 continue; | |
128 | |
129 IList matches; | |
130 | |
131 if (!indexHash.TryGetValue(key, out matches)) | |
132 indexHash.Add(key, matches = new List<object>()); | |
133 | |
134 matches.Add(o); | |
135 } | |
136 | |
137 return indexHash; | |
138 } | |
139 | |
140 public IDictionary<object,IList> GetIndex(MappingSchema ms, MapRelation relation) | |
141 { | |
142 return GetIndex(ms, relation.MasterIndex); | |
143 } | |
144 } | |
145 } | |
146 |