1 18 19 package org.apache.jmeter.protocol.jdbc.util; 20 21 import java.io.Serializable ; 22 23 public class DBKey implements Serializable { 25 private final String driver; 26 private final String url; 27 private final String username; 28 private final String password; 29 30 34 private transient int hashCode = 0; 35 36 37 public DBKey( 38 String driver, 39 String url, 40 String username, 41 String password) 42 { 43 if (driver == null) 44 { 45 throw new IllegalArgumentException ( 46 "DBKey 'driver' must be non-null"); 47 } 48 49 if (url == null) 50 { 51 throw new IllegalArgumentException ("DBKey 'url' must be non-null"); 52 } 53 54 56 this.driver = driver; 57 this.url = url; 58 this.username = username; 59 this.password = password; 60 61 hashCode = calculateHashCode(); 63 } 64 65 public DBKey(){ 67 this("","","",""); 68 } 69 70 public String getUrl() 71 { 72 return url; 73 } 74 75 public String getUsername() 76 { 77 return username; 78 } 79 80 public String getPassword() 81 { 82 return password; 83 } 84 85 public String getDriver() 86 { 87 return driver; 88 } 89 90 95 public boolean equals(Object o2) 96 { 97 if (this == o2) 98 { 99 return true; 100 } 101 102 if (!(o2 instanceof DBKey)) 103 { 104 return false; 105 } 106 107 DBKey key = (DBKey)o2; 108 109 if (!driver.equals(key.driver)) 110 { 111 return false; 112 } 113 114 if (!url.equals(key.url)) 115 { 116 return false; 117 } 118 119 if (username == null) 120 { 121 if (key.username != null) 122 { 123 return false; 124 } 125 } 126 else 127 { 128 if (!username.equals(key.username)) 129 { 130 return false; 131 } 132 } 133 134 if (password == null) 135 { 136 if (key.password != null) 137 { 138 return false; 139 } 140 } 141 else 142 { 143 if (!password.equals(key.password)) 144 { 145 return false; 146 } 147 } 148 149 return true; 150 } 151 152 public int hashCode() 153 { 154 hashCode = calculateHashCode(); 155 return hashCode; 156 } 157 158 private int calculateHashCode() 159 { 160 int result = 17; 163 164 result = 37 * result + driver.hashCode(); 165 result = 37 * result + url.hashCode(); 166 result = 37 * result + (username == null ? 0 : username.hashCode()); 167 result = 37 * result + (password == null ? 0 : password.hashCode()); 168 169 return result; 170 } 171 172 public String toString() 173 { 174 StringBuffer ret = new StringBuffer (); 175 ret.append("Class=DBKey(" + "\n"); 176 ret.append("driver=" + driver + "\n"); 177 ret.append("url=" + url + "\n"); 178 ret.append("username=" + username + "\n"); 179 ret.append(")"); 180 return ret.toString(); 181 } 182 } 183 | Popular Tags |