@@ -220,67 +220,59 @@ public override object DoWorkInCurrentTransaction(ISessionImplementor session, I
220
220
//select + uspdate even for no transaction
221
221
//or read committed isolation level (needed for .net?)
222
222
223
- IDbCommand qps = conn . CreateCommand ( ) ;
224
- IDataReader rs = null ;
225
- qps . CommandText = query ;
226
- qps . CommandType = CommandType . Text ;
227
- qps . Transaction = transaction ;
228
- PersistentIdGeneratorParmsNames . SqlStatementLogger . LogCommand ( "Reading high value:" , qps , FormatStyle . Basic ) ;
229
- try
223
+ using ( var qps = conn . CreateCommand ( ) )
230
224
{
231
- rs = qps . ExecuteReader ( ) ;
232
- if ( ! rs . Read ( ) )
225
+ qps . CommandText = query ;
226
+ qps . CommandType = CommandType . Text ;
227
+ qps . Transaction = transaction ;
228
+ PersistentIdGeneratorParmsNames . SqlStatementLogger . LogCommand ( "Reading high value:" , qps , FormatStyle . Basic ) ;
229
+ try
233
230
{
234
- string err ;
235
- if ( string . IsNullOrEmpty ( whereClause ) )
231
+ using ( var rs = qps . ExecuteReader ( ) )
236
232
{
237
- err = "could not read a hi value - you need to populate the table: " + tableName ;
233
+ if ( ! rs . Read ( ) )
234
+ {
235
+ string err ;
236
+ if ( string . IsNullOrEmpty ( whereClause ) )
237
+ {
238
+ err = "could not read a hi value - you need to populate the table: " + tableName ;
239
+ }
240
+ else
241
+ {
242
+ err = string . Format ( "could not read a hi value from table '{0}' using the where clause ({1})- you need to populate the table." , tableName , whereClause ) ;
243
+ }
244
+ log . Error ( err ) ;
245
+ throw new IdentifierGenerationException ( err ) ;
246
+ }
247
+ result = Convert . ToInt64 ( columnType . Get ( rs , 0 ) ) ;
238
248
}
239
- else
240
- {
241
- err = string . Format ( "could not read a hi value from table '{0}' using the where clause ({1})- you need to populate the table." , tableName , whereClause ) ;
242
- }
243
- log . Error ( err ) ;
244
- throw new IdentifierGenerationException ( err ) ;
245
249
}
246
- result = Convert . ToInt64 ( columnType . Get ( rs , 0 ) ) ;
247
- }
248
- catch ( Exception e )
249
- {
250
- log . Error ( "could not read a hi value" , e ) ;
251
- throw ;
252
- }
253
- finally
254
- {
255
- if ( rs != null )
250
+ catch ( Exception e )
256
251
{
257
- rs . Close ( ) ;
252
+ log . Error ( "could not read a hi value" , e ) ;
253
+ throw ;
258
254
}
259
- qps . Dispose ( ) ;
260
255
}
261
256
262
- IDbCommand ups = session . Factory . ConnectionProvider . Driver . GenerateCommand ( CommandType . Text , updateSql ,
263
- parameterTypes ) ;
264
- ups . Connection = conn ;
265
- ups . Transaction = transaction ;
266
-
267
- try
257
+ using ( var ups = session . Factory . ConnectionProvider . Driver . GenerateCommand ( CommandType . Text , updateSql , parameterTypes ) )
268
258
{
269
- columnType . Set ( ups , result + 1 , 0 ) ;
270
- columnType . Set ( ups , result , 1 ) ;
259
+ ups . Connection = conn ;
260
+ ups . Transaction = transaction ;
261
+
262
+ try
263
+ {
264
+ columnType . Set ( ups , result + 1 , 0 ) ;
265
+ columnType . Set ( ups , result , 1 ) ;
271
266
272
- PersistentIdGeneratorParmsNames . SqlStatementLogger . LogCommand ( "Updating high value:" , ups , FormatStyle . Basic ) ;
267
+ PersistentIdGeneratorParmsNames . SqlStatementLogger . LogCommand ( "Updating high value:" , ups , FormatStyle . Basic ) ;
273
268
274
- rows = ups . ExecuteNonQuery ( ) ;
275
- }
276
- catch ( Exception e )
277
- {
278
- log . Error ( "could not update hi value in: " + tableName , e ) ;
279
- throw ;
280
- }
281
- finally
282
- {
283
- ups . Dispose ( ) ;
269
+ rows = ups . ExecuteNonQuery ( ) ;
270
+ }
271
+ catch ( Exception e )
272
+ {
273
+ log . Error ( "could not update hi value in: " + tableName , e ) ;
274
+ throw ;
275
+ }
284
276
}
285
277
}
286
278
while ( rows == 0 ) ;
0 commit comments