src/org/objectweb/cjdbc/driver/DataSource.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.driver; 00026 00027 import java.io.PrintWriter; 00028 import java.io.Serializable; 00029 import java.sql.SQLException; 00030 import java.util.Properties; 00031 00032 import javax.naming.NamingException; 00033 import javax.naming.Reference; 00034 import javax.naming.Referenceable; 00035 import javax.naming.StringRefAddr; 00036 00047 public class DataSource 00048 implements 00049 javax.sql.DataSource, 00050 Referenceable, 00051 Serializable 00052 { 00053 00055 protected static final String URL_PROPERTY = "url"; 00056 protected static final String USER_PROPERTY = Driver.USER_PROPERTY; 00057 protected static final String PASSWORD_PROPERTY = Driver.PASSWORD_PROPERTY; 00058 protected static final String DRIVER_CLASSNAME = "org.objectweb.cjdbc.driver.Driver"; 00059 protected static final String FACTORY_CLASSNAME = "org.objectweb.cjdbc.driver.DataSourceFactory"; 00060 protected static final String DESCRIPTION_PROPERTY = "description"; 00061 00063 protected static Driver driver = null; 00064 static 00065 { 00066 try 00067 { 00068 driver = (Driver) Class.forName(DRIVER_CLASSNAME).newInstance(); 00069 } 00070 catch (Exception e) 00071 { 00072 throw new RuntimeException("Can't load " + DRIVER_CLASSNAME); 00073 } 00074 } 00075 00077 protected String url = null; 00078 protected String user = null; 00079 protected String password = null; 00080 protected PrintWriter logWriter = null; 00081 00085 public DataSource() 00086 { 00087 } 00088 00089 //--------------------------------- 00090 //--- DataSource methods 00091 //--------------------------------- 00099 public java.sql.Connection getConnection() throws SQLException 00100 { 00101 return getConnection(user, password); 00102 } 00103 00113 public java.sql.Connection getConnection(String user, String password) 00114 throws SQLException 00115 { 00116 if (user == null) 00117 { 00118 user = ""; 00119 } 00120 if (password == null) 00121 { 00122 password = ""; 00123 } 00124 Properties props = new Properties(); 00125 props.put(USER_PROPERTY, user); 00126 props.put(PASSWORD_PROPERTY, password); 00127 00128 return getConnection(props); 00129 } 00130 00137 public void setLogWriter(PrintWriter output) throws SQLException 00138 { 00139 logWriter = output; 00140 } 00141 00147 public java.io.PrintWriter getLogWriter() 00148 { 00149 return logWriter; 00150 } 00151 00158 public void setLoginTimeout(int seconds) throws SQLException 00159 { 00160 } 00161 00168 public int getLoginTimeout() throws SQLException 00169 { 00170 return 0; 00171 } 00172 00173 //--------------------------------- 00174 //--- Referenceable methods 00175 //--------------------------------- 00183 public Reference getReference() throws NamingException 00184 { 00185 Reference ref = new Reference(getClass().getName(), FACTORY_CLASSNAME, null); 00186 ref.add(new StringRefAddr(DESCRIPTION_PROPERTY, getDescription())); 00187 ref.add(new StringRefAddr(USER_PROPERTY, getUser())); 00188 ref.add(new StringRefAddr(PASSWORD_PROPERTY, password)); 00189 ref.add(new StringRefAddr(URL_PROPERTY, getUrl())); 00190 return ref; 00191 } 00192 00193 //--------------------------------- 00194 //--- Properties methods 00195 //--------------------------------- 00196 00202 public String getDescription() 00203 { 00204 return "C-JDBC " + driver.getMajorVersion() + "." 00205 + driver.getMinorVersion() + " Datasource"; 00206 } 00207 00215 public void setUrl(String url) 00216 { 00217 this.url = url; 00218 } 00219 00227 public void setURL(String url) 00228 { 00229 setUrl(url); 00230 } 00231 00238 public String getUrl() 00239 { 00240 return url; 00241 } 00242 00249 public String getURL() 00250 { 00251 return getUrl(); 00252 } 00253 00262 public void setUser(String userName) 00263 { 00264 user = userName; 00265 } 00266 00273 public String getUser() 00274 { 00275 return user; 00276 } 00277 00287 public void setPassword(String pwd) 00288 { 00289 password = pwd; 00290 } 00291 00292 //--------------------------------- 00293 //--- Protected methods 00294 //--------------------------------- 00302 protected java.sql.Connection getConnection(Properties props) 00303 throws SQLException 00304 { 00305 return driver.connect(url, props); 00306 } 00307 00308 }

CJDBCversion1.0.4に対してTue Oct 12 15:16:05 2004に生成されました。 doxygen 1.3.8