1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package org.apache.tapestry.contrib.table.model.sql; |
16 | |
|
17 | |
import java.sql.Connection; |
18 | |
import java.sql.DriverManager; |
19 | |
import java.sql.SQLException; |
20 | |
|
21 | |
import org.apache.commons.logging.Log; |
22 | |
import org.apache.commons.logging.LogFactory; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class SimpleSqlConnectionSource implements ISqlConnectionSource |
28 | |
{ |
29 | |
|
30 | 0 | private static final Log LOG = LogFactory |
31 | 0 | .getLog(SimpleSqlConnectionSource.class); |
32 | |
|
33 | |
private String m_strUrl; |
34 | |
|
35 | |
private String m_strUser; |
36 | |
|
37 | |
private String m_strPwd; |
38 | |
|
39 | |
public SimpleSqlConnectionSource(String strUrl) |
40 | |
{ |
41 | 0 | this(strUrl, null, null); |
42 | 0 | } |
43 | |
|
44 | |
public SimpleSqlConnectionSource(String strUrl, String strUser, |
45 | |
String strPwd) |
46 | 0 | { |
47 | 0 | m_strUrl = strUrl; |
48 | 0 | m_strUser = strUser; |
49 | 0 | m_strPwd = strPwd; |
50 | 0 | } |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public Connection obtainConnection() |
56 | |
throws SQLException |
57 | |
{ |
58 | 0 | if (m_strUser == null) return DriverManager.getConnection(m_strUrl); |
59 | |
|
60 | 0 | return DriverManager.getConnection(m_strUrl, m_strUser, m_strPwd); |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public void returnConnection(Connection objConnection) |
67 | |
{ |
68 | |
try |
69 | |
{ |
70 | 0 | objConnection.close(); |
71 | |
} |
72 | 0 | catch (SQLException e) |
73 | |
{ |
74 | 0 | LOG.warn("Could not close connection", e); |
75 | 0 | } |
76 | 0 | } |
77 | |
|
78 | |
} |