001 package com.sptci.rwt;
002
003 import java.io.Serializable;
004
005 /**
006 * A simple value object used to represent the data required to initiate
007 * a connection to a database. T
008 * be obtained through {@link javax.sql.DataSource} or {@link
009 * java.sql.DriverManager}.
010 *
011 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
012 * @author Rakesh Vidyadharan 2007-09-24
013 * @version $Id: ConnectionParameters.java 4123 2008-05-25 21:49:01Z rakesh $
014 */
015 public class ConnectionParameters implements Serializable
016 {
017 /**
018 * The encoded value used to represent the <code>host</code> part of a
019 * JDBC connection url.
020 *
021 * {@value}
022 */
023 public static final String HOST = "$HOST$";
024
025 /**
026 * The encoded value used to represent the <code>port</code> part of a
027 * JDBC connection url.
028 *
029 * {@value}
030 */
031 public static final String PORT = "$PORT$";
032
033 /**
034 * The encoded value used to represent the <code>database</code> part of a
035 * JDBC connection url.
036 *
037 * {@value}
038 */
039 public static final String DATABASE = "$DATABASE$";
040
041 /**
042 * The fully qualified hostname of the database server to connect to.
043 */
044 public final String host;
045
046 /**
047 * The name of the database to connect to.
048 */
049 public final String database;
050
051 /**
052 * The port to connect to.
053 */
054 public final int port;
055
056 /**
057 * The database user to connect as.
058 */
059 public final String userName;
060
061 /**
062 * The password for the database user to connect as.
063 */
064 public transient final String password;
065
066 /**
067 * The name to use to identify the database engine.
068 */
069 public final String databaseType;
070
071 /**
072 * The JDBC connection url pattern to use. The URL pattern contains
073 * encoded values for variables such as <code>$HOST$</code> etc.
074 */
075 public final String urlPattern;
076
077 /**
078 * The fully qualified name of the JDBC driver class.
079 */
080 public final String driver;
081
082 /**
083 * Designated constructor. Create a new instance with the specified
084 * values.
085 *
086 * @param userName The {@link #userName} value to use.
087 * @param password The {@link #password} value to use.
088 * @param host The {@link #host} value to use.
089 * @param port The {@link #port} value to use.
090 * @param database The {@link #database} value to use.
091 * @param urlPattern The {@link #urlPattern} value to use.
092 */
093 public ConnectionParameters( final String userName, final String password,
094 final String host, final int port, final String database,
095 final String databaseType, final String urlPattern,
096 final String driver )
097 {
098 this.userName = userName;
099 this.password = password;
100 this.host = host;
101 this.port = port;
102 this.database = database;
103 this.databaseType = databaseType;
104 this.urlPattern = urlPattern;
105 this.driver = driver;
106 }
107
108 /**
109 * Return the proper JDBC connection url after replacing place holders
110 * in {@link #urlPattern}.
111 *
112 * @return The proper connection url.
113 */
114 public String getUrl()
115 {
116 String url = urlPattern.replace( HOST, host );
117 url = url.replace( DATABASE, database );
118 url = url.replace( PORT, String.valueOf( port ) );
119 return url;
120 }
121 }