1 30 31 32 package org.hsqldb.jdbc; 33 34 import java.io.PrintWriter ; 35 import java.io.Serializable ; 36 import java.sql.Connection ; 37 import java.sql.SQLException ; 38 import java.util.Properties ; 39 40 import javax.naming.NamingException ; 41 import javax.naming.Reference ; 42 import javax.naming.Referenceable ; 43 import javax.naming.StringRefAddr ; 44 import javax.sql.DataSource ; 45 46 import org.hsqldb.jdbcDriver; 47 48 50 94 public class jdbcDataSource 95 implements Serializable , Referenceable , DataSource { 96 97 100 private int loginTimeout = 0; 101 102 105 private transient PrintWriter logWriter; 106 107 110 private String password = ""; 111 112 115 private String user = ""; 116 117 120 private String database = ""; 121 122 125 public jdbcDataSource() {} 126 127 134 public Connection getConnection() throws SQLException { 135 return getConnection(user, password); 136 } 137 138 148 public Connection getConnection(String username, 149 String password) throws SQLException { 150 151 Properties props = new Properties (); 152 153 if (username != null) { 154 props.put("user", username); 155 } 156 157 if (password != null) { 158 props.put("password", password); 159 } 160 161 return jdbcDriver.getConnection(database, props); 162 } 163 164 169 public String getDatabase() { 170 return database; 171 } 172 173 185 public int getLoginTimeout() throws SQLException { 186 return 0; 187 } 188 189 209 public java.io.PrintWriter getLogWriter() throws SQLException { 210 return logWriter; 211 } 212 213 public Reference getReference() throws NamingException { 215 216 String cname = "org.hsqldb.jdbc.jdbcDataSourceFactory"; 217 Reference ref = new Reference (getClass().getName(), cname, null); 218 219 ref.add(new StringRefAddr ("database", getDatabase())); 220 ref.add(new StringRefAddr ("user", getUser())); 221 ref.add(new StringRefAddr ("password", password)); 222 223 return ref; 224 } 225 226 231 public String getUser() { 232 return user; 233 } 234 235 242 public void setDatabase(String database) { 243 this.database = database; 244 } 245 246 258 public void setLoginTimeout(int seconds) throws SQLException { 259 loginTimeout = 0; 260 } 261 262 281 public void setLogWriter(PrintWriter logWriter) throws SQLException { 282 this.logWriter = logWriter; 283 } 284 285 289 public void setPassword(String password) { 290 this.password = password; 291 } 292 293 297 public void setUser(String user) { 298 this.user = user; 299 } 300 } 301 | Popular Tags |