1 /***
2 * Copyright (c) 2003 held jointly by the individual authors.
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; with out even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 *
18 * > http://www.gnu.org/copyleft/lesser.html
19 * > http://www.opensource.org/licenses/lgpl-license.php
20 */
21 package net.mlw.vlh.adapter.jdbc.spring.util;
22
23 import java.sql.Connection;
24 import java.sql.PreparedStatement;
25 import java.sql.ResultSet;
26 import java.sql.SQLException;
27
28 import javax.sql.DataSource;
29
30 import net.mlw.vlh.adapter.jdbc.util.StandardConnectionCreator;
31
32 import org.springframework.jdbc.datasource.DataSourceUtils;
33 import org.springframework.jdbc.support.JdbcUtils;
34
35 /***
36 * This connection creator uses spring to manage connection in transactional environment.
37 *
38 * @author Stepan Marek
39 * @version $Revision: 1.2 $ $Date: 2005/10/20 16:37:49 $
40 * @see DataSourceUtils
41 */
42 public class SpringConnectionCreator extends StandardConnectionCreator
43 {
44
45 public SpringConnectionCreator()
46 {
47 }
48
49 public SpringConnectionCreator(DataSource dataSource)
50 {
51 super(dataSource);
52 }
53
54 public Connection createConnection() throws SQLException
55 {
56 return DataSourceUtils.getConnection(getDataSource());
57 }
58
59 public void close(ResultSet result, PreparedStatement statement, Connection connection)
60 {
61 JdbcUtils.closeResultSet(result);
62 JdbcUtils.closeStatement(statement);
63
64 DataSourceUtils.closeConnectionIfNecessary(connection, getDataSource());
65 }
66 }