1 19 20 package org.netbeans.api.db.explorer; 21 22 import java.sql.Connection ; 23 import org.netbeans.modules.db.explorer.ConnectionList; 24 import org.netbeans.modules.db.explorer.DatabaseConnectionAccessor; 25 26 45 public final class DatabaseConnection { 46 47 private org.netbeans.modules.db.explorer.DatabaseConnection delegate; 48 49 61 62 static { 63 DatabaseConnectionAccessor.DEFAULT = new DatabaseConnectionAccessor() { 64 public DatabaseConnection createDatabaseConnection(org.netbeans.modules.db.explorer.DatabaseConnection conn) { 65 return new DatabaseConnection(conn); 66 } 67 }; 68 } 69 70 73 DatabaseConnection(org.netbeans.modules.db.explorer.DatabaseConnection delegate) { 74 assert delegate != null; 75 this.delegate = delegate; 76 } 77 78 81 org.netbeans.modules.db.explorer.DatabaseConnection getDelegate() { 82 return delegate; 83 } 84 85 98 public static DatabaseConnection create(JDBCDriver driver, String databaseURL, 99 String user, String schema, String password, boolean rememberPassword) { 100 if (driver == null || databaseURL == null) { 101 throw new NullPointerException (); 102 } 103 org.netbeans.modules.db.explorer.DatabaseConnection conn = new org.netbeans.modules.db.explorer.DatabaseConnection(); 104 conn.setDriverName(driver.getName()); 105 conn.setDriver(driver.getClassName()); 106 conn.setDatabase(databaseURL); 107 conn.setUser(user); 108 conn.setSchema(schema); 109 conn.setPassword(password); 110 conn.setRememberPassword(rememberPassword); 111 112 return conn.getDatabaseConnection(); 113 } 114 115 120 public String getDriverClass() { 121 return delegate.getDriver(); 122 } 123 124 129 public String getDatabaseURL() { 130 return delegate.getDatabase(); 131 } 132 133 138 public String getSchema() { 139 return delegate.getSchema(); 140 } 141 142 147 public String getUser() { 148 return delegate.getUser(); 149 } 150 151 156 public String getPassword() { 157 return delegate.getPassword(); 158 } 159 160 165 public String getName() { 166 return delegate.getName(); 167 } 168 169 174 public String getDisplayName() { 175 return delegate.getName(); 176 } 177 178 198 public Connection getJDBCConnection() { 199 if (!ConnectionList.getDefault().contains(delegate)) { 200 throw new IllegalStateException ("This connection is not added to the ConnectionManager."); } 202 return delegate.getJDBCConnection(); 203 } 204 205 208 public String toString() { 209 return "DatabaseConnection[name='" + getName() + "']"; } 211 } 212 | Popular Tags |