00001 package com.quadcap.services;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
import java.io.PrintWriter;
00042
00043
import java.util.Properties;
00044
00045
import java.sql.Driver;
00046
import java.sql.DriverManager;
00047
import java.sql.SQLException;
00048
00049
import javax.naming.Reference;
00050
import javax.naming.Referenceable;
00051
import javax.naming.StringRefAddr;
00052
00053
00054
00055
00056
00057
00058
00059
00060 public class DataSource implements javax.sql.
DataSource, Referenceable {
00061 String
name;
00062 String
driverClass = null;
00063 PrintWriter
logWriter = null;
00064 int loginTimeout = 0;
00065 String
url;
00066 Properties
props =
new Properties();
00067 Driver
driver = null;
00068
00069
00070
00071
00072 public DataSource() {
00073 }
00074
00075 public void setName(String name) {
00076
this.name = name;
00077 }
00078
00079 public String
getName() {
00080
return name;
00081 }
00082
00083 public void setDriverClass(String s) {
00084
this.driverClass = s;
00085
try {
00086 Class.forName(
driverClass);
00087 }
catch (Throwable t) {
00088 }
00089 }
00090
00091 public String
getDriverClass() {
00092
return driverClass;
00093 }
00094
00095
00096
00097
00098 public String
getUrl() {
return url; }
00099
00100
00101
00102
00103 public void setUrl(String url) {
00104
this.url = url;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113 public void addConnectionProperty(String name, String val) {
00114
props.setProperty(name, val);
00115 }
00116
00117
00118
00119
00120
00121
00122
00123 public java.sql.Connection
getConnection()
00124 throws SQLException
00125 {
00126
return getDriver().connect(
url,
props);
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 public java.sql.Connection
getConnection(String username, String password)
00140
throws SQLException
00141 {
00142 Properties p =
new Properties(
props);
00143 p.setProperty(
"user", username);
00144 p.setProperty(
"password", password);
00145
return getDriver().connect(
url, p);
00146 }
00147
00148
00149
00150
00151 public PrintWriter
getLogWriter() {
00152
return logWriter;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 public void setLogWriter(PrintWriter w) {
00165
this.logWriter = w;
00166 }
00167
00168
00169
00170
00171
00172
00173 public int getLoginTimeout() {
00174
return loginTimeout;
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184 public void setLoginTimeout(
int timeout) {
00185
this.loginTimeout = timeout;
00186 }
00187
00188 public Reference
getReference() {
00189 Reference ref =
new Reference(
DataSource.class.getName(),
00190
"com.quadcap.services.DataSources",
00191 null);
00192 ref.add(
new StringRefAddr(
"name",
name));
00193
return ref;
00194 }
00195
00196 final private Driver
getDriver() throws SQLException {
00197
if (
driver == null) {
00198
driver = DriverManager.getDriver(
url);
00199 }
00200
return driver;
00201 }
00202 }
00203