1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.commons.jelly.tags.sql; |
18 |
|
|
19 |
|
import java.io.PrintWriter; |
20 |
|
import java.sql.Connection; |
21 |
|
import java.sql.DriverManager; |
22 |
|
import java.sql.SQLException; |
23 |
|
|
24 |
|
import javax.sql.DataSource; |
25 |
|
|
26 |
|
import org.apache.commons.jelly.tags.Resources; |
27 |
|
import org.apache.commons.jelly.util.ClassLoaderUtils; |
28 |
|
import org.apache.commons.logging.Log; |
29 |
|
import org.apache.commons.logging.LogFactory; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
0 |
public class DataSourceWrapper implements DataSource { |
38 |
|
|
39 |
|
|
40 |
0 |
private static final Log log = LogFactory.getLog(DataSourceWrapper.class); |
41 |
|
|
42 |
|
private String driverClassName; |
43 |
|
private String jdbcURL; |
44 |
|
private String userName; |
45 |
|
private String password; |
46 |
|
|
47 |
|
public void setDriverClassName(String driverClassName) |
48 |
|
throws ClassNotFoundException, InstantiationException, IllegalAccessException { |
49 |
|
|
50 |
0 |
if (log.isDebugEnabled()) { |
51 |
0 |
log.debug("Loading JDBC driver: [" + driverClassName + "]"); |
52 |
|
} |
53 |
|
|
54 |
0 |
this.driverClassName = driverClassName; |
55 |
0 |
ClassLoaderUtils.getClassLoader(getClass()).loadClass(driverClassName).newInstance(); |
56 |
0 |
} |
57 |
|
|
58 |
|
public void setJdbcURL(String jdbcURL) { |
59 |
0 |
this.jdbcURL = jdbcURL; |
60 |
0 |
} |
61 |
|
|
62 |
|
public void setUserName(String userName) { |
63 |
0 |
this.userName = userName; |
64 |
0 |
} |
65 |
|
|
66 |
|
public void setPassword(String password) { |
67 |
0 |
this.password = password; |
68 |
0 |
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
public Connection getConnection() throws SQLException { |
75 |
0 |
Connection conn = null; |
76 |
0 |
if (userName != null) { |
77 |
0 |
if (log.isDebugEnabled()) { |
78 |
0 |
log.debug( |
79 |
|
"Creating connection from url: " + jdbcURL + " userName: " + userName); |
80 |
|
} |
81 |
|
|
82 |
0 |
conn = DriverManager.getConnection(jdbcURL, userName, password); |
83 |
|
} |
84 |
|
else { |
85 |
0 |
if (log.isDebugEnabled()) { |
86 |
0 |
log.debug("Creating connection from url: " + jdbcURL); |
87 |
|
} |
88 |
|
|
89 |
0 |
conn = DriverManager.getConnection(jdbcURL); |
90 |
|
} |
91 |
0 |
if (log.isDebugEnabled()) { |
92 |
0 |
log.debug( |
93 |
|
"Created connection: " + conn ); |
94 |
|
} |
95 |
0 |
return conn; |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
public Connection getConnection(String username, String password) |
103 |
|
throws SQLException { |
104 |
0 |
throw new SQLException(Resources.getMessage("NOT_SUPPORTED")); |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
public int getLoginTimeout() throws SQLException { |
111 |
0 |
throw new SQLException(Resources.getMessage("NOT_SUPPORTED")); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
public PrintWriter getLogWriter() throws SQLException { |
118 |
0 |
throw new SQLException(Resources.getMessage("NOT_SUPPORTED")); |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
public void setLoginTimeout(int seconds) throws SQLException { |
125 |
0 |
throw new SQLException(Resources.getMessage("NOT_SUPPORTED")); |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
public synchronized void setLogWriter(PrintWriter out) throws SQLException { |
132 |
0 |
throw new SQLException(Resources.getMessage("NOT_SUPPORTED")); |
133 |
|
} |
134 |
|
|
135 |
|
} |