@@ -118,29 +118,35 @@ class Session(database: Database) extends Logging {
118
118
withConnection { connection =>
119
119
val (preprocessedSelect, sql, argumentLists) = database.statementBuilder(select)
120
120
val startTime = new DateTime
121
- val preparedStatement = prepareStatement(connection, preprocessedSelect, sql, argumentLists)
122
121
try {
123
- val resultSet = preparedStatement.executeQuery
122
+ val preparedStatement = prepareStatement(connection, preprocessedSelect, sql, argumentLists)
124
123
try {
125
- val result = extractor(resultSet)
126
- val endTime = new DateTime
127
- logger.info(s " Ran sql in ${endTime.getMillis - startTime.getMillis}ms: ${logDetails(connection, sql, argumentLists)}" )
128
- result
124
+ val resultSet = preparedStatement.executeQuery
125
+ try {
126
+ val result = extractor(resultSet)
127
+ val endTime = new DateTime
128
+ logger.info(s " Ran sql in ${endTime.getMillis - startTime.getMillis}ms: ${logDetails(connection, sql, argumentLists)}" )
129
+ result
130
+ } finally {
131
+ try {
132
+ if (resultSet != null ) resultSet.close
133
+ } catch {
134
+ case e : SQLException =>
135
+ }
136
+ }
129
137
} finally {
130
138
try {
131
- if (resultSet != null ) resultSet.close
132
- } catch { case e : SQLException => }
139
+ if (preparedStatement != null ) preparedStatement.close
140
+ } catch {
141
+ case e : SQLException =>
142
+ }
133
143
}
134
144
} catch {
135
145
case NonFatal (e) =>
136
146
if (! database.verboseExceptions)
137
147
throw e
138
148
else
139
149
throw new SqlestException (s " Exception running sql: ${logDetails(connection, sql, argumentLists)}" , e)
140
- } finally {
141
- try {
142
- if (preparedStatement != null ) preparedStatement.close
143
- } catch { case e : SQLException => }
144
150
}
145
151
}
146
152
@@ -300,53 +306,60 @@ case class Transaction(database: Database) extends Session(database) {
300
306
withConnection { connection =>
301
307
val (preprocessedCommand, sql, argumentLists) = database.statementBuilder(command)
302
308
val startTime = new DateTime
303
- val preparedStatement = prepareStatement(connection, preprocessedCommand, sql, argumentLists)
309
+
304
310
try {
305
- val result = preparedStatement.executeBatch.sum
306
- val endTime = new DateTime
307
- logger.info(s " Ran sql in ${endTime.getMillis - startTime.getMillis}ms: ${logDetails(connection, sql, argumentLists)}" )
308
- result
311
+ val preparedStatement = prepareStatement(connection, preprocessedCommand, sql, argumentLists)
312
+ try {
313
+ val result = preparedStatement.executeBatch.sum
314
+ val endTime = new DateTime
315
+ logger.info(s " Ran sql in ${endTime.getMillis - startTime.getMillis}ms: ${logDetails(connection, sql, argumentLists)}" )
316
+ result
317
+ } finally {
318
+ try {
319
+ if (preparedStatement != null ) preparedStatement.close
320
+ } catch { case e : SQLException => }
321
+ }
309
322
} catch {
310
323
case NonFatal (e) =>
311
324
if (! database.verboseExceptions)
312
325
throw e
313
326
else
314
327
throw new SqlestException (s " Exception running sql: ${logDetails(connection, sql, argumentLists)}" , e)
315
- } finally {
316
- try {
317
- if (preparedStatement != null ) preparedStatement.close
318
- } catch { case e : SQLException => }
319
328
}
320
329
}
321
330
322
331
def executeInsertReturningKeys [T ](command : Insert )(implicit columnType : ColumnType [T ]): List [T ] =
323
332
withConnection { connection =>
324
333
val (preprocessedCommand, sql, argumentLists) = database.statementBuilder(command)
325
334
val startTime = new DateTime
326
- val preparedStatement = prepareStatement(
327
- connection,
328
- preprocessedCommand,
329
- sql,
330
- argumentLists,
331
- returnKeys = true
332
- )
333
335
try {
334
- val result = preparedStatement.executeUpdate
335
- val rs = preparedStatement.getGeneratedKeys
336
- val keys = IndexedExtractor [T ](1 ).extractAll(ResultSetIterable (rs))
337
- val endTime = new DateTime
338
- logger.info(s " Ran sql in ${endTime.getMillis - startTime.getMillis}ms: ${logDetails(connection, sql, argumentLists)}" )
339
- keys
336
+ val preparedStatement = prepareStatement(
337
+ connection,
338
+ preprocessedCommand,
339
+ sql,
340
+ argumentLists,
341
+ returnKeys = true
342
+ )
343
+ try {
344
+ val result = preparedStatement.executeUpdate
345
+ val rs = preparedStatement.getGeneratedKeys
346
+ val keys = IndexedExtractor [T ](1 ).extractAll(ResultSetIterable (rs))
347
+ val endTime = new DateTime
348
+ logger.info(s " Ran sql in ${endTime.getMillis - startTime.getMillis}ms: ${logDetails(connection, sql, argumentLists)}" )
349
+ keys
350
+ } finally {
351
+ try {
352
+ if (preparedStatement != null ) preparedStatement.close
353
+ } catch {
354
+ case e : SQLException =>
355
+ }
356
+ }
340
357
} catch {
341
358
case NonFatal (e) =>
342
359
if (! database.verboseExceptions)
343
360
throw e
344
361
else
345
362
throw new SqlestException (s " Exception running sql: ${logDetails(connection, sql, argumentLists)}" , e)
346
- } finally {
347
- try {
348
- if (preparedStatement != null ) preparedStatement.close
349
- } catch { case e : SQLException => }
350
363
}
351
364
}
352
365
0 commit comments