Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.jdbc / src / main / java / org / gvsig / fmap / dal / store / jdbc / JDBCStoreParameters.java @ 40559

History | View | Annotate | Download (7.91 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program 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 this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
*
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
*
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
*
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
42
* MA  02110-1301, USA.
43
*
44
*/
45

    
46
/*
47
* AUTHORS (In addition to CIT):
48
* 2009 IVER T.I   {{Task}}
49
*/
50

    
51
package org.gvsig.fmap.dal.store.jdbc;
52

    
53
import java.text.MessageFormat;
54

    
55
import org.gvsig.fmap.dal.store.db.DBStoreParameters;
56

    
57
/**
58
 * Parameters class for JDBC generic provider
59
 *
60
 * @author jmvivo
61
 *
62
 */
63
public class JDBCStoreParameters extends DBStoreParameters
64
                implements JDBCConnectionParameters {
65

    
66
        public static final String PARAMETERS_DEFINITION_NAME = "JDBCStoreParameters";
67

    
68
        public JDBCStoreParameters() {
69
                super(PARAMETERS_DEFINITION_NAME,JDBCStoreProvider.NAME);
70
        }
71

    
72
        protected JDBCStoreParameters(String parametersDefinitionName) {
73
                super(parametersDefinitionName,JDBCStoreProvider.NAME);
74
        }
75

    
76
        protected JDBCStoreParameters(String parametersDefinitionName, String providerName) {
77
                super(parametersDefinitionName,providerName);
78
        }
79

    
80
        public boolean isValid() {
81
                return this.getHost() != null;
82
        }
83

    
84
        public String getHost() {
85
                return (String) this.getDynValue(HOST_PARAMTER_NAME);
86
        }
87

    
88
        public Integer getPort() {
89
                return (Integer) this.getDynValue(PORT_PARAMTER_NAME);
90
        }
91

    
92
        public String getDBName() {
93
                return (String) this.getDynValue(DBNAME_PARAMTER_NAME);
94
        }
95

    
96
        public String getUser() {
97
                return (String) this.getDynValue(USER_PARAMTER_NAME);
98
        }
99

    
100
        public String getPassword() {
101
                return (String) this.getDynValue(PASSWORD_PARAMTER_NAME);
102
        }
103

    
104
        public void setHost(String host) {
105
                this.setDynValue(HOST_PARAMTER_NAME, host);
106
        }
107

    
108
        public void setPort(int port) {
109
                this.setDynValue(PORT_PARAMTER_NAME, new Integer(port));
110
        }
111

    
112
        public void setPort(Integer port) {
113
                this.setDynValue(PORT_PARAMTER_NAME, port);
114
        }
115

    
116
        public void setDBName(String dbName) {
117
                this.setDynValue(DBNAME_PARAMTER_NAME, dbName);
118
        }
119

    
120
        public void setUser(String user) {
121
                this.setDynValue(USER_PARAMTER_NAME, user);
122
        }
123

    
124
        public void setPassword(String password) {
125
                this.setDynValue(PASSWORD_PARAMTER_NAME, password);
126
        }
127

    
128
        /**
129
         * Set <code>JDBC Driver class name</code> parameter
130
         *
131
         * @param className
132
         */
133
        public void setJDBCDriverClassName(String className) {
134
                this.setDynValue(JDBC_DRIVER_CLASS_PARAMTER_NAME, className);
135
        }
136

    
137
        public String getJDBCDriverClassName() {
138
                return (String) this.getDynValue(JDBC_DRIVER_CLASS_PARAMTER_NAME);
139
        }
140

    
141
        public String getCatalog() {
142
                return (String) this.getDynValue(CATALOG_PARAMTER_NAME);
143
        }
144

    
145

    
146
        /**
147
         * Set <code>catalog</code> parameter
148
         *
149
         * @param className
150
         */
151
        public void setCatalog(String catalog) {
152
                this.setDynValue(CATALOG_PARAMTER_NAME, catalog);
153
        }
154

    
155
        public String getSchema() {
156
                return (String) this.getDynValue(SCHEMA_PARAMTER_NAME);
157
        }
158

    
159
        /**
160
         * Set <code>schema</code> parameter
161
         *
162
         * @param className
163
         */
164
        public void setSchema(String schema) {
165
                this.setDynValue(SCHEMA_PARAMTER_NAME, schema);
166
        }
167

    
168
        public String getTable() {
169
                return (String) this.getDynValue(TABLE_PARAMTER_NAME);
170
        }
171

    
172
        public void setTable(String table) {
173
                this.setDynValue(TABLE_PARAMTER_NAME, table);
174
        }
175

    
176
        public String getFieldsString() {
177
                return (String) this.getDynValue(FIELDS_PARAMTER_NAME);
178
        }
179

    
180
        public String[] getFields() {
181
                String fields = (String) this.getDynValue(FIELDS_PARAMTER_NAME);
182
                if (fields == null) {
183
                        return null;
184
                }
185
                // FIXME check for fields with spaces and special chars
186
                return fields.split(",");
187
        }
188

    
189
        public void setFields(String fields) {
190
                this.setDynValue(FIELDS_PARAMTER_NAME, fields);
191
        }
192

    
193
        public void setFields(String[] fields) {
194
                StringBuilder str = new StringBuilder();
195
                for (int i = 0; i < fields.length - 1; i++) {
196
                        str.append(fields[i]);
197
                        str.append(",");
198
                }
199
                str.append(fields[fields.length - 1]);
200

    
201
                this.setDynValue(FIELDS_PARAMTER_NAME, str.toString());
202
        }
203

    
204
        public String getSQL() {
205
                return (String) this.getDynValue(SQL_PARAMTER_NAME);
206
        }
207

    
208
        public void setSQL(String sql) {
209
                this.setDynValue(SQL_PARAMTER_NAME, sql);
210
        }
211

    
212
        public String getBaseFilter() {
213
                return (String) this.getDynValue(BASEFILTER_PARAMTER_NAME);
214
        }
215

    
216
        public void setBaseFilter(String initialFilter) {
217
                this.setDynValue(BASEFILTER_PARAMTER_NAME, initialFilter);
218
        }
219

    
220
        public String getBaseOrder() {
221
                return (String) this.getDynValue(BASEORDER_PARAMTER_NAME);
222
        }
223

    
224
        public void setBaseOrder(String order) {
225
                this.setDynValue(BASEORDER_PARAMTER_NAME, order);
226
        }
227

    
228
        public String getPkFieldsString() {
229
                return (String) this.getDynValue(PKFIELDS_PARAMTER_NAME);
230
        }
231

    
232
        public String[] getPkFields() {
233
                String fields = (String) this.getDynValue(PKFIELDS_PARAMTER_NAME);
234
                if (fields == null) {
235
                        return null;
236
                }
237
                // FIXME check for fields with spaces and special chars
238
                return fields.split(",");
239
        }
240

    
241
        public void setPkFields(String fields) {
242
                this.setDynValue(PKFIELDS_PARAMTER_NAME, fields);
243
        }
244

    
245
        public void setPkFields(String[] fields) {
246
                StringBuilder str = new StringBuilder();
247
                for (int i = 0; i < fields.length - 1; i++) {
248
                        str.append(fields[i]);
249
                        str.append(",");
250
                }
251
                str.append(fields[fields.length - 1]);
252

    
253
                this.setDynValue(PKFIELDS_PARAMTER_NAME, str.toString());
254
        }
255

    
256
        /**
257
         * Return table <code>name</code> or <code>schema.tableName</code> if
258
         * <code>schema</code> parameter is set.
259
         *
260
         * @return
261
         */
262
        public String tableID() {
263
                if (this.getSchema() == null || this.getSchema() == "") {
264
            return escapeName(this.getTable());
265
                }
266
        return escapeName(this.getSchema()) + "." + escapeName(this.getTable());
267
        }
268

    
269
    protected String escapeName(String name) {
270
        return "\"".concat(name).concat("\"");
271
    }
272

    
273
        /**
274
         * Compound a string that can identify the source
275
         *
276
         * @return
277
         */
278
        public String getSourceId() {
279
                if (getTable() != null) {
280
                        return MessageFormat.format(
281
                                        "provider={0}:url=\"{1}\":table=\"{2}\":user={3}:driverclass={4}", 
282
                                        this.getDataStoreName(),
283
                                        this.getUrl(),
284
                                        this.getTable(),
285
                                        this.getUser(),
286
                                        this.getJDBCDriverClassName()
287
                        );
288
                }
289
                return MessageFormat.format(
290
                                "provider={0}:url=\"{1}\":sql=\"{2}\":user={3}:driverclass={4}", 
291
                                this.getDataStoreName(),
292
                                this.getUrl(),
293
                                this.getSQL(),
294
                                this.getUser(),
295
                                this.getJDBCDriverClassName()
296
                );
297
        }
298

    
299
        public String getUrl() {
300
                return (String) this.getDynValue(URL_PARAMTER_NAME);
301
        }
302

    
303
        /**
304
         * Set <code>JDBC connection url</code> parameter
305
         *
306
         * @param url
307
         */
308
        public void setUrl(String url) {
309
                this.setDynValue(URL_PARAMTER_NAME, url);
310
        }
311

    
312
}