git_sitools_idoc / flarecast / workspace / sitools-install-izpack / src / fr / cnes / sitools / izpack / model / RemoteJDBCConnectionModel.java @ master
1 |
/*******************************************************************************
|
---|---|
2 |
* Copyright 2010-2014 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
|
3 |
*
|
4 |
* This file is part of SITools2.
|
5 |
*
|
6 |
* SITools2 is free software: you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* SITools2 is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with SITools2. If not, see <http://www.gnu.org/licenses/>.
|
18 |
******************************************************************************/
|
19 |
package fr.cnes.sitools.izpack.model; |
20 |
|
21 |
import com.izforge.izpack.installer.AutomatedInstallData; |
22 |
|
23 |
/**
|
24 |
* Model to store informations about JDBC connection
|
25 |
*
|
26 |
* @author m.gond
|
27 |
*
|
28 |
*/
|
29 |
public class RemoteJDBCConnectionModel implements JDBCConnectionModel { |
30 |
/**
|
31 |
* Identifier of the IzPack installer form fields
|
32 |
*/
|
33 |
/** The db type */
|
34 |
public static final String ID_DB_TYPE = "input.database.driver"; |
35 |
/** The db host */
|
36 |
public static final String ID_DB_HOST = "input.database.hostname"; |
37 |
/** The db port */
|
38 |
public static final String ID_DB_PORT = "input.database.port"; |
39 |
/** The db name */
|
40 |
public static final String ID_DB_NAME = "input.database.name"; |
41 |
/** The db schema */
|
42 |
public static final String ID_DB_SCHEMA = "input.database.schema"; |
43 |
/** The db user */
|
44 |
public static final String ID_DB_USER = "db_user"; |
45 |
/** The db password */
|
46 |
public static final String ID_DB_PASSWORD = "db_pwd"; |
47 |
|
48 |
/** The db url */
|
49 |
private String dbUrl; |
50 |
/** The db username */
|
51 |
private String dbUser; |
52 |
/** The db password */
|
53 |
private String dbPassword; |
54 |
/** The db driver class name */
|
55 |
private String dbDriverClassName; |
56 |
/** The db driver class name */
|
57 |
private String dbType; |
58 |
/** The db url */
|
59 |
private String dbSchema; |
60 |
|
61 |
/** The postgresql */
|
62 |
private final String postgresqlDriverClassName = "org.postgresql.Driver"; |
63 |
/** The mysql */
|
64 |
private final String mysqlDriverClassName = "org.gjt.mm.mysql.Driver"; |
65 |
|
66 |
|
67 |
/**
|
68 |
* Constructor with AutomatedInstallData IzPack data
|
69 |
*
|
70 |
* @param aid
|
71 |
* the AutomatedInstallData
|
72 |
*/
|
73 |
public RemoteJDBCConnectionModel(AutomatedInstallData aid) {
|
74 |
String type = aid.getVariable(ID_DB_TYPE);
|
75 |
String host = aid.getVariable(ID_DB_HOST);
|
76 |
String port = aid.getVariable(ID_DB_PORT);
|
77 |
String name = aid.getVariable(ID_DB_NAME);
|
78 |
String schema = aid.getVariable(ID_DB_SCHEMA);
|
79 |
|
80 |
String user = aid.getVariable(ID_DB_USER);
|
81 |
String password = aid.getVariable(ID_DB_PASSWORD);
|
82 |
|
83 |
constructor(type, host, port, name, schema, user, password); |
84 |
} |
85 |
|
86 |
/**
|
87 |
* Model to represent a connection to the database
|
88 |
*
|
89 |
* @param type
|
90 |
* the type of the database (mysql or postgresql)
|
91 |
* @param host
|
92 |
* the host of the database
|
93 |
* @param port
|
94 |
* the port of the database
|
95 |
* @param name
|
96 |
* the name of the database
|
97 |
* @param schema
|
98 |
* the schema of the database
|
99 |
* @param dbUser
|
100 |
* the user of the database
|
101 |
* @param dbPassword
|
102 |
* the password of the database
|
103 |
*/
|
104 |
public RemoteJDBCConnectionModel(String type, String host, String port, String name, String schema, String dbUser, |
105 |
String dbPassword) {
|
106 |
constructor(type, host, port, name, schema, dbUser, dbPassword); |
107 |
} |
108 |
|
109 |
/**
|
110 |
* Model to represent a connection to the database
|
111 |
*
|
112 |
* @param type
|
113 |
* the type of the database (mysql or postgresql)
|
114 |
* @param host
|
115 |
* the host of the database
|
116 |
* @param port
|
117 |
* the port of the database
|
118 |
* @param name
|
119 |
* the name of the database
|
120 |
* @param schema
|
121 |
* the schema of the database
|
122 |
* @param dbUser
|
123 |
* the user of the database
|
124 |
* @param dbPassword
|
125 |
* the password of the database
|
126 |
*/
|
127 |
public void constructor(String type, String host, String port, String name, String schema, String dbUser, |
128 |
String dbPassword) {
|
129 |
this.dbUser = dbUser;
|
130 |
this.dbPassword = dbPassword;
|
131 |
|
132 |
String url = "jdbc:" + type + "://" + host + ":" + port + "/" + name; |
133 |
|
134 |
if (schema != null && !"".equals(schema) && !"mysql".equals(type)) { |
135 |
url += "?schema=" + schema;
|
136 |
} |
137 |
|
138 |
if (type.equals("mysql")) { |
139 |
url += "?allowMultiQueries=true";
|
140 |
} |
141 |
|
142 |
if ("mysql".equals(type)) { |
143 |
this.dbDriverClassName = this.mysqlDriverClassName; |
144 |
} |
145 |
else if ("postgresql".equals(type)) { |
146 |
this.dbDriverClassName = this.postgresqlDriverClassName; |
147 |
} |
148 |
|
149 |
this.dbUrl = url;
|
150 |
this.dbType = type;
|
151 |
this.dbSchema = schema;
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* Gets the dbUrl value
|
156 |
*
|
157 |
* @return the dbUrl
|
158 |
*/
|
159 |
public String getDbUrl() { |
160 |
return dbUrl;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* Sets the value of dbUrl
|
165 |
*
|
166 |
* @param dbUrl
|
167 |
* the dbUrl to set
|
168 |
*/
|
169 |
public void setDbUrl(String dbUrl) { |
170 |
this.dbUrl = dbUrl;
|
171 |
} |
172 |
|
173 |
/**
|
174 |
* Gets the dbUser value
|
175 |
*
|
176 |
* @return the dbUser
|
177 |
*/
|
178 |
public String getDbUser() { |
179 |
return dbUser;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* Sets the value of dbUser
|
184 |
*
|
185 |
* @param dbUser
|
186 |
* the dbUser to set
|
187 |
*/
|
188 |
public void setDbUser(String dbUser) { |
189 |
this.dbUser = dbUser;
|
190 |
} |
191 |
|
192 |
/**
|
193 |
* Gets the dbPassword value
|
194 |
*
|
195 |
* @return the dbPassword
|
196 |
*/
|
197 |
public String getDbPassword() { |
198 |
return dbPassword;
|
199 |
} |
200 |
|
201 |
/**
|
202 |
* Sets the value of dbPassword
|
203 |
*
|
204 |
* @param dbPassword
|
205 |
* the dbPassword to set
|
206 |
*/
|
207 |
public void setDbPassword(String dbPassword) { |
208 |
this.dbPassword = dbPassword;
|
209 |
} |
210 |
|
211 |
/**
|
212 |
* Gets the dbDriverClassName value
|
213 |
*
|
214 |
* @return the dbDriverClassName
|
215 |
*/
|
216 |
public String getDbDriverClassName() { |
217 |
return dbDriverClassName;
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* Sets the value of dbDriverClassName
|
222 |
*
|
223 |
* @param dbDriverClassName
|
224 |
* the dbDriverClassName to set
|
225 |
*/
|
226 |
public void setDbDriverClassName(String dbDriverClassName) { |
227 |
this.dbDriverClassName = dbDriverClassName;
|
228 |
} |
229 |
|
230 |
/**
|
231 |
* Sets the value of dbType
|
232 |
*
|
233 |
* @param dbType
|
234 |
* the dbType to set
|
235 |
*/
|
236 |
public void setDbType(String dbType) { |
237 |
this.dbType = dbType;
|
238 |
} |
239 |
|
240 |
/**
|
241 |
* Gets the dbType value
|
242 |
*
|
243 |
* @return the dbType
|
244 |
*/
|
245 |
public String getDbType() { |
246 |
return dbType;
|
247 |
} |
248 |
|
249 |
/**
|
250 |
* Sets the value of dbSchema
|
251 |
*
|
252 |
* @param dbSchema
|
253 |
* the dbSchema to set
|
254 |
*/
|
255 |
public void setDbSchema(String dbSchema) { |
256 |
this.dbSchema = dbSchema;
|
257 |
} |
258 |
|
259 |
/**
|
260 |
* Gets the dbSchema value
|
261 |
*
|
262 |
* @return the dbSchema
|
263 |
*/
|
264 |
public String getDbSchema() { |
265 |
return dbSchema;
|
266 |
} |
267 |
|
268 |
@Override
|
269 |
public String getDbConnectionPassword() { |
270 |
return getDbPassword();
|
271 |
} |
272 |
|
273 |
} |