执行后groovy.sql.Sql.firstRow会关闭连接吗? [英] Does groovy.sql.Sql.firstRow Closes Connection After Execution?
问题描述
import groovy.sql.Sql
class MyService {
sql groovySql
def serviceMethod(){
groovySql.firstRow(some query .....)
}
}
在resources.groovy groovySql中注入如下内容:
groovySql(groovy.sql.Sql,ref('dataSource'))
这是一个Grails 2.4.5应用程序。现在,问题是何时调用 serviceMethod
,连接是否自动关闭?
如果需要, Sql
中的每个方法都会创建并释放资源。 / b>
在外观下,外观隐藏了与获取
连接,构造和配置语句,与
交互连接,关闭资源和记录错误。
如果您创建 Sql
一个 DataSource
,它会每次都得到一个新的连接,并在操作结束时关闭它。
如果我们使用的是DataSource,并且我们还没有启用语句缓存,那么严格来说,最后的close()方法并不是必需的 - 因为
执行所有连接处理透明地代表我们;
但是,它并不会伤害到它,因为它将在这种情况下默默返回
。
In MyService I have the following:
import groovy.sql.Sql
class MyService {
Sql groovySql
def serviceMethod(){
groovySql.firstRow("some query.....")
}
}
In resources.groovy groovySql inject as follows:
groovySql(groovy.sql.Sql, ref('dataSource'))
This is a Grails 2.4.5 application. Now, the question is when serviceMethod
is called, is the connection closed automatically?
Every method in Sql
creates and releases resources if necessary.
Under the covers the facade hides away details associated with getting connections, constructing and configuring statements, interacting with the connection, closing resources and logging errors.
If you create a Sql
with a DataSource
, it will get a new connection every time, and close it at the end of the operation.
If we are using a DataSource and we haven't enabled statement caching, then strictly speaking the final close() method isn't required - as all connection handling is performed transparently on our behalf; however, it doesn't hurt to have it there as it will return silently in that case.
这篇关于执行后groovy.sql.Sql.firstRow会关闭连接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!