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