|
2 | 2 | using System.Collections; |
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.Data; |
5 | | -using System.Data.Common; |
6 | | -using System.Linq; |
| 5 | +using System.Data.Common; |
| 6 | +using System.Linq; |
7 | 7 | using System.Text; |
8 | 8 | using NHibernate.AdoNet; |
9 | 9 | using NHibernate.Cache; |
@@ -621,11 +621,11 @@ private ICollectionInitializer GetSubselectInitializer(object key, ISessionImple |
621 | 621 | else |
622 | 622 | { |
623 | 623 | // Take care of any entities that might have |
624 | | - // been evicted! |
625 | | - List<EntityKey> keysToRemove = subselect.Result |
626 | | - .Where(entityKey => !persistenceContext.ContainsEntity(entityKey)).ToList(); |
627 | | - |
628 | | - foreach (var entityKey in keysToRemove) |
| 624 | + // been evicted! |
| 625 | + List<EntityKey> keysToRemove = subselect.Result |
| 626 | + .Where(entityKey => !persistenceContext.ContainsEntity(entityKey)).ToList(); |
| 627 | + |
| 628 | + foreach (var entityKey in keysToRemove) |
629 | 629 | subselect.Result.Remove(entityKey); |
630 | 630 |
|
631 | 631 | // Run a subquery loader |
@@ -1080,50 +1080,49 @@ public void Recreate(IPersistentCollection collection, object id, ISessionImplem |
1080 | 1080 |
|
1081 | 1081 | try |
1082 | 1082 | { |
| 1083 | + IExpectation expectation = null; |
| 1084 | + bool useBatch = false; |
| 1085 | + int i = 0; |
| 1086 | + int count = 0; |
| 1087 | + |
1083 | 1088 | // create all the new entries |
1084 | 1089 | IEnumerator entries = collection.Entries(this).GetEnumerator(); |
1085 | | - if (entries.MoveNext()) |
| 1090 | + while (entries.MoveNext()) |
1086 | 1091 | { |
1087 | | - entries.Reset(); |
1088 | | - IExpectation expectation = Expectations.AppropriateExpectation(insertCheckStyle); |
1089 | | - collection.PreInsert(this); |
1090 | | - //bool callable = InsertCallable; |
1091 | | - bool useBatch = expectation.CanBeBatched; |
1092 | | - int i = 0; |
1093 | | - int count = 0; |
1094 | | - |
1095 | | - while (entries.MoveNext()) |
| 1092 | + // Init, if we're on the first element. |
| 1093 | + if (count == 0) |
1096 | 1094 | { |
1097 | | - object entry = entries.Current; |
1098 | | - if (collection.EntryExists(entry, i)) |
1099 | | - { |
1100 | | - object entryId; |
1101 | | - if (!IsIdentifierAssignedByInsert) |
1102 | | - { |
1103 | | - // NH Different implementation: write once |
1104 | | - entryId = PerformInsert(id, collection, expectation, entry, i, useBatch, false, session); |
1105 | | - } |
1106 | | - else |
1107 | | - { |
1108 | | - entryId = PerformInsert(id, collection, entry, i, session); |
1109 | | - } |
1110 | | - collection.AfterRowInsert(this, entry, i, entryId); |
1111 | | - count++; |
1112 | | - } |
1113 | | - i++; |
| 1095 | + expectation = Expectations.AppropriateExpectation(insertCheckStyle); |
| 1096 | + collection.PreInsert(this); |
| 1097 | + //bool callable = InsertCallable; |
| 1098 | + useBatch = expectation.CanBeBatched; |
1114 | 1099 | } |
1115 | 1100 |
|
1116 | | - if (log.IsDebugEnabled) |
| 1101 | + object entry = entries.Current; |
| 1102 | + if (collection.EntryExists(entry, i)) |
1117 | 1103 | { |
1118 | | - log.Debug(string.Format("done inserting collection: {0} rows inserted", count)); |
| 1104 | + object entryId; |
| 1105 | + if (!IsIdentifierAssignedByInsert) |
| 1106 | + { |
| 1107 | + // NH Different implementation: write once |
| 1108 | + entryId = PerformInsert(id, collection, expectation, entry, i, useBatch, false, session); |
| 1109 | + } |
| 1110 | + else |
| 1111 | + { |
| 1112 | + entryId = PerformInsert(id, collection, entry, i, session); |
| 1113 | + } |
| 1114 | + collection.AfterRowInsert(this, entry, i, entryId); |
| 1115 | + count++; |
1119 | 1116 | } |
| 1117 | + i++; |
1120 | 1118 | } |
1121 | | - else |
| 1119 | + |
| 1120 | + if (log.IsDebugEnabled) |
1122 | 1121 | { |
1123 | | - if (log.IsDebugEnabled) |
1124 | | - { |
| 1122 | + if (count > 0) |
| 1123 | + log.Debug(string.Format("done inserting collection: {0} rows inserted", count)); |
| 1124 | + else |
1125 | 1125 | log.Debug("collection was empty"); |
1126 | | - } |
1127 | 1126 | } |
1128 | 1127 | } |
1129 | 1128 | catch (DbException sqle) |
|
0 commit comments