64 bit build fix
[csql.git] / src / jdbc / JdbcSqlDataSource.java
blob99a516886f797fa91a3e384f75bb8022a9a41112
1 package csql.jdbc;
3 import java.util.*;
4 import java.sql.*;
5 import javax.sql.*;
6 import javax.naming.*;
7 import java.io.*;
8 import java.lang.*;
9 import java.lang.Class;
10 //import java.sql.SQLException;
12 public class JdbcSqlDataSource implements javax.sql.DataSource, javax.naming.Referenceable, java.io.Serializable
14 static
16 try
18 DriverManager.registerDriver(new JdbcSqlDriver());
20 catch (Exception e)
22 System.out.println ("CSql JDBC Driver: " + e);
26 private String databaseName="csql";
27 private String dataSourceName;
28 private String serverName="localhost";
29 private String password="manager";
30 private String userName="root";
31 private String mode="";
32 transient JdbcSqlDriver driver;
33 transient private PrintWriter printer;
34 private int loginTimeout;
35 private String jdbcurl="jdbc:";
36 private int portno = 5678;
37 boolean explicityUrlUsed=false;
38 private String explicityUrl="";
39 public JdbcSqlDataSource()
45 /* Connection*/
46 public Connection getConnection() throws SQLException
48 return this.getConnection(getUserName(),getPassword());
50 public synchronized Connection getConnection(String username, String password) throws SQLException
52 String url="";
53 if(!explicityUrlUsed){
54 url = jdbcurl+ mode +"://" + serverName + ":" + portno +"/" + databaseName;
55 } else {
56 url = explicityUrl;
58 Properties info = new Properties();
59 if (username != null)
60 info.put("user", username);
61 if (password != null)
62 info.put("password", password);
63 Connection conn = findDriver().connect(url, info);
64 /* if (conn == null)
65 throw ;*/
66 return conn;
69 public void setUrl(String url)
71 if(explicityUrlUsed) {
72 explicityUrl = url;
75 public String getUrl()
77 String url="";
78 if(!explicityUrlUsed){
79 url = jdbcurl+ mode +"://" + serverName + ":" + portno +"/" + databaseName;
80 } else {
81 url = explicityUrl;
83 return url;
86 public void setPort(int port)
88 this.portno = port;
90 public int getPort()
92 return this.portno ;
95 public void setMode(String mode)
97 this.mode = mode;
99 public String getMode()
101 return this.mode ;
104 JdbcSqlDriver findDriver() throws SQLException
106 String url = getUrl();
107 if (driver == null || !driver.acceptsURL(url))
109 //new JdbcSqlDriver();
110 driver=(JdbcSqlDriver) DriverManager.getDriver(url);
112 return driver;
114 public java.io.PrintWriter getLogWriter() throws SQLException
116 return printer;
119 public void setLogWriter(java.io.PrintWriter out)
121 printer = out;
124 public void setLoginTimeout(int seconds)throws SQLException
126 loginTimeout = seconds;
130 public int getLoginTimeout()
132 return loginTimeout;
135 public Reference getReference() throws NamingException
137 Reference ref = new Reference(this.getClass().getName(),"csql.jdbc.JdbcSqlObjectFactory", null);
138 ref.add( new StringRefAddr("serverName", getServerName()) );
139 ref.add( new StringRefAddr("databaseName",getDatabaseName()));
140 ref.add( new StringRefAddr("mode",getMode()));
141 ref.add( new StringRefAddr("port",""+getPort()));
142 ref.add( new StringRefAddr("user",getUserName()));
143 ref.add( new StringRefAddr("password",getPassword()));
144 ref.add( new StringRefAddr("url",getUrl()));
145 return ref;
149 public String getServerName(){
150 return serverName;
153 public void setServerName(String serverName){
154 this.serverName=serverName;
157 public String getDatabaseName(){
158 return databaseName;
161 public void setDatabaseName(String databaseName){
162 this.databaseName=databaseName;
165 public String getUserName()
167 return userName;
170 public void setUserName(String un)
172 this.userName=un;
175 public String getPassword()
177 return password;
180 public void setPassword(String pw)
182 this.password=pw;
185 public boolean isWrapperFor(Class ifact) throws SQLException
188 return ifact.isInstance(this);
191 public <T> T unwrap(java.lang.Class<T> iface) throws SQLException
193 return iface.cast(this);