Datei: NDODLL/_NDOContainerStack.cs
Last Commit (e2d950d)
| 1 | // |
| 2 | // Copyright (c) 2002-2016 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | #pragma warning disable 1591 // No XML comments needed |
| 23 | |
| 24 | using System; |
| 25 | using System.Threading; |
| 26 | using System.Collections; |
| 27 | |
| 28 | namespace NDO |
| 29 | { |
| 30 | ····/// <summary> |
| 31 | ····/// Don't even think about using this class... |
| 32 | ····/// We included it in the docs to explicitly tell you, that it is verboten to use it. |
| 33 | ····/// If you call any of the functions of this class, an immediate disfunction of the |
| 34 | ····/// NDO framework will occur. |
| 35 | ····/// </summary> |
| 36 | ····//[CLSCompliant(false)] |
| 37 | ····public class _NDOContainerStack |
| 38 | ····{ |
| 39 | ········private class Triple |
| 40 | ········{ |
| 41 | ············public Triple(object p, string f) |
| 42 | ············{ |
| 43 | ················this.parent = p; |
| 44 | ················this.field = f; |
| 45 | ············} |
| 46 | ············object parent; |
| 47 | ············public object Parent |
| 48 | ············{ |
| 49 | get { return parent; } |
| 50 | set { parent = value; } |
| 51 | ············} |
| 52 | ············string field; |
| 53 | ············public string Field |
| 54 | ············{ |
| 55 | get { return field; } |
| 56 | set { field = value; } |
| 57 | ············} |
| 58 | |
| 59 | ········} |
| 60 | |
| 61 | |
| 62 | ········/// <summary> |
| 63 | ········/// Registers a child object |
| 64 | ········/// </summary> |
| 65 | ········/// <param name="parent"></param> |
| 66 | ········/// <param name="container"></param> |
| 67 | ········/// <param name="table"></param> |
| 68 | ········/// <param name="field"></param> |
| 69 | ········/// <returns></returns> |
| 70 | ········public static object RegisterContainer (object parent, object container, Hashtable table, string field) |
| 71 | ········{ |
| 72 | ············IPersistenceCapable pc = parent as IPersistenceCapable; |
| 73 | ············if (pc == null) |
| 74 | ················goto exit; |
| 75 | |
| 76 | ············if (pc.NDOStateManager == null || pc.NDOObjectState == NDOObjectState.Transient) |
| 77 | ················goto exit; |
| 78 | |
| 79 | ············if (pc.NDOObjectState != NDOObjectState.Created) |
| 80 | ············{ |
| 81 | ················IList result = pc.NDOStateManager.LoadRelation(pc, field); |
| 82 | ················if (result != null) |
| 83 | ····················container = result; |
| 84 | ············} |
| 85 | |
| 86 | ············if (container == null) |
| 87 | ················goto exit; |
| 88 | |
| 89 | ············if (!table.Contains(container)) |
| 90 | ················table.Add(container, new Triple(parent, field)); |
| 91 | exit: |
| 92 | ············return container; |
| 93 | ········} |
| 94 | |
| 95 | ········public static void AddRange(object container, IEnumerable coll, Hashtable table) |
| 96 | ········{ |
| 97 | ············if (container == null) |
| 98 | ············{ |
| 99 | ················throw new NDOException(1, "AddRange: container is null"); |
| 100 | ············} |
| 101 | |
| 102 | ············Triple t = (Triple) table[container]; |
| 103 | ············if (t == null) |
| 104 | ················goto exit; |
| 105 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 106 | ············if (parent == null) |
| 107 | ················goto exit; |
| 108 | |
| 109 | ············string field = t.Field; |
| 110 | |
| 111 | ············IStateManager stateManager; |
| 112 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 113 | ················goto exit; |
| 114 | |
| 115 | ············if (coll == null) |
| 116 | ················goto exit; |
| 117 | |
| 118 | ············foreach(IPersistenceCapable pc in coll) |
| 119 | ················stateManager.AddRelatedObject(parent, field, pc); |
| 120 | |
| 121 | ············exit: |
| 122 | ················foreach(object o in coll) |
| 123 | ················((IList)container).Add(o); |
| 124 | ········} |
| 125 | |
| 126 | ········public static void InsertRange(object container, int index, IEnumerable coll, Hashtable table) |
| 127 | ········{ |
| 128 | ············if (container == null) |
| 129 | ············{ |
| 130 | ················throw new NDOException(2, "InsertRange: container is null"); |
| 131 | ············} |
| 132 | ············Triple t = (Triple) table[container]; |
| 133 | ············if (t == null) |
| 134 | ················goto exit; |
| 135 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 136 | ············if (parent == null) |
| 137 | ················goto exit; |
| 138 | |
| 139 | ············string field = t.Field; |
| 140 | |
| 141 | ············IStateManager stateManager; |
| 142 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 143 | ················goto exit; |
| 144 | |
| 145 | ············if (coll == null) |
| 146 | ················goto exit; |
| 147 | |
| 148 | ············foreach(IPersistenceCapable pc in coll) |
| 149 | ················stateManager.AddRelatedObject(parent, field, pc); |
| 150 | |
| 151 | ········exit: |
| 152 | ············ArrayList temp = new ArrayList(); |
| 153 | ············foreach (object o in coll) |
| 154 | ················temp.Add(o); |
| 155 | ············for (int i = temp.Count - 1; i >= 0; i--) |
| 156 | ················((IList)container).Insert(index, temp[i]); |
| 157 | ········} |
| 158 | |
| 159 | ········public static int RemoveAll(object container, Delegate pred, Hashtable table) |
| 160 | ········{ |
| 161 | ············if (container == null) |
| 162 | ················throw new NDOException(3, "RemoveAll: container is null"); |
| 163 | |
| 164 | ············if (pred == null) |
| 165 | ················return 0; |
| 166 | |
| 167 | ············bool validRelation = false; |
| 168 | ············IPersistenceCapable parent = null; |
| 169 | ············string field = null; |
| 170 | ············IStateManager stateManager = null; |
| 171 | |
| 172 | ············Triple t = (Triple) table[container]; |
| 173 | ············if (t == null) |
| 174 | ················goto exit; |
| 175 | ············parent = t.Parent as IPersistenceCapable; |
| 176 | ············if (parent == null) |
| 177 | ················goto exit; |
| 178 | |
| 179 | ············field = t.Field; |
| 180 | |
| 181 | ············stateManager = parent.NDOStateManager; |
| 182 | ············if (stateManager == null) |
| 183 | ················goto exit; |
| 184 | |
| 185 | ············validRelation = true; |
| 186 | |
| 187 | ············exit: |
| 188 | ············IList ilist = (IList) container; |
| 189 | ············ArrayList toDelete = new ArrayList(); |
| 190 | ············foreach(object relObj in ilist) |
| 191 | ············{ |
| 192 | ················if((bool) pred.DynamicInvoke(new object[]{relObj})) |
| 193 | ················{ |
| 194 | ····················toDelete.Add(relObj); |
| 195 | ····················if (validRelation) |
| 196 | ························stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable) relObj); |
| 197 | ················} |
| 198 | ············} |
| 199 | ············foreach(object o in toDelete) |
| 200 | ················ilist.Remove(o); |
| 201 | |
| 202 | ············return toDelete.Count; |
| 203 | ········} |
| 204 | |
| 205 | |
| 206 | ········public static void SetRange(object container, int index, ICollection coll, Hashtable table) |
| 207 | ········{ |
| 208 | ············if (container == null) |
| 209 | ············{ |
| 210 | ····················throw new NDOException(3, "SetRange: container is null"); |
| 211 | ············} |
| 212 | ············Triple t = (Triple) table[container]; |
| 213 | ············if (t == null) |
| 214 | ················goto exit; |
| 215 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 216 | ············if (parent == null) |
| 217 | ················goto exit; |
| 218 | |
| 219 | ············string field = t.Field; |
| 220 | |
| 221 | ············IStateManager stateManager; |
| 222 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 223 | ················goto exit; |
| 224 | |
| 225 | ············if (coll == null) |
| 226 | ················goto exit; |
| 227 | |
| 228 | ············int lastIndex = index + coll.Count; |
| 229 | ············if (lastIndex > ((IList)container).Count) |
| 230 | ············{ |
| 231 | ················ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException(); |
| 232 | ················throw new ArgumentOutOfRangeException(string.Empty, "SetRange: " + ex.Message); |
| 233 | ············} |
| 234 | |
| 235 | ············for (int i = index; i < lastIndex; i++) |
| 236 | ················stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable)((IList)container)[i]); |
| 237 | ············foreach(IPersistenceCapable pc in coll) |
| 238 | ················stateManager.AddRelatedObject(parent, field, pc); |
| 239 | |
| 240 | ············exit: |
| 241 | ················((ArrayList)container).SetRange(index, coll); |
| 242 | ········} |
| 243 | |
| 244 | ········public static void RemoveRange(object container, int index, int count, Hashtable table) |
| 245 | ········{ |
| 246 | ············if (container == null) |
| 247 | ············{ |
| 248 | ················throw new NDOException(4, "RemoveRange: container is null"); |
| 249 | ············} |
| 250 | ············Triple t = (Triple) table[container]; |
| 251 | ············if (t == null) |
| 252 | ················goto exit; |
| 253 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 254 | ············if (parent == null) |
| 255 | ················goto exit; |
| 256 | |
| 257 | ············string field = t.Field; |
| 258 | |
| 259 | ············IStateManager stateManager; |
| 260 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 261 | ················goto exit; |
| 262 | |
| 263 | ············int lastIndex = index + count; |
| 264 | ············if (lastIndex > ((IList)container).Count) |
| 265 | ············{ |
| 266 | ················ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException(); |
| 267 | ················throw new ArgumentOutOfRangeException(string.Empty, "RemoveRange: " + ex.Message); |
| 268 | ············} |
| 269 | |
| 270 | ············for (int i = index; i < lastIndex; i++) |
| 271 | ················stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable)((IList)container)[i]); |
| 272 | |
| 273 | ········exit: |
| 274 | ············for (int i = 0; i < count; i++) |
| 275 | ················((IList)container).RemoveAt(index); |
| 276 | ········} |
| 277 | |
| 278 | |
| 279 | ········public static int Add(object container, object element, Hashtable table) |
| 280 | ········{ |
| 281 | ············if (container == null) |
| 282 | ············{ |
| 283 | ················if (element != null) |
| 284 | ····················throw new NDOException(5, "Adding related object of type " + element.GetType().FullName + ": container is null"); |
| 285 | ················else |
| 286 | ····················throw new NDOException(5, "Adding related object: container is null"); |
| 287 | ············} |
| 288 | ············Triple t = (Triple) table[container]; |
| 289 | ············if (t == null) |
| 290 | ················goto exit; |
| 291 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 292 | ············if (parent == null) |
| 293 | ················goto exit; |
| 294 | |
| 295 | ············string field = t.Field; |
| 296 | |
| 297 | ············IStateManager stateManager; |
| 298 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 299 | ················goto exit; |
| 300 | ············stateManager.AddRelatedObject(parent, field, (IPersistenceCapable) element); |
| 301 | |
| 302 | exit: |
| 303 | ············return ((IList)container).Add(element);············ |
| 304 | ········} |
| 305 | |
| 306 | ········public static void Insert(object container, int index, object element, Hashtable table) |
| 307 | ········{ |
| 308 | ············Triple t = (Triple) table[container]; |
| 309 | ············if (t == null) |
| 310 | ················goto exit; |
| 311 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 312 | ············if (parent == null) |
| 313 | ················goto exit; |
| 314 | |
| 315 | ············string field = t.Field; |
| 316 | |
| 317 | ············IStateManager stateManager; |
| 318 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 319 | ················goto exit; |
| 320 | ············stateManager.AddRelatedObject(parent, field, (IPersistenceCapable) element); |
| 321 | |
| 322 | ············exit: |
| 323 | ················((IList)container).Insert(index, (IPersistenceCapable) element);············ |
| 324 | ········} |
| 325 | |
| 326 | ········public static void SetItem(object container, int index, object element, Hashtable table) |
| 327 | ········{ |
| 328 | ············Triple t = (Triple) table[container]; |
| 329 | ············if (t == null) |
| 330 | ················goto exit; |
| 331 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 332 | ············if (parent == null) |
| 333 | ················goto exit; |
| 334 | |
| 335 | ············string field = t.Field; |
| 336 | |
| 337 | ············IStateManager stateManager; |
| 338 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 339 | ················goto exit; |
| 340 | ············object elToRemove = ((IList)container)[index]; |
| 341 | ············stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable) elToRemove); |
| 342 | ············stateManager.AddRelatedObject(parent, field, (IPersistenceCapable) element); |
| 343 | |
| 344 | ············exit: |
| 345 | ················((IList)container)[index] = element; |
| 346 | ········} |
| 347 | |
| 348 | |
| 349 | ········public static bool Remove(object container, object element, Hashtable table) |
| 350 | ········{ |
| 351 | ············Triple t = (Triple) table[container]; |
| 352 | ············if (t == null) |
| 353 | ················goto exit; |
| 354 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 355 | ············if (parent == null) |
| 356 | ················goto exit; |
| 357 | |
| 358 | ············string field = t.Field; |
| 359 | |
| 360 | ············IStateManager stateManager; |
| 361 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 362 | ················goto exit; |
| 363 | ············stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable) element); |
| 364 | |
| 365 | ········exit: |
| 366 | ············IList ilist = ((IList)container); |
| 367 | ············int ix = ilist.IndexOf(element); |
| 368 | ············if (ix < 0) |
| 369 | ················return false; |
| 370 | ············ilist.RemoveAt(ix); |
| 371 | ············return true; |
| 372 | ········} |
| 373 | |
| 374 | ········public static void RemoveAt(object container, int index, Hashtable table) |
| 375 | ········{ |
| 376 | ············Triple t = (Triple) table[container]; |
| 377 | ············if (t == null) |
| 378 | ················goto exit; |
| 379 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 380 | ············if (parent == null) |
| 381 | ················goto exit; |
| 382 | |
| 383 | ············string field = t.Field; |
| 384 | |
| 385 | ············IStateManager stateManager; |
| 386 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 387 | ················goto exit; |
| 388 | ············IPersistenceCapable element = (IPersistenceCapable)((IList)container)[index]; |
| 389 | ············stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable) element); |
| 390 | |
| 391 | ············exit: |
| 392 | ················((IList)container).RemoveAt(index);············ |
| 393 | ········} |
| 394 | |
| 395 | ········public static void Clear(object container, Hashtable table) |
| 396 | ········{ |
| 397 | ············Triple t = (Triple) table[container]; |
| 398 | ············if (t == null) |
| 399 | ················goto exit; |
| 400 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 401 | ············if (parent == null) |
| 402 | ················goto exit; |
| 403 | |
| 404 | ············string field = t.Field; |
| 405 | |
| 406 | ············IStateManager stateManager; |
| 407 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 408 | ················goto exit; |
| 409 | |
| 410 | ············stateManager.RemoveRangeRelatedObjects(parent, field, (IList) container); |
| 411 | |
| 412 | ············exit: |
| 413 | ················((IList)container).Clear();············ |
| 414 | ········} |
| 415 | ····} |
| 416 | } |
| 417 |
New Commit (6e13ce2)
| 1 | // |
| 2 | // Copyright (c) 2002-2016 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | #pragma warning disable 1591 // No XML comments needed |
| 23 | |
| 24 | using System; |
| 25 | using System.Threading; |
| 26 | using System.Collections; |
| 27 | |
| 28 | namespace NDO |
| 29 | { |
| 30 | ····/// <summary> |
| 31 | ····/// Don't even think about using this class... |
| 32 | ····/// We included it in the docs to explicitly tell you, that it is verboten to use it. |
| 33 | ····/// If you call any of the functions of this class, an immediate disfunction of the |
| 34 | ····/// NDO framework will occur. |
| 35 | ····/// </summary> |
| 36 | ····//[CLSCompliant(false)] |
| 37 | ····public class _NDOContainerStack |
| 38 | ····{ |
| 39 | ········private class Triple |
| 40 | ········{ |
| 41 | ············public Triple(object p, string f) |
| 42 | ············{ |
| 43 | ················this.parent = p; |
| 44 | ················this.field = f; |
| 45 | ············} |
| 46 | ············object parent; |
| 47 | ············public object Parent |
| 48 | ············{ |
| 49 | get { return this. parent; } |
| 50 | set { this. parent = value; } |
| 51 | ············} |
| 52 | ············string field; |
| 53 | ············public string Field |
| 54 | ············{ |
| 55 | get { return this. field; } |
| 56 | set { this. field = value; } |
| 57 | ············} |
| 58 | |
| 59 | ········} |
| 60 | |
| 61 | |
| 62 | ········/// <summary> |
| 63 | ········/// Registers a child object |
| 64 | ········/// </summary> |
| 65 | ········/// <param name="parent"></param> |
| 66 | ········/// <param name="container"></param> |
| 67 | ········/// <param name="table"></param> |
| 68 | ········/// <param name="field"></param> |
| 69 | ········/// <returns></returns> |
| 70 | ········public static object RegisterContainer (object parent, object container, Hashtable table, string field) |
| 71 | ········{ |
| 72 | ············IPersistenceCapable pc = parent as IPersistenceCapable; |
| 73 | ············if (pc == null) |
| 74 | ················goto exit; |
| 75 | |
| 76 | ············if (pc.NDOStateManager == null || pc.NDOObjectState == NDOObjectState.Transient) |
| 77 | ················goto exit; |
| 78 | |
| 79 | ············if (pc.NDOObjectState != NDOObjectState.Created) |
| 80 | ············{ |
| 81 | ················IList result = pc.NDOStateManager.LoadRelation(pc, field); |
| 82 | ················if (result != null) |
| 83 | ····················container = result; |
| 84 | ············} |
| 85 | |
| 86 | ············if (container == null) |
| 87 | ················goto exit; |
| 88 | |
| 89 | ············if (!table.Contains(container)) |
| 90 | ················table.Add(container, new Triple(parent, field)); |
| 91 | exit: |
| 92 | ············return container; |
| 93 | ········} |
| 94 | |
| 95 | ········public static void AddRange(object container, IEnumerable coll, Hashtable table) |
| 96 | ········{ |
| 97 | ············if (container == null) |
| 98 | ············{ |
| 99 | ················throw new NDOException(1, "AddRange: container is null"); |
| 100 | ············} |
| 101 | |
| 102 | ············Triple t = (Triple) table[container]; |
| 103 | ············if (t == null) |
| 104 | ················goto exit; |
| 105 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 106 | ············if (parent == null) |
| 107 | ················goto exit; |
| 108 | |
| 109 | ············string field = t.Field; |
| 110 | |
| 111 | ············IStateManager stateManager; |
| 112 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 113 | ················goto exit; |
| 114 | |
| 115 | ············if (coll == null) |
| 116 | ················goto exit; |
| 117 | |
| 118 | ············foreach(IPersistenceCapable pc in coll) |
| 119 | ················stateManager.AddRelatedObject(parent, field, pc); |
| 120 | |
| 121 | ············exit: |
| 122 | ················foreach(object o in coll) |
| 123 | ················((IList)container).Add(o); |
| 124 | ········} |
| 125 | |
| 126 | ········public static void InsertRange(object container, int index, IEnumerable coll, Hashtable table) |
| 127 | ········{ |
| 128 | ············if (container == null) |
| 129 | ············{ |
| 130 | ················throw new NDOException(2, "InsertRange: container is null"); |
| 131 | ············} |
| 132 | ············Triple t = (Triple) table[container]; |
| 133 | ············if (t == null) |
| 134 | ················goto exit; |
| 135 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 136 | ············if (parent == null) |
| 137 | ················goto exit; |
| 138 | |
| 139 | ············string field = t.Field; |
| 140 | |
| 141 | ············IStateManager stateManager; |
| 142 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 143 | ················goto exit; |
| 144 | |
| 145 | ············if (coll == null) |
| 146 | ················goto exit; |
| 147 | |
| 148 | ············foreach(IPersistenceCapable pc in coll) |
| 149 | ················stateManager.AddRelatedObject(parent, field, pc); |
| 150 | |
| 151 | ········exit: |
| 152 | ············ArrayList temp = new ArrayList(); |
| 153 | ············foreach (object o in coll) |
| 154 | ················temp.Add(o); |
| 155 | ············for (int i = temp.Count - 1; i >= 0; i--) |
| 156 | ················((IList)container).Insert(index, temp[i]); |
| 157 | ········} |
| 158 | |
| 159 | ········public static int RemoveAll(object container, Delegate pred, Hashtable table) |
| 160 | ········{ |
| 161 | ············if (container == null) |
| 162 | ················throw new NDOException(3, "RemoveAll: container is null"); |
| 163 | |
| 164 | ············if (pred == null) |
| 165 | ················return 0; |
| 166 | |
| 167 | ············bool validRelation = false; |
| 168 | ············IPersistenceCapable parent = null; |
| 169 | ············string field = null; |
| 170 | ············IStateManager stateManager = null; |
| 171 | |
| 172 | ············Triple t = (Triple) table[container]; |
| 173 | ············if (t == null) |
| 174 | ················goto exit; |
| 175 | ············parent = t.Parent as IPersistenceCapable; |
| 176 | ············if (parent == null) |
| 177 | ················goto exit; |
| 178 | |
| 179 | ············field = t.Field; |
| 180 | |
| 181 | ············stateManager = parent.NDOStateManager; |
| 182 | ············if (stateManager == null) |
| 183 | ················goto exit; |
| 184 | |
| 185 | ············validRelation = true; |
| 186 | |
| 187 | ············exit: |
| 188 | ············IList ilist = (IList) container; |
| 189 | ············ArrayList toDelete = new ArrayList(); |
| 190 | ············foreach(object relObj in ilist) |
| 191 | ············{ |
| 192 | ················if((bool) pred.DynamicInvoke(new object[]{relObj})) |
| 193 | ················{ |
| 194 | ····················toDelete.Add(relObj); |
| 195 | ····················if (validRelation) |
| 196 | ························stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable) relObj); |
| 197 | ················} |
| 198 | ············} |
| 199 | ············foreach(object o in toDelete) |
| 200 | ················ilist.Remove(o); |
| 201 | |
| 202 | ············return toDelete.Count; |
| 203 | ········} |
| 204 | |
| 205 | |
| 206 | ········public static void SetRange(object container, int index, ICollection coll, Hashtable table) |
| 207 | ········{ |
| 208 | ············if (container == null) |
| 209 | ············{ |
| 210 | ····················throw new NDOException(3, "SetRange: container is null"); |
| 211 | ············} |
| 212 | ············Triple t = (Triple) table[container]; |
| 213 | ············if (t == null) |
| 214 | ················goto exit; |
| 215 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 216 | ············if (parent == null) |
| 217 | ················goto exit; |
| 218 | |
| 219 | ············string field = t.Field; |
| 220 | |
| 221 | ············IStateManager stateManager; |
| 222 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 223 | ················goto exit; |
| 224 | |
| 225 | ············if (coll == null) |
| 226 | ················goto exit; |
| 227 | |
| 228 | ············int lastIndex = index + coll.Count; |
| 229 | ············if (lastIndex > ((IList)container).Count) |
| 230 | ············{ |
| 231 | ················ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException(); |
| 232 | ················throw new ArgumentOutOfRangeException(string.Empty, "SetRange: " + ex.Message); |
| 233 | ············} |
| 234 | |
| 235 | ············for (int i = index; i < lastIndex; i++) |
| 236 | ················stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable)((IList)container)[i]); |
| 237 | ············foreach(IPersistenceCapable pc in coll) |
| 238 | ················stateManager.AddRelatedObject(parent, field, pc); |
| 239 | |
| 240 | ············exit: |
| 241 | ················((ArrayList)container).SetRange(index, coll); |
| 242 | ········} |
| 243 | |
| 244 | ········public static void RemoveRange(object container, int index, int count, Hashtable table) |
| 245 | ········{ |
| 246 | ············if (container == null) |
| 247 | ············{ |
| 248 | ················throw new NDOException(4, "RemoveRange: container is null"); |
| 249 | ············} |
| 250 | ············Triple t = (Triple) table[container]; |
| 251 | ············if (t == null) |
| 252 | ················goto exit; |
| 253 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 254 | ············if (parent == null) |
| 255 | ················goto exit; |
| 256 | |
| 257 | ············string field = t.Field; |
| 258 | |
| 259 | ············IStateManager stateManager; |
| 260 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 261 | ················goto exit; |
| 262 | |
| 263 | ············int lastIndex = index + count; |
| 264 | ············if (lastIndex > ((IList)container).Count) |
| 265 | ············{ |
| 266 | ················ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException(); |
| 267 | ················throw new ArgumentOutOfRangeException(string.Empty, "RemoveRange: " + ex.Message); |
| 268 | ············} |
| 269 | |
| 270 | ············for (int i = index; i < lastIndex; i++) |
| 271 | ················stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable)((IList)container)[i]); |
| 272 | |
| 273 | ········exit: |
| 274 | ············for (int i = 0; i < count; i++) |
| 275 | ················((IList)container).RemoveAt(index); |
| 276 | ········} |
| 277 | |
| 278 | |
| 279 | ········public static int Add(object container, object element, Hashtable table) |
| 280 | ········{ |
| 281 | ············if (container == null) |
| 282 | ············{ |
| 283 | ················if (element != null) |
| 284 | ····················throw new NDOException(5, "Adding related object of type " + element.GetType().FullName + ": container is null"); |
| 285 | ················else |
| 286 | ····················throw new NDOException(5, "Adding related object: container is null"); |
| 287 | ············} |
| 288 | ············Triple t = (Triple) table[container]; |
| 289 | ············if (t == null) |
| 290 | ················goto exit; |
| 291 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 292 | ············if (parent == null) |
| 293 | ················goto exit; |
| 294 | |
| 295 | ············string field = t.Field; |
| 296 | |
| 297 | ············IStateManager stateManager; |
| 298 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 299 | ················goto exit; |
| 300 | ············stateManager.AddRelatedObject(parent, field, (IPersistenceCapable) element); |
| 301 | |
| 302 | exit: |
| 303 | ············return ((IList)container).Add(element);············ |
| 304 | ········} |
| 305 | |
| 306 | ········public static void Insert(object container, int index, object element, Hashtable table) |
| 307 | ········{ |
| 308 | ············Triple t = (Triple) table[container]; |
| 309 | ············if (t == null) |
| 310 | ················goto exit; |
| 311 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 312 | ············if (parent == null) |
| 313 | ················goto exit; |
| 314 | |
| 315 | ············string field = t.Field; |
| 316 | |
| 317 | ············IStateManager stateManager; |
| 318 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 319 | ················goto exit; |
| 320 | ············stateManager.AddRelatedObject(parent, field, (IPersistenceCapable) element); |
| 321 | |
| 322 | ············exit: |
| 323 | ················((IList)container).Insert(index, (IPersistenceCapable) element);············ |
| 324 | ········} |
| 325 | |
| 326 | ········public static void SetItem(object container, int index, object element, Hashtable table) |
| 327 | ········{ |
| 328 | ············Triple t = (Triple) table[container]; |
| 329 | ············if (t == null) |
| 330 | ················goto exit; |
| 331 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 332 | ············if (parent == null) |
| 333 | ················goto exit; |
| 334 | |
| 335 | ············string field = t.Field; |
| 336 | |
| 337 | ············IStateManager stateManager; |
| 338 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 339 | ················goto exit; |
| 340 | ············object elToRemove = ((IList)container)[index]; |
| 341 | ············stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable) elToRemove); |
| 342 | ············stateManager.AddRelatedObject(parent, field, (IPersistenceCapable) element); |
| 343 | |
| 344 | ············exit: |
| 345 | ················((IList)container)[index] = element; |
| 346 | ········} |
| 347 | |
| 348 | |
| 349 | ········public static bool Remove(object container, object element, Hashtable table) |
| 350 | ········{ |
| 351 | ············Triple t = (Triple) table[container]; |
| 352 | ············if (t == null) |
| 353 | ················goto exit; |
| 354 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 355 | ············if (parent == null) |
| 356 | ················goto exit; |
| 357 | |
| 358 | ············string field = t.Field; |
| 359 | |
| 360 | ············IStateManager stateManager; |
| 361 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 362 | ················goto exit; |
| 363 | ············stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable) element); |
| 364 | |
| 365 | ········exit: |
| 366 | ············IList ilist = ((IList)container); |
| 367 | ············int ix = ilist.IndexOf(element); |
| 368 | ············if (ix < 0) |
| 369 | ················return false; |
| 370 | ············ilist.RemoveAt(ix); |
| 371 | ············return true; |
| 372 | ········} |
| 373 | |
| 374 | ········public static void RemoveAt(object container, int index, Hashtable table) |
| 375 | ········{ |
| 376 | ············Triple t = (Triple) table[container]; |
| 377 | ············if (t == null) |
| 378 | ················goto exit; |
| 379 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 380 | ············if (parent == null) |
| 381 | ················goto exit; |
| 382 | |
| 383 | ············string field = t.Field; |
| 384 | |
| 385 | ············IStateManager stateManager; |
| 386 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 387 | ················goto exit; |
| 388 | ············IPersistenceCapable element = (IPersistenceCapable)((IList)container)[index]; |
| 389 | ············stateManager.RemoveRelatedObject(parent, field, (IPersistenceCapable) element); |
| 390 | |
| 391 | ············exit: |
| 392 | ················((IList)container).RemoveAt(index);············ |
| 393 | ········} |
| 394 | |
| 395 | ········public static void Clear(object container, Hashtable table) |
| 396 | ········{ |
| 397 | ············Triple t = (Triple) table[container]; |
| 398 | ············if (t == null) |
| 399 | ················goto exit; |
| 400 | ············IPersistenceCapable parent = t.Parent as IPersistenceCapable; |
| 401 | ············if (parent == null) |
| 402 | ················goto exit; |
| 403 | |
| 404 | ············string field = t.Field; |
| 405 | |
| 406 | ············IStateManager stateManager; |
| 407 | ············if ((stateManager = parent.NDOStateManager) == null) |
| 408 | ················goto exit; |
| 409 | |
| 410 | ············stateManager.RemoveRangeRelatedObjects(parent, field, (IList) container); |
| 411 | |
| 412 | ············exit: |
| 413 | ················((IList)container).Clear();············ |
| 414 | ········} |
| 415 | ····} |
| 416 | } |
| 417 |