Skip to content

Commit 4af22ca

Browse files
cremorhazzik
authored andcommitted
NH-3072: OneToManyPersister improvements
1 parent 1ac52c1 commit 4af22ca

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

src/NHibernate/Persister/Collection/OneToManyPersister.cs

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -161,47 +161,41 @@ protected override int DoUpdateRows(object id, IPersistentCollection collection,
161161

162162
if (RowDeleteEnabled)
163163
{
164-
bool useBatch = true;
164+
IExpectation deleteExpectation = Expectations.AppropriateExpectation(DeleteCheckStyle);
165+
bool useBatch = deleteExpectation.CanBeBatched;
166+
SqlCommandInfo sql = SqlDeleteRowString;
165167
IDbCommand st = null;
166168
// update removed rows fks to null
167169
try
168170
{
169171
int i = 0;
170172
IEnumerable entries = collection.Entries(this);
171-
IExpectation expectation = Expectations.None;
172173

173174
foreach (object entry in entries)
174175
{
175176
if (collection.NeedsUpdating(entry, i, ElementType))
176177
{
177178
// will still be issued when it used to be null
178-
if (st == null)
179+
if (useBatch)
180+
{
181+
st = session.Batcher.PrepareBatchCommand(SqlDeleteRowString.CommandType, sql.Text,
182+
SqlDeleteRowString.ParameterTypes);
183+
}
184+
else
179185
{
180-
SqlCommandInfo sql = SqlDeleteRowString;
181-
if (DeleteCallable)
182-
{
183-
expectation = Expectations.AppropriateExpectation(DeleteCheckStyle);
184-
useBatch = expectation.CanBeBatched;
185-
st = useBatch
186-
? session.Batcher.PrepareBatchCommand(SqlDeleteRowString.CommandType, sql.Text, SqlDeleteRowString.ParameterTypes)
187-
: session.Batcher.PrepareCommand(SqlDeleteRowString.CommandType, sql.Text, SqlDeleteRowString.ParameterTypes);
188-
//offset += expectation.prepare(st);
189-
}
190-
else
191-
{
192-
st = session.Batcher.PrepareBatchCommand(SqlDeleteRowString.CommandType, sql.Text, SqlDeleteRowString.ParameterTypes);
193-
}
186+
st = session.Batcher.PrepareCommand(SqlDeleteRowString.CommandType, sql.Text,
187+
SqlDeleteRowString.ParameterTypes);
194188
}
195189

196190
int loc = WriteKey(st, id, offset, session);
197191
WriteElementToWhere(st, collection.GetSnapshotElement(entry, i), loc, session);
198192
if (useBatch)
199193
{
200-
session.Batcher.AddToBatch(expectation);
194+
session.Batcher.AddToBatch(deleteExpectation);
201195
}
202196
else
203197
{
204-
expectation.VerifyOutcomeNonBatched(session.Batcher.ExecuteNonQuery(st), st);
198+
deleteExpectation.VerifyOutcomeNonBatched(session.Batcher.ExecuteNonQuery(st), st);
205199
}
206200
count++;
207201
}
@@ -227,9 +221,9 @@ protected override int DoUpdateRows(object id, IPersistentCollection collection,
227221

228222
if (RowInsertEnabled)
229223
{
230-
IExpectation expectation = Expectations.AppropriateExpectation(InsertCheckStyle);
224+
IExpectation insertExpectation = Expectations.AppropriateExpectation(InsertCheckStyle);
231225
//bool callable = InsertCallable;
232-
bool useBatch = expectation.CanBeBatched;
226+
bool useBatch = insertExpectation.CanBeBatched;
233227
SqlCommandInfo sql = SqlInsertRowString;
234228
IDbCommand st = null;
235229

@@ -244,17 +238,16 @@ protected override int DoUpdateRows(object id, IPersistentCollection collection,
244238
{
245239
if (useBatch)
246240
{
247-
if (st == null)
248-
{
249-
st = session.Batcher.PrepareBatchCommand(SqlInsertRowString.CommandType, sql.Text, SqlInsertRowString.ParameterTypes);
250-
}
241+
st = session.Batcher.PrepareBatchCommand(SqlInsertRowString.CommandType, sql.Text,
242+
SqlInsertRowString.ParameterTypes);
251243
}
252244
else
253245
{
254-
st = session.Batcher.PrepareCommand(SqlInsertRowString.CommandType, sql.Text, SqlInsertRowString.ParameterTypes);
246+
st = session.Batcher.PrepareCommand(SqlInsertRowString.CommandType, sql.Text,
247+
SqlInsertRowString.ParameterTypes);
255248
}
256249

257-
//offset += expectation.Prepare(st, Factory.ConnectionProvider.Driver);
250+
//offset += insertExpectation.Prepare(st, Factory.ConnectionProvider.Driver);
258251
int loc = WriteKey(st, id, offset, session);
259252
if (HasIndex && !indexContainsFormula)
260253
{
@@ -263,11 +256,11 @@ protected override int DoUpdateRows(object id, IPersistentCollection collection,
263256
WriteElementToWhere(st, collection.GetElement(entry), loc, session);
264257
if (useBatch)
265258
{
266-
session.Batcher.AddToBatch(expectation);
259+
session.Batcher.AddToBatch(insertExpectation);
267260
}
268261
else
269262
{
270-
expectation.VerifyOutcomeNonBatched(session.Batcher.ExecuteNonQuery(st), st);
263+
insertExpectation.VerifyOutcomeNonBatched(session.Batcher.ExecuteNonQuery(st), st);
271264
}
272265
count++;
273266
}

0 commit comments

Comments
 (0)