root / branches / v2_0_0_prep / libraries / libFMap_dataDB / src / org / gvsig / fmap / data / feature / db / DBStoreParameters.java @ 24250
History | View | Annotate | Download (8.4 KB)
1 |
package org.gvsig.fmap.data.feature.db; |
---|---|
2 |
|
3 |
import java.util.HashMap; |
4 |
import java.util.Map; |
5 |
|
6 |
import org.gvsig.fmap.data.DataStoreParameters; |
7 |
import org.gvsig.fmap.data.exceptions.InitializeException; |
8 |
import org.gvsig.fmap.geom.primitive.Envelope; |
9 |
|
10 |
import com.iver.utiles.NotExistInXMLEntity; |
11 |
import com.iver.utiles.XMLEntity; |
12 |
|
13 |
public abstract class DBStoreParameters extends DataStoreParameters |
14 |
implements DBParameters {
|
15 |
|
16 |
protected Map createDefaultValuesMap() { |
17 |
Map defaultValues = new HashMap(16); |
18 |
defaultValues.put("user", null); |
19 |
defaultValues.put("passw", null); |
20 |
defaultValues.put("schema", null); |
21 |
defaultValues.put("catalog", null); |
22 |
defaultValues.put("host", null); |
23 |
defaultValues.put("port", null); |
24 |
defaultValues.put("db", null); |
25 |
|
26 |
defaultValues.put("fields", null); |
27 |
|
28 |
defaultValues.put("baseFilter", null); |
29 |
defaultValues.put("baseOrder", null); |
30 |
defaultValues.put("tableName", null); |
31 |
|
32 |
defaultValues.put("fieldsId", null); |
33 |
|
34 |
defaultValues.put("sqlSoure", null); |
35 |
defaultValues.put("workingArea", null); |
36 |
defaultValues.put("SRISD", null); |
37 |
defaultValues.put("defaultGeometryField", null); |
38 |
|
39 |
return defaultValues;
|
40 |
} |
41 |
|
42 |
public String getDb() { |
43 |
return (String) this.getAttribute("db"); |
44 |
} |
45 |
|
46 |
public void setDb(String db) { |
47 |
this.put("db", db); |
48 |
} |
49 |
public String getHost() { |
50 |
return (String) this.getAttribute("host"); |
51 |
} |
52 |
public void setHost(String host) { |
53 |
this.put("host", host); |
54 |
} |
55 |
public String getPort() { |
56 |
return (String) this.getAttribute("port"); |
57 |
} |
58 |
public void setPort(String port) { |
59 |
this.put("port", port); |
60 |
} |
61 |
public String getSchema() { |
62 |
return (String) this.getAttribute("schema"); |
63 |
} |
64 |
public void setSchema(String schema) { |
65 |
this.put("schema", schema); |
66 |
} |
67 |
public String getPassw() { |
68 |
return (String) this.getAttribute("passw"); |
69 |
} |
70 |
public void setPassw(String passw) { |
71 |
this.put("passw", passw); |
72 |
} |
73 |
|
74 |
public String getUser() { |
75 |
return (String) this.getAttribute("user"); |
76 |
} |
77 |
|
78 |
public void setUser(String user) { |
79 |
this.put("user", user); |
80 |
} |
81 |
|
82 |
public String getCatalog() { |
83 |
return (String) this.getAttribute("catalog"); |
84 |
} |
85 |
|
86 |
public void setCatalog(String catalog) { |
87 |
this.put("catalog", catalog); |
88 |
} |
89 |
|
90 |
public String getBaseFilter() { |
91 |
return (String) this.getAttribute("baseFilter"); |
92 |
} |
93 |
|
94 |
public void setBaseFilter(String baseFilter) { |
95 |
this.put("baseFilter", baseFilter); |
96 |
} |
97 |
|
98 |
public String getBaseOrder() { |
99 |
return (String) this.getAttribute("baseOrder"); |
100 |
} |
101 |
public void setBaseOrder(String baseOrder) { |
102 |
this.put("baseOrder", baseOrder); |
103 |
} |
104 |
public String[] getFields() { |
105 |
return (String[]) this.getAttribute("fields"); |
106 |
} |
107 |
public void setFields(String[] fields) { |
108 |
this.put("fields", fields); |
109 |
} |
110 |
private String arrayToString(Object[] array) { |
111 |
StringBuffer buff = new StringBuffer(); |
112 |
if (array.length < 1) { |
113 |
return ""; |
114 |
} |
115 |
for (int i = 0; i < array.length; i++) { |
116 |
buff.append(array[i] + ",");
|
117 |
} |
118 |
|
119 |
String r = buff.toString();
|
120 |
return r.substring(0, r.length() - 1); |
121 |
} |
122 |
|
123 |
public String getFieldsString(){ |
124 |
String[] fields = this.getFields(); |
125 |
if (fields == null || fields.length == 0) { |
126 |
return "*"; |
127 |
} else if (fields.length == 1) { |
128 |
return fields[0]; |
129 |
} else {
|
130 |
return arrayToString(fields);
|
131 |
} |
132 |
} |
133 |
|
134 |
public String getTableName() { |
135 |
return (String) this.getAttribute("tableName"); |
136 |
} |
137 |
public void setTableName(String tableName) { |
138 |
this.put("tableName", tableName); |
139 |
} |
140 |
public String tableID(){ |
141 |
String schema = this.getSchema(); |
142 |
if (schema == null || schema == "") { |
143 |
return this.getTableName(); |
144 |
} |
145 |
return schema + "." + this.getTableName(); |
146 |
} |
147 |
public String[] getFieldsId() { |
148 |
return (String[]) this.getAttribute("fieldsId"); |
149 |
} |
150 |
public void setFieldsId(String[] fieldsId) { |
151 |
this.put("fieldsId", fieldsId); |
152 |
} |
153 |
|
154 |
public String getFieldsIdString() { |
155 |
String[] fieldsId = this.getFieldsId(); |
156 |
if (fieldsId == null || fieldsId.length == 0) { |
157 |
return ""; |
158 |
} else if (fieldsId.length == 1) { |
159 |
return fieldsId[0]; |
160 |
} else {
|
161 |
return arrayToString(fieldsId);
|
162 |
} |
163 |
} |
164 |
|
165 |
public boolean isValid() { |
166 |
if (this.getSqlSoure() != null) { |
167 |
return this.getTableName() == null && this.getFieldsId() != null |
168 |
&& this.getFieldsId().length > 0; |
169 |
} |
170 |
return this.getTableName() != null && this.getFields() != null |
171 |
&& this.getFields().length > 0 && this.getFieldsId() != null |
172 |
&& this.getFieldsId().length > 0 && this.getDb() != null; |
173 |
} |
174 |
public String getSqlSoure() { |
175 |
return (String) this.getAttribute("sqlSoure"); |
176 |
} |
177 |
public void setSqlSoure(String sqlSoure) { |
178 |
this.put("sqlSoure", sqlSoure); |
179 |
} |
180 |
public String getDefaultGeometryField() { |
181 |
return (String) this.getAttribute("defaultGeometryField"); |
182 |
} |
183 |
public void setDefaultGeometryField(String geometryColumn) { |
184 |
this.put("defaultGeometryField", geometryColumn); |
185 |
} |
186 |
public String getSRISD() { |
187 |
return (String) this.getAttribute("SRISD"); |
188 |
} |
189 |
public void setSRISD(String srisd) { |
190 |
this.put("SRISD", srisd); |
191 |
} |
192 |
public Envelope getWorkingArea() {
|
193 |
return (Envelope) this.getAttribute("workingArea"); |
194 |
} |
195 |
public void setWorkingArea(Envelope workingArea) { |
196 |
this.put("workingArea", workingArea); |
197 |
} |
198 |
|
199 |
|
200 |
public XMLEntity getXMLEntity() {
|
201 |
XMLEntity xmlEntity = super.getXMLEntity();
|
202 |
|
203 |
xmlEntity.putProperty("user", this.getUser()); |
204 |
//xmlEntity.putProperty("passw", this.passw);
|
205 |
xmlEntity.putProperty("schema", this.getSchema()); |
206 |
xmlEntity.putProperty("catalog", this.getCatalog()); |
207 |
xmlEntity.putProperty("host", this.getHost()); |
208 |
xmlEntity.putProperty("port", this.getPort()); |
209 |
xmlEntity.putProperty("db", this.getDb()); |
210 |
|
211 |
xmlEntity.putProperty("tableName", this.getTableName()); |
212 |
|
213 |
xmlEntity.putProperty("fieldsString", this.getFieldsString()); |
214 |
xmlEntity.putProperty("fieldsIdString", this.getFieldsIdString()); |
215 |
|
216 |
xmlEntity.putProperty("baseFilter", this.getBaseFilter()); |
217 |
xmlEntity.putProperty("baseOrder", this.getBaseOrder()); |
218 |
xmlEntity.putProperty("sqlSoure", this.getSqlSoure()); |
219 |
// TODO xmlEntity.putProperty("workingArea", this.workingArea.toString());
|
220 |
|
221 |
xmlEntity.putProperty("SRISD", this.getSRISD()); |
222 |
|
223 |
xmlEntity |
224 |
.putProperty("defaultGeometryField", this |
225 |
.getDefaultGeometryField()); |
226 |
|
227 |
return xmlEntity;
|
228 |
} |
229 |
|
230 |
public void loadFromXMLEntity(XMLEntity xmlEntity) |
231 |
throws InitializeException {
|
232 |
|
233 |
try {
|
234 |
this.setUser(xmlEntity.getStringProperty("user")); |
235 |
} catch (NotExistInXMLEntity e) {
|
236 |
this.remove("user"); |
237 |
} |
238 |
|
239 |
try {
|
240 |
this.setPassw(xmlEntity.getStringProperty("passw")); |
241 |
} catch (NotExistInXMLEntity e) {
|
242 |
this.remove("passw"); |
243 |
} |
244 |
|
245 |
try {
|
246 |
this.setSchema(xmlEntity.getStringProperty("schema")); |
247 |
} catch (NotExistInXMLEntity e) {
|
248 |
this.remove("schema"); |
249 |
} |
250 |
|
251 |
try {
|
252 |
this.setCatalog(xmlEntity.getStringProperty("catalog")); |
253 |
} catch (NotExistInXMLEntity e) {
|
254 |
this.remove("catalog"); |
255 |
} |
256 |
|
257 |
try {
|
258 |
this.setHost(xmlEntity.getStringProperty("host")); |
259 |
} catch (NotExistInXMLEntity e) {
|
260 |
throw new InitializeException("host property not set", this |
261 |
.getDataStoreName()); |
262 |
} |
263 |
try {
|
264 |
this.setPort(xmlEntity.getStringProperty("port")); |
265 |
} catch (NotExistInXMLEntity e) {
|
266 |
throw new InitializeException("port property not set", this |
267 |
.getDataStoreName()); |
268 |
} |
269 |
try {
|
270 |
this.setDb(xmlEntity.getStringProperty("db")); |
271 |
} catch (NotExistInXMLEntity e) {
|
272 |
throw new InitializeException("db property not set", this |
273 |
.getDataStoreName()); |
274 |
} |
275 |
|
276 |
try {
|
277 |
this.setTableName(xmlEntity.getStringProperty("tableName")); |
278 |
} catch (NotExistInXMLEntity e) {
|
279 |
this.remove("tableName"); |
280 |
} |
281 |
|
282 |
try {
|
283 |
this.setBaseFilter(xmlEntity.getStringProperty("baseFilter")); |
284 |
} catch (NotExistInXMLEntity e) {
|
285 |
this.remove("baseFilter"); |
286 |
} |
287 |
|
288 |
try {
|
289 |
this.setBaseOrder(xmlEntity.getStringProperty("baseOrder")); |
290 |
} catch (NotExistInXMLEntity e) {
|
291 |
this.remove("baseOrder"); |
292 |
} |
293 |
|
294 |
try {
|
295 |
this.setSqlSoure(xmlEntity.getStringProperty("sqlSoure")); |
296 |
} catch (NotExistInXMLEntity e) {
|
297 |
this.remove("sqlSoure"); |
298 |
} |
299 |
|
300 |
try {
|
301 |
this.setSRISD(xmlEntity.getStringProperty("SRISD")); |
302 |
} catch (NotExistInXMLEntity e) {
|
303 |
this.remove("SRISD"); |
304 |
} |
305 |
|
306 |
try {
|
307 |
this.setDefaultGeometryField(xmlEntity
|
308 |
.getStringProperty("defaultGeometryField"));
|
309 |
} catch (NotExistInXMLEntity e) {
|
310 |
this.remove("defaultGeometryField"); |
311 |
} |
312 |
|
313 |
String tmp;
|
314 |
try {
|
315 |
tmp = xmlEntity.getStringProperty("fieldsString");
|
316 |
if (tmp.equals("*")) { |
317 |
this.setFields(null); |
318 |
} else {
|
319 |
this.setFields(tmp.split(",")); |
320 |
} |
321 |
} catch (NotExistInXMLEntity e) {
|
322 |
this.remove("fields"); |
323 |
} |
324 |
|
325 |
try {
|
326 |
tmp = xmlEntity.getStringProperty("fieldsIdString");
|
327 |
this.setFieldsId(tmp.split(",")); |
328 |
} catch (NotExistInXMLEntity e) {
|
329 |
this.remove("fieldsId"); |
330 |
} |
331 |
|
332 |
} |
333 |
|
334 |
} |