001: package org.dbbrowser.drivermanager;
002:
003: import java.io.File;
004: import java.io.Serializable;
005: import java.util.Date;
006:
007: /**
008: * A connection info class represents the details of a JDBC connection to a database
009: * @author amangat
010: *
011: */
012: public class ConnectionInfo implements Serializable {
013: public static final String DES56C_ENCRYPTION_ALGORITHM = "DES56C";
014: public static final String DES40C_ENCRYPTION_ALGORITHM = "DES40C";
015: public static final String RC4_40_ENCRYPTION_ALGORITHM = "RC4_40";
016: public static final String RC4_56_ENCRYPTION_ALGORITHM = "RC4_56";
017:
018: public static final String MD5_CHECK_SUM_ALGORITHM = "MD5";
019:
020: public static final String[] LIST_OF_ENCRYPTION_ALGORITHMS = new String[] {
021: DES56C_ENCRYPTION_ALGORITHM, DES40C_ENCRYPTION_ALGORITHM,
022: RC4_40_ENCRYPTION_ALGORITHM, RC4_56_ENCRYPTION_ALGORITHM };
023: public static final String[] LIST_OF_CHECKSUM_ALGORITHMS = new String[] { MD5_CHECK_SUM_ALGORITHM };
024:
025: private String driverClassName = null;
026: private File jdbcDriverJarFileLocation = null;
027: private String name = null;
028: private String dbmsType = null;
029: private String databaseURL = null;
030: private String username = null;
031: private String password = null;
032: private Date lastUsed = null;
033: private String encryptionAlgorithm = null;
034: private String checkSumAlgorithm = null;
035:
036: private static final long serialVersionUID = 1l;
037:
038: /**
039: * Constrcuter
040: * @param driverClassName
041: * @param jdbcDriverJarFileLocation
042: * @param name
043: * @param dbmsType
044: * @param databaseURL
045: * @param username
046: * @param password
047: * @param encryptionAlgorithm
048: * @param checkSumAlgorithm
049: */
050: public ConnectionInfo(String driverClassName,
051: File jdbcDriverJarFileLocation, String name,
052: String dbmsType, String databaseURL, String username,
053: String passwordString, String encryptionAlgorithm,
054: String checkSumAlgorithm) {
055: this .driverClassName = driverClassName;
056: this .jdbcDriverJarFileLocation = jdbcDriverJarFileLocation;
057: this .name = name;
058: this .dbmsType = dbmsType;
059: this .databaseURL = databaseURL;
060: this .username = username;
061: this .password = passwordString;
062: this .encryptionAlgorithm = encryptionAlgorithm;
063: this .checkSumAlgorithm = checkSumAlgorithm;
064: }
065:
066: /**
067: * Return the time this connection was last used
068: * @return
069: */
070: public Date getLastUsed() {
071: return this .lastUsed;
072: }
073:
074: /**
075: * Update the last time this connection was used
076: * @param updatedLastUsedDate
077: */
078: public void setLastUsed(Date updatedLastUsedDate) {
079: this .lastUsed = updatedLastUsedDate;
080: }
081:
082: /**
083: * Get the driver class name, e.g. 'oracle.jdbc.OracleDriver'
084: * @return
085: */
086: public String getDriverClassName() {
087: return this .driverClassName;
088: }
089:
090: /**
091: * Get the location fo the jar file, e.g. c:/drivers/ojdbc14.jar
092: * @return
093: */
094: public File getJdbcDriverJarFileLocation() {
095: return this .jdbcDriverJarFileLocation;
096: }
097:
098: /**
099: * Get the name specified for this connection - any unique name. E.g. 'Oracle connection to my database'
100: * @return
101: */
102: public String getName() {
103: return this .name;
104: }
105:
106: /**
107: * Return the dbms type - e.g. Oracle, MySQL
108: * @return
109: */
110: public String getDBMSType() {
111: return this .dbmsType;
112: }
113:
114: /**
115: * Get the database URL
116: * @return
117: */
118: public String getDatabaseURL() {
119: return this .databaseURL;
120: }
121:
122: /**
123: * get the username
124: * @return
125: */
126: public String getUsername() {
127: return this .username;
128: }
129:
130: /**
131: * Get the password
132: * @return
133: */
134: public String getPassword() {
135: return this .password;
136: }
137:
138: /**
139: * Returns the encryption algorithm used, or null if there is no encryption required
140: * @return
141: */
142: public String getEncryptionAlgorithm() {
143: return this .encryptionAlgorithm;
144: }
145:
146: /**
147: * Returns the checkSumAlgorithm, or null if no check sum is in use
148: * @return
149: */
150: public String getCheckSumAlgorithm() {
151: return this .checkSumAlgorithm;
152: }
153:
154: /**
155: * Overrides the hashCode method of Object so it can be used as a key in a hashtable
156: */
157: public int hashCode() {
158: return this .driverClassName.hashCode()
159: + this .databaseURL.hashCode()
160: + this .username.hashCode() + this .password.hashCode();
161: }
162:
163: /**
164: * Overrides the equals method of Object so it can be used as a key in a hashtable. Only
165: * uses the connectionInfo.getName() to make the comparision. If 2 connection info objects have the same name,
166: * they are equal. The name uniquely identifies the connection info object
167: */
168: public boolean equals(Object obj) {
169: boolean equal = false;
170: if (obj instanceof ConnectionInfo) {
171: ConnectionInfo otherConnectionInfo = (ConnectionInfo) obj;
172: String otherConnectionInfoName = otherConnectionInfo
173: .getName();
174: if (this .getName().equals(otherConnectionInfoName)) {
175: equal = true;
176: }
177: }
178: return equal;
179: }
180:
181: /**
182: * For debugging only
183: * @return
184: */
185: public String toString() {
186: StringBuffer buffer = new StringBuffer();
187: buffer.append("Connection Info\n");
188: buffer.append("Name: " + this .getName() + "\n");
189: buffer.append("DBMS Type: " + this .getDBMSType() + "\n");
190: buffer.append("Database URL: " + this .getDatabaseURL() + "\n");
191: buffer.append("Driver class: " + this .getDriverClassName()
192: + "\n");
193: buffer
194: .append("JDBC Jar location: "
195: + this .getJdbcDriverJarFileLocation()
196: .toString() + "\n");
197: buffer.append("Username: " + this .getUsername() + "\n");
198: buffer.append("Password: " + this .getPassword() + "\n");
199: buffer.append("Last used: " + this .getLastUsed() + "\n");
200: buffer.append("Encryption algorithm: "
201: + this .getEncryptionAlgorithm() + "\n");
202: buffer.append("Checksum algorithm: "
203: + this .getCheckSumAlgorithm() + "\n");
204:
205: return buffer.toString();
206: }
207: }
|