1 22 23 package org.continuent.sequoia.driver; 24 25 import java.io.PrintWriter ; 26 import java.io.Serializable ; 27 import java.sql.SQLException ; 28 import java.util.Properties ; 29 30 import javax.naming.NamingException ; 31 import javax.naming.Reference ; 32 import javax.naming.Referenceable ; 33 import javax.naming.StringRefAddr ; 34 35 45 public class DataSource 46 implements 47 javax.sql.DataSource , 48 Referenceable , 49 Serializable  50 { 51 private static final long serialVersionUID = 7103360001817804513L; 52 53 54 protected static final String URL_PROPERTY = "url"; 55 protected static final String USER_PROPERTY = Driver.USER_PROPERTY; 56 protected static final String PASSWORD_PROPERTY = Driver.PASSWORD_PROPERTY; 57 protected static final String DRIVER_CLASSNAME = "org.continuent.sequoia.driver.Driver"; 58 protected static final String FACTORY_CLASSNAME = "org.continuent.sequoia.driver.DataSourceFactory"; 59 protected static final String DESCRIPTION_PROPERTY = "description"; 60 61 62 protected static Driver driver = null; 63 static 64 { 65 try 66 { 67 driver = (Driver) Class.forName(DRIVER_CLASSNAME).newInstance(); 68 } 69 catch (Exception e) 70 { 71 throw new RuntimeException ("Can't load " + DRIVER_CLASSNAME); 72 } 73 } 74 75 76 protected String url = null; 77 protected String user = null; 78 protected String password = null; 79 protected PrintWriter logWriter = null; 80 81 84 public DataSource() 85 { 86 } 87 88 98 public java.sql.Connection getConnection() throws SQLException  99 { 100 return getConnection(user, password); 101 } 102 103 112 public java.sql.Connection getConnection(String user, String password) 113 throws SQLException  114 { 115 if (user == null) 116 { 117 user = ""; 118 } 119 if (password == null) 120 { 121 password = ""; 122 } 123 Properties props = new Properties (); 124 props.put(USER_PROPERTY, user); 125 props.put(PASSWORD_PROPERTY, password); 126 127 return getConnection(props); 128 } 129 130 136 public void setLogWriter(PrintWriter output) throws SQLException  137 { 138 logWriter = output; 139 } 140 141 146 public java.io.PrintWriter getLogWriter() 147 { 148 return logWriter; 149 } 150 151 157 public void setLoginTimeout(int seconds) throws SQLException  158 { 159 } 160 161 167 public int getLoginTimeout() throws SQLException  168 { 169 return 0; 170 } 171 172 182 public Reference getReference() throws NamingException  183 { 184 Reference ref = new Reference (getClass().getName(), FACTORY_CLASSNAME, null); 185 ref.add(new StringRefAddr (DESCRIPTION_PROPERTY, getDescription())); 186 ref.add(new StringRefAddr (USER_PROPERTY, getUser())); 187 ref.add(new StringRefAddr (PASSWORD_PROPERTY, password)); 188 ref.add(new StringRefAddr (URL_PROPERTY, getUrl())); 189 return ref; 190 } 191 192 196 201 public String getDescription() 202 { 203 return "Sequoia " + driver.getMajorVersion() + "." 204 + driver.getMinorVersion() + " Datasource"; 205 } 206 207 214 public void setUrl(String url) 215 { 216 this.url = url; 217 } 218 219 226 public void setURL(String url) 227 { 228 setUrl(url); 229 } 230 231 237 public String getUrl() 238 { 239 return url; 240 } 241 242 248 public String getURL() 249 { 250 return getUrl(); 251 } 252 253 261 public void setUser(String userName) 262 { 263 user = userName; 264 } 265 266 272 public String getUser() 273 { 274 return user; 275 } 276 277 286 public void setPassword(String pwd) 287 { 288 password = pwd; 289 } 290 291 301 protected java.sql.Connection getConnection(Properties props) 302 throws SQLException  303 { 304 return driver.connect(url, props); 305 } 306 307 } 308 | Popular Tags |