1 package in.co.daffodil.db.jdbc; 2 3 import java.io.*; 4 import java.sql.*; 5 import java.sql.Connection ; 6 import java.util.*; 7 import javax.sql.*; 8 import javax.naming.*; 9 import com.daffodilwoods.daffodildb.server.serversystem._Server; 10 19 20 public class DBDataSource implements DataSource,Referenceable, java.io.Serializable { 21 22 protected String user; 23 protected String password; 24 protected String databaseName; 25 private String databaseHome; 26 private String description; 27 protected boolean createDatabase; 28 private Properties props = null; 29 private String defaultSchema = null; 30 31 protected int loginTimeout; 32 protected transient PrintWriter logWriter; 33 protected transient AbstractDaffodilDBDriver driver; 34 35 public DBDataSource(){ 36 user = ""; 37 password = ""; 38 databaseHome = null; 39 databaseName = ""; 40 driver = new DaffodilDBDriver(); 41 } 42 43 public Connection getConnection() throws SQLException { 44 return getConnection(user,password); 45 } 46 47 public Connection getConnection(String username, String passwd) throws SQLException { 48 return getConnection(getConnectionProperties()); 49 } 50 51 protected Connection getConnection(java.util.Properties props) throws SQLException { 52 return driver.getConnection(null, props); 53 } 54 55 public PrintWriter getLogWriter() throws SQLException { 56 return logWriter; 57 } 58 59 public int getLoginTimeout() throws SQLException { 60 return loginTimeout; 61 } 62 63 public void setLogWriter(PrintWriter parm1) throws SQLException { 64 logWriter = parm1; 65 } 66 67 public void setLoginTimeout(int parm1) throws SQLException { 68 loginTimeout = parm1; 69 } 70 71 public String getUser(){ 72 return user; 73 } 74 75 public void setUser(String user0){ 76 user = user0; 77 } 78 79 public String getPassword(){ 80 return password; 81 } 82 83 public void setPassword(String password0){ 84 password = password0; 85 } 86 87 public String getDatabaseName(){ 88 return databaseName; 89 } 90 91 public void setDatabaseName(String dbName){ 92 databaseName = dbName; 93 } 94 95 public String getDatabaseHome(){ 96 return databaseHome; 97 } 98 99 public void setDatabaseHome(String dbHome){ 100 databaseHome = dbHome; 101 } 102 103 public void setCreateDatabase(String flag) { 104 createDatabase = flag.trim().equals("true"); 105 } 106 107 public boolean getCreateDatabase() { 108 return createDatabase; 109 } 110 111 protected Properties getConnectionProperties() throws SQLException{ 112 if(props == null){ 113 props = new Properties(); 114 props.put("user", user); 115 props.put("password", password); 116 props.put(DaffodilDBDriver.DATABASE_NAME_PROPERTY, databaseName); 117 if (databaseHome != null) 118 props.put(DaffodilDBDriver.DATABASE_HOME_PROPERTY, databaseHome); 119 props.put(DaffodilDBDriver.DATABASE_CREATE_PROPERTY, 120 createDatabase ? "true" : "false"); 121 if(defaultSchema != null) 122 props.put("schema",defaultSchema); 123 } 124 return props; 125 } 126 127 void setServer(_Server server){ 128 driver.setServer(server); 129 } 130 131 _Server getServer() throws SQLException { 132 Properties pr = getConnectionProperties(); 133 String aa = pr.getProperty("rmiStr",""); 134 String url = aa.length() == 0 ? aa : ("rmi:" + aa +"/DaffodilDB"); 135 return driver.getServer(url); 136 } 137 public void setDefaultSchema(String defaultSchema){ 138 this.defaultSchema=defaultSchema; 139 } 140 public String getDefaultSchema(){ 141 return defaultSchema; 142 } 143 144 public Reference getReference() throws NamingException{ 145 String factoryName = "in.co.daffodil.db.rmi.DataSourceFactory"; 146 Reference reference = new Reference(getClass().getName(), factoryName, null); 147 reference.add(new StringRefAddr("user",user)); 148 reference.add(new StringRefAddr("password",password)); 149 reference.add(new StringRefAddr("databaseName",databaseName)); 150 reference.add(new StringRefAddr("createDatabase",createDatabase ? "true":"false")); 151 reference.add(new StringRefAddr("databaseHome",databaseHome)); 152 return reference; 153 } 154 } 155 | Popular Tags |