1 29 30 package com.caucho.db.jdbc; 31 32 import com.caucho.db.Database; 33 import com.caucho.log.Log; 34 import com.caucho.util.L10N; 35 import com.caucho.vfs.Path; 36 37 import javax.sql.DataSource ; 38 import java.io.PrintWriter ; 39 import java.sql.Connection ; 40 import java.sql.SQLException ; 41 import java.util.logging.Logger ; 42 43 46 public class DataSourceImpl implements DataSource { 47 private static final Logger log = Log.open(DataSourceImpl.class); 48 private static final L10N L = new L10N(DataSourceImpl.class); 49 50 private Database _database; 51 52 private boolean _createDatabase; 53 private boolean _isInit; 54 55 58 public DataSourceImpl() 59 { 60 _database = new Database(); 61 } 62 63 66 public DataSourceImpl(Path path) 67 throws SQLException 68 { 69 this(); 70 71 setPath(path); 72 73 init(); 74 } 75 76 79 public void setPath(Path path) 80 { 81 _database.setPath(path); 82 } 83 84 87 public void setCreateDatabase(boolean create) 88 { 89 _createDatabase = create; 90 } 91 92 95 public void setRemoveOnError(boolean remove) 96 { 97 _database.setRemoveOnError(remove); 98 } 99 100 103 public void init() 104 throws SQLException 105 { 106 synchronized (this) { 107 if (_isInit) 108 return; 109 110 try { 111 _database.init(); 112 } finally { 113 _isInit = true; 114 } 115 } 116 } 117 118 public int getLoginTimeout() 119 { 120 return 0; 121 } 122 123 public void setLoginTimeout(int foo) 124 { 125 } 126 127 public PrintWriter getLogWriter() 128 { 129 return null; 130 } 131 132 public void setLogWriter(PrintWriter log) 133 { 134 } 135 136 139 public Connection getConnection(String user, String password) 140 throws SQLException 141 { 142 return getConnection(); 143 } 144 145 148 public Connection getConnection() 149 throws SQLException 150 { 151 init(); 152 153 return new ConnectionImpl(_database); 154 } 155 156 public void close() 157 { 158 _database.close(); 159 } 160 161 public String toString() 162 { 163 return "DataSourceImpl[" + _database.getPath() + "]"; 164 } 165 166 protected void finalize() 167 throws Throwable 168 { 169 super.finalize(); 170 171 _database.close(); 172 } 173 } 174 | Popular Tags |