Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/hsql/jdbcDataSource.java


1   package org.hsql;
2   
3   import java.io.Serializable;
4   import java.io.PrintWriter;
5   import javax.naming.*;
6   import java.sql.*;
7   import javax.sql.DataSource;
8   
9   /**
10   * Insert the type's description here.
11   * Creation date: (10/19/2000 2:26:43 PM)
12   * @author:
13   */
14  public class jdbcDataSource implements Serializable, Referenceable, DataSource {
15      /** Login timeout
16      */
17      private int loginTimeout=0;
18      /** Log writer
19      */
20      private transient PrintWriter logWriter;
21      /** Default password to use for connections
22      */
23      private           String      password     = "";
24      /** Default user to use for connections
25      */
26      private           String      user         = "";
27      /** Signature
28      */
29        private final static String sStartURL="jdbc:HypersonicSQL:";
30      /** Database location
31      */
32      private String database="";
33  /** Constructor
34   */
35  public jdbcDataSource() {
36  }
37  /** Forward with current user/password
38  */
39  public Connection getConnection() throws java.sql.SQLException {
40      return getConnection(user, password);
41  }
42  /**
43   * getConnection method comment.
44   */
45  public Connection getConnection(String user, String password) throws SQLException {
46      if(user==null) {
47        user="";
48      }
49      if(password==null) {
50        password="";
51      }
52      return new jdbcConnection(database,user,password);
53  }
54  /** Return database
55  */
56  public String getDatabase(){
57      return database;
58  }
59  /**
60   * getLoginTimeout method comment.
61   */
62  public int getLoginTimeout() throws java.sql.SQLException {
63      return loginTimeout;
64  }
65  /**
66   * getLogWriter method comment.
67   */
68  public java.io.PrintWriter getLogWriter() throws java.sql.SQLException {
69      return null;
70  }
71  /**
72   * getReference method comment.
73   */
74  public Reference getReference() throws NamingException {
75      String cname = "org.hsql.jdbcDataSourceFactory";
76      Reference ref = new Reference(getClass().getName(), cname, null);
77      ref.add(new StringRefAddr("database", getDatabase()));
78      ref.add(new StringRefAddr("user", getUser()));
79      ref.add(new StringRefAddr("password", password));
80      return ref;
81  }
82  /** @return user ID for the connection
83    */
84  public String getUser() {
85      return user;
86  }
87  /** Set database location
88  */
89  public void setDatabase(String database){
90      this.database=database;
91  }
92  /** Not yet implemented
93   */
94  public void setLoginTimeout(int ignore) throws java.sql.SQLException {
95      this.loginTimeout=ignore;
96  }
97  /**
98   * setLogWriter method comment.
99   */
100 public void setLogWriter(PrintWriter logWriter) throws java.sql.SQLException {
101     this.logWriter=logWriter;
102 }
103 /** Sets the password to use for connecting to the database
104   * @param password the password
105   */
106 public void setPassword(String password) {
107     this.password = password;
108 }
109 /** Sets the userid
110   * @param user the user id
111   */
112 public void setUser(String user) {
113     this.user = user;
114 }
115 }