concept DataSource in category groovy

This is an excerpt from Manning's book Groovy in Action, Second Edition.
The other scenario, which is quite common, is using a DataSource. We cover that next.
If you look back to figure 13.1, you’ll notice two concepts below the JDBC API: DriverManager and DataSource. The Sql.newInstance methods always go through the DriverManager facility, which can be seen as the classic low-level way of connecting. Since JDK 1.4, there has been a second way that uses the DataSource concept.
Although the DriverManager facility is still supported for backward compatibility, using DataSource is generally preferable. In addition to providing a connection to the database, it may optionally manage a connection pool and support distributed transactions (not explained here). Because obtaining connections to a database is a time-consuming operation, it’s common to reuse them. The pool is the storage facility that provides you with a connection. You have to pass the connection back after use so that others can reuse it. If you forget to return it, the pool becomes pointless. To avoid that, Groovy SQL transparently returns the connection for you.
DataSources become even more important when running in a managed environment such as within an application server. A managed environment provides its applications with DataSource objects to make its special features (such as connection pooling) available. In this scenario, DataSource objects are often retrieved through the Java Naming and Directory Interface (JNDI).
Now that you’ve heard about the merits of DataSources, how do you use them in Groovy? Your database vendor provides its own implementation of the javax.sql.DataSource interface. HSQLDB, for example, provides the class org.hsqldb.jdbc.JDBCDataSource for that purpose. To obtain a Sql instance for a DataSource, you need to create it, optionally set its properties, and pass it to the Sql constructor, as can be seen in the following listing.