git_sitools_idoc / flarecast / workspace / sitools-install-izpack / src / fr / cnes / sitools / izpack / model / FileJDBCConnectionModel.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 FileJDBCConnectionModel 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_FILE_PATH = "input.database.filepath"; |
37 |
/** The db name */
|
38 |
public static final String ID_DB_NAME = "input.database.name"; |
39 |
/** The db schema */
|
40 |
public static final String ID_DB_SCHEMA = "input.database.schema"; |
41 |
/** The db user */
|
42 |
public static final String ID_DB_USER = "db_user"; |
43 |
/** The db password */
|
44 |
public static final String ID_DB_PASSWORD = "db_pwd"; |
45 |
|
46 |
/** The db url */
|
47 |
private String dbUrl; |
48 |
/** The db username */
|
49 |
private String dbUser; |
50 |
/** The db password */
|
51 |
private String dbPassword; |
52 |
/** The db driver class name */
|
53 |
private String dbDriverClassName; |
54 |
/** The db driver class name */
|
55 |
private String dbType; |
56 |
/** The db url */
|
57 |
private String dbSchema; |
58 |
|
59 |
/** The hsqldb */
|
60 |
private final String hsqldbDriverClassName = "org.hsqldb.jdbcDriver"; |
61 |
|
62 |
/**
|
63 |
* Constructor with AutomatedInstallData IzPack data
|
64 |
*
|
65 |
* @param aid
|
66 |
* the AutomatedInstallData
|
67 |
*/
|
68 |
public FileJDBCConnectionModel(AutomatedInstallData aid) {
|
69 |
String type = aid.getVariable(ID_DB_TYPE);
|
70 |
String filePath = aid.getVariable(ID_DB_FILE_PATH);
|
71 |
String name = aid.getVariable(ID_DB_NAME);
|
72 |
String schema = aid.getVariable(ID_DB_SCHEMA);
|
73 |
|
74 |
String user = aid.getVariable(ID_DB_USER);
|
75 |
String password = aid.getVariable(ID_DB_PASSWORD);
|
76 |
|
77 |
constructor(type, filePath, name, schema, user, password); |
78 |
} |
79 |
|
80 |
/**
|
81 |
* Model to represent a connection to the database
|
82 |
*
|
83 |
* @param type
|
84 |
* the type of the database (mysql or postgresql)
|
85 |
* @param host
|
86 |
* the host of the database
|
87 |
* @param port
|
88 |
* the port of the database
|
89 |
* @param name
|
90 |
* the name of the database
|
91 |
* @param schema
|
92 |
* the schema of the database
|
93 |
* @param dbUser
|
94 |
* the user of the database
|
95 |
* @param dbPassword
|
96 |
* the password of the database
|
97 |
*/
|
98 |
public FileJDBCConnectionModel(String type, String filePath, String name, String schema, String dbUser, |
99 |
String dbPassword) {
|
100 |
constructor(type, filePath, name, schema, dbUser, dbPassword); |
101 |
} |
102 |
|
103 |
/**
|
104 |
* Model to represent a connection to the database
|
105 |
*
|
106 |
* @param type
|
107 |
* the type of the database (mysql or postgresql)
|
108 |
* @param host
|
109 |
* the host of the database
|
110 |
* @param port
|
111 |
* the port of the database
|
112 |
* @param name
|
113 |
* the name of the database
|
114 |
* @param schema
|
115 |
* the schema of the database
|
116 |
* @param dbUser
|
117 |
* the user of the database
|
118 |
* @param dbPassword
|
119 |
* the password of the database
|
120 |
*/
|
121 |
public void constructor(String type, String filePath, String name, String schema, String dbUser, String dbPassword) { |
122 |
this.dbUser = dbUser;
|
123 |
this.dbPassword = dbPassword;
|
124 |
|
125 |
String url = "jdbc:" + type + ":file://" + filePath + "/" + name; |
126 |
|
127 |
if ("hsqldb".equals(type)) { |
128 |
this.dbDriverClassName = this.hsqldbDriverClassName; |
129 |
} |
130 |
|
131 |
this.dbUrl = url;
|
132 |
this.dbType = type;
|
133 |
this.dbSchema = schema;
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* Gets the dbUrl value
|
138 |
*
|
139 |
* @return the dbUrl
|
140 |
*/
|
141 |
public String getDbUrl() { |
142 |
return dbUrl;
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* Sets the value of dbUrl
|
147 |
*
|
148 |
* @param dbUrl
|
149 |
* the dbUrl to set
|
150 |
*/
|
151 |
public void setDbUrl(String dbUrl) { |
152 |
this.dbUrl = dbUrl;
|
153 |
} |
154 |
|
155 |
/**
|
156 |
* Gets the dbUser value
|
157 |
*
|
158 |
* @return the dbUser
|
159 |
*/
|
160 |
public String getDbUser() { |
161 |
return dbUser;
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* Sets the value of dbUser
|
166 |
*
|
167 |
* @param dbUser
|
168 |
* the dbUser to set
|
169 |
*/
|
170 |
public void setDbUser(String dbUser) { |
171 |
this.dbUser = dbUser;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* Gets the dbPassword value
|
176 |
*
|
177 |
* @return the dbPassword
|
178 |
*/
|
179 |
public String getDbPassword() { |
180 |
return dbPassword;
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* Sets the value of dbPassword
|
185 |
*
|
186 |
* @param dbPassword
|
187 |
* the dbPassword to set
|
188 |
*/
|
189 |
public void setDbPassword(String dbPassword) { |
190 |
this.dbPassword = dbPassword;
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* Gets the dbDriverClassName value
|
195 |
*
|
196 |
* @return the dbDriverClassName
|
197 |
*/
|
198 |
public String getDbDriverClassName() { |
199 |
return dbDriverClassName;
|
200 |
} |
201 |
|
202 |
/**
|
203 |
* Sets the value of dbDriverClassName
|
204 |
*
|
205 |
* @param dbDriverClassName
|
206 |
* the dbDriverClassName to set
|
207 |
*/
|
208 |
public void setDbDriverClassName(String dbDriverClassName) { |
209 |
this.dbDriverClassName = dbDriverClassName;
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* Sets the value of dbType
|
214 |
*
|
215 |
* @param dbType
|
216 |
* the dbType to set
|
217 |
*/
|
218 |
public void setDbType(String dbType) { |
219 |
this.dbType = dbType;
|
220 |
} |
221 |
|
222 |
/**
|
223 |
* Gets the dbType value
|
224 |
*
|
225 |
* @return the dbType
|
226 |
*/
|
227 |
public String getDbType() { |
228 |
return dbType;
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* Sets the value of dbSchema
|
233 |
*
|
234 |
* @param dbSchema
|
235 |
* the dbSchema to set
|
236 |
*/
|
237 |
public void setDbSchema(String dbSchema) { |
238 |
this.dbSchema = dbSchema;
|
239 |
} |
240 |
|
241 |
/**
|
242 |
* Gets the dbSchema value
|
243 |
*
|
244 |
* @return the dbSchema
|
245 |
*/
|
246 |
public String getDbSchema() { |
247 |
return dbSchema;
|
248 |
} |
249 |
|
250 |
@Override
|
251 |
public String getDbConnectionPassword() { |
252 |
// HSQLDB first connexion password is empty
|
253 |
return ""; |
254 |
} |
255 |
|
256 |
} |