1 28 29 package com.caucho.sql; 30 31 import com.caucho.log.Log; 32 import com.caucho.util.L10N; 33 34 import javax.resource.ResourceException ; 35 import javax.resource.spi.ConnectionManager ; 36 import javax.sql.DataSource ; 37 import java.io.PrintWriter ; 38 import java.sql.Connection ; 39 import java.sql.SQLException ; 40 import java.util.logging.Logger ; 41 42 45 public class DataSourceImpl implements DataSource { 46 protected static final Logger log = Log.open(DataSourceImpl.class); 47 private static final L10N L = new L10N(DataSourceImpl.class); 48 49 private ManagedFactoryImpl _managedFactory; 50 private ConnectionManager _connManager; 51 52 DataSourceImpl(ManagedFactoryImpl factory, ConnectionManager cm) 53 { 54 _managedFactory = factory; 55 _connManager = cm; 56 } 57 58 61 public Connection getConnection() 62 throws SQLException 63 { 64 try { 65 return (Connection ) _connManager.allocateConnection(_managedFactory, 66 null); 67 } catch (ResourceException e) { 68 Throwable cause; 69 70 for (cause = e; cause != null; cause = cause.getCause()) { 71 if (cause instanceof SQLException ) 72 throw (SQLException ) cause; 73 } 74 75 throw new SQLExceptionWrapper(e); 76 } 77 } 78 79 82 public Connection getConnection(String username, String password) 83 throws SQLException 84 { 85 try { 86 Credential credential = null; 87 88 if (username != null && password != null) 89 credential = new Credential(username, password); 90 91 return (Connection ) _connManager.allocateConnection(_managedFactory, 92 credential); 93 } catch (ResourceException e) { 94 Throwable cause; 95 96 for (cause = e; cause != null; cause = cause.getCause()) { 97 if (cause instanceof SQLException ) 98 throw (SQLException ) cause; 99 } 100 101 throw new SQLExceptionWrapper(e); 102 } 103 } 104 105 108 public int getLoginTimeout() 109 { 110 return 0; 111 } 112 113 116 public void setLoginTimeout(int seconds) 117 { 118 } 119 120 123 public PrintWriter getLogWriter() 124 { 125 return null; 126 } 127 128 131 public void setLogWriter(PrintWriter out) 132 { 133 } 134 135 138 boolean isClosed() 139 { 140 return false; 141 } 142 } 143 144 | Popular Tags |