svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.prov / org.gvsig.exportto.swing.prov.jdbc / src / main / java / org / gvsig / export / jdbc / service / ExportJDBCParametersImpl.java @ 47191
History | View | Annotate | Download (16.7 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.export.jdbc.service; |
7 |
|
8 |
import java.util.List; |
9 |
import org.apache.commons.lang3.StringUtils; |
10 |
import org.gvsig.export.spi.AbstractExportParametersGeometry; |
11 |
import org.gvsig.expressionevaluator.Expression; |
12 |
import org.gvsig.fmap.dal.DALLocator; |
13 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
14 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCStoreProviderFactory; |
15 |
import static org.gvsig.fmap.dal.store.jdbc2.JDBCStoreProviderFactory.CASE_IDENTIFIERS_LOWERCASE; |
16 |
import static org.gvsig.fmap.dal.store.jdbc2.JDBCStoreProviderFactory.CASE_IDENTIFIERS_UPPERCASE; |
17 |
import org.gvsig.tools.ToolsLocator; |
18 |
import org.gvsig.tools.dynobject.DynStruct; |
19 |
import static org.gvsig.tools.namestranslator.BaseNamesTranslator.DEFAULT_FIELD_NAME; |
20 |
import org.gvsig.tools.persistence.PersistenceManager; |
21 |
import org.gvsig.tools.persistence.PersistentState; |
22 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
23 |
|
24 |
/**
|
25 |
*
|
26 |
* @author jjdelcerro
|
27 |
*/
|
28 |
public class ExportJDBCParametersImpl |
29 |
extends AbstractExportParametersGeometry
|
30 |
implements ExportJDBCParameters {
|
31 |
|
32 |
private JDBCServerExplorerParameters explorerParameters;
|
33 |
private String schema; |
34 |
private String tableName; |
35 |
private boolean canCreatetable; |
36 |
private String primaryKeyName; |
37 |
private String storeName; |
38 |
private String explorerName; |
39 |
private boolean removeSpacesInIdentifiers; |
40 |
private boolean translateHyphens; |
41 |
private String selectRole; |
42 |
private String insertRole; |
43 |
private String updateRole; |
44 |
private String deleteRole; |
45 |
private String truncateRole; |
46 |
private String referenceRole; |
47 |
private String triggerRole; |
48 |
private String allRole; |
49 |
private String postCreatingStatement; |
50 |
private boolean createIndexInGeometryRow; |
51 |
private boolean updateTableStatistics; |
52 |
private int caseIdentifierMode; |
53 |
private boolean deleteRows; |
54 |
private Expression deleteRowsFilter; |
55 |
|
56 |
public ExportJDBCParametersImpl(ExportJDBCServiceFactory factory) {
|
57 |
super(factory);
|
58 |
this.exportAttributes.setNamesTranslator(new ExportJDBCAttributeNamesTranslator(this)); |
59 |
|
60 |
this.canCreatetable = true; |
61 |
this.caseIdentifierMode = CASE_IDENTIFIERS_UPPERCASE;
|
62 |
this.removeSpacesInIdentifiers = true; |
63 |
this.translateHyphens = true; |
64 |
this.createIndexInGeometryRow = true; |
65 |
this.updateTableStatistics = true; |
66 |
} |
67 |
|
68 |
public ExportJDBCParametersImpl() {
|
69 |
super(null); |
70 |
} |
71 |
|
72 |
@Override
|
73 |
public String getServiceName() { |
74 |
return ExportJDBCServiceFactory.SERVICE_NAME;
|
75 |
} |
76 |
|
77 |
/**
|
78 |
* @return the explorerParameters
|
79 |
*/
|
80 |
@Override
|
81 |
public JDBCServerExplorerParameters getExplorerParameters() {
|
82 |
return explorerParameters;
|
83 |
} |
84 |
|
85 |
/**
|
86 |
* @param explorerParameters the explorerParameters to set
|
87 |
*/
|
88 |
@Override
|
89 |
public void setExplorerParameters(JDBCServerExplorerParameters explorerParameters) { |
90 |
this.explorerParameters = explorerParameters;
|
91 |
String provider = this.explorerParameters.getProviderName(); |
92 |
JDBCStoreProviderFactory providerFactory = (JDBCStoreProviderFactory)DALLocator.getDataManager().getStoreProviderFactory(provider); |
93 |
int caseMode = providerFactory.caseIndentifierPreferedMode();
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* @return the schema
|
98 |
*/
|
99 |
@Override
|
100 |
public String getSchema() { |
101 |
return schema;
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* @param schema the schema to set
|
106 |
*/
|
107 |
@Override
|
108 |
public void setSchema(String schema) { |
109 |
this.schema = schema;
|
110 |
} |
111 |
|
112 |
/**
|
113 |
* @return the tableName
|
114 |
*/
|
115 |
@Override
|
116 |
public String getTableName() { |
117 |
return tableName;
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* @param tableName the tableName to set
|
122 |
*/
|
123 |
@Override
|
124 |
public void setTableName(String tableName) { |
125 |
this.tableName = tableName;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* @return the canCreatetable
|
130 |
*/
|
131 |
@Override
|
132 |
public boolean canCreatetable() { |
133 |
return canCreatetable;
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* @param canCreatetable the canCreatetable to set
|
138 |
*/
|
139 |
@Override
|
140 |
public void setCanCreatetable(boolean canCreatetable) { |
141 |
this.canCreatetable = canCreatetable;
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* @return the primaryKeyName
|
146 |
*/
|
147 |
@Override
|
148 |
public String getPrimaryKey() { |
149 |
return primaryKeyName;
|
150 |
} |
151 |
|
152 |
/**
|
153 |
* @param primaryKey the primaryKeyName to set
|
154 |
*/
|
155 |
@Override
|
156 |
public void setPrimaryKey(String primaryKey) { |
157 |
this.primaryKeyName = primaryKey;
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* @return the storeName
|
162 |
*/
|
163 |
@Override
|
164 |
public String getStoreName() { |
165 |
return storeName;
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* @param storeName the storeName to set
|
170 |
*/
|
171 |
@Override
|
172 |
public void setStoreName(String storeName) { |
173 |
this.storeName = storeName;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* @return the explorerName
|
178 |
*/
|
179 |
@Override
|
180 |
public String getExplorerName() { |
181 |
return explorerName;
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* @param explorerName the explorerName to set
|
186 |
*/
|
187 |
@Override
|
188 |
public void setExplorerName(String explorerName) { |
189 |
this.explorerName = explorerName;
|
190 |
} |
191 |
|
192 |
@Override
|
193 |
public void setCaseIdentifiersMode(int mode) { |
194 |
if(mode != this.caseIdentifierMode){ |
195 |
this.caseIdentifierMode = mode;
|
196 |
this.exportAttributes.getNamesTranslator().rebuild();
|
197 |
} |
198 |
} |
199 |
|
200 |
/**
|
201 |
* @param removeSpacesInIdentifiers the removeSpacesInIdentifiers to set
|
202 |
*/
|
203 |
@Override
|
204 |
public void setRemoveSpacesInIdentifiers(boolean removeSpacesInIdentifiers) { |
205 |
if (removeSpacesInIdentifiers != this.removeSpacesInIdentifiers) { |
206 |
this.removeSpacesInIdentifiers = removeSpacesInIdentifiers;
|
207 |
this.exportAttributes.getNamesTranslator().rebuild();
|
208 |
} |
209 |
} |
210 |
|
211 |
/**
|
212 |
* @param translateHyphens the translateHyphens to set
|
213 |
*/
|
214 |
@Override
|
215 |
public void setTranslateHyphens(boolean translateHyphens) { |
216 |
if (translateHyphens != this.translateHyphens) { |
217 |
this.translateHyphens = translateHyphens;
|
218 |
List<String> sourceNames = this.exportAttributes.getNamesTranslator().getSourceNames(); |
219 |
this.exportAttributes.getNamesTranslator().rebuild();
|
220 |
} |
221 |
} |
222 |
|
223 |
/**
|
224 |
* @return the selectRole
|
225 |
*/
|
226 |
@Override
|
227 |
public String getSelectRole() { |
228 |
return selectRole;
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* @param selectRole the selectRole to set
|
233 |
*/
|
234 |
@Override
|
235 |
public void setSelectRole(String selectRole) { |
236 |
this.selectRole = selectRole;
|
237 |
} |
238 |
|
239 |
/**
|
240 |
* @return the insertRole
|
241 |
*/
|
242 |
@Override
|
243 |
public String getInsertRole() { |
244 |
return insertRole;
|
245 |
} |
246 |
|
247 |
/**
|
248 |
* @param insertRole the insertRole to set
|
249 |
*/
|
250 |
@Override
|
251 |
public void setInsertRole(String insertRole) { |
252 |
this.insertRole = insertRole;
|
253 |
} |
254 |
|
255 |
/**
|
256 |
* @return the updateRole
|
257 |
*/
|
258 |
@Override
|
259 |
public String getUpdateRole() { |
260 |
return updateRole;
|
261 |
} |
262 |
|
263 |
/**
|
264 |
* @param updateRole the updateRole to set
|
265 |
*/
|
266 |
@Override
|
267 |
public void setUpdateRole(String updateRole) { |
268 |
this.updateRole = updateRole;
|
269 |
} |
270 |
|
271 |
/**
|
272 |
* @return the deleteRole
|
273 |
*/
|
274 |
@Override
|
275 |
public String getDeleteRole() { |
276 |
return deleteRole;
|
277 |
} |
278 |
|
279 |
/**
|
280 |
* @param deleteRole the deleteRole to set
|
281 |
*/
|
282 |
@Override
|
283 |
public void setDeleteRole(String deleteRole) { |
284 |
this.deleteRole = deleteRole;
|
285 |
} |
286 |
|
287 |
/**
|
288 |
* @return the truncateRole
|
289 |
*/
|
290 |
@Override
|
291 |
public String getTruncateRole() { |
292 |
return truncateRole;
|
293 |
} |
294 |
|
295 |
/**
|
296 |
* @param truncateRole the truncateRole to set
|
297 |
*/
|
298 |
@Override
|
299 |
public void setTruncateRole(String truncateRole) { |
300 |
this.truncateRole = truncateRole;
|
301 |
} |
302 |
|
303 |
/**
|
304 |
* @return the referenceRole
|
305 |
*/
|
306 |
@Override
|
307 |
public String getReferenceRole() { |
308 |
return referenceRole;
|
309 |
} |
310 |
|
311 |
/**
|
312 |
* @param referenceRole the referenceRole to set
|
313 |
*/
|
314 |
@Override
|
315 |
public void setReferenceRole(String referenceRole) { |
316 |
this.referenceRole = referenceRole;
|
317 |
} |
318 |
|
319 |
/**
|
320 |
* @return the triggerRole
|
321 |
*/
|
322 |
@Override
|
323 |
public String getTriggerRole() { |
324 |
return triggerRole;
|
325 |
} |
326 |
|
327 |
/**
|
328 |
* @param triggerRole the triggerRole to set
|
329 |
*/
|
330 |
@Override
|
331 |
public void setTriggerRole(String triggerRole) { |
332 |
this.triggerRole = triggerRole;
|
333 |
} |
334 |
|
335 |
/**
|
336 |
* @return the allRole
|
337 |
*/
|
338 |
@Override
|
339 |
public String getAllRole() { |
340 |
return allRole;
|
341 |
} |
342 |
|
343 |
/**
|
344 |
* @param allRole the allRole to set
|
345 |
*/
|
346 |
@Override
|
347 |
public void setAllRole(String allRole) { |
348 |
this.allRole = allRole;
|
349 |
} |
350 |
|
351 |
/**
|
352 |
* @return the postCreatingStatement
|
353 |
*/
|
354 |
@Override
|
355 |
public String getPostCreatingStatement() { |
356 |
return postCreatingStatement;
|
357 |
} |
358 |
|
359 |
/**
|
360 |
* @param postCreatingStatement the postCreatingStatement to set
|
361 |
*/
|
362 |
@Override
|
363 |
public void setPostCreatingStatement(String postCreatingStatement) { |
364 |
this.postCreatingStatement = postCreatingStatement;
|
365 |
} |
366 |
|
367 |
/**
|
368 |
* @return the createIndexInGeometryRow
|
369 |
*/
|
370 |
@Override
|
371 |
public boolean getCreateIndexInGeometryRow() { |
372 |
return createIndexInGeometryRow;
|
373 |
} |
374 |
|
375 |
/**
|
376 |
* @param createIndexInGeometryRow the createIndexInGeometryRow to set
|
377 |
*/
|
378 |
@Override
|
379 |
public void setCreateIndexInGeometryRow(boolean createIndexInGeometryRow) { |
380 |
this.createIndexInGeometryRow = createIndexInGeometryRow;
|
381 |
} |
382 |
|
383 |
/**
|
384 |
* @return the updateTableStatistics
|
385 |
*/
|
386 |
@Override
|
387 |
public boolean getUpdateTableStatistics() { |
388 |
return updateTableStatistics;
|
389 |
} |
390 |
|
391 |
/**
|
392 |
* @param updateTableStatistics the updateTableStatistics to set
|
393 |
*/
|
394 |
@Override
|
395 |
public void setUpdateTableStatistics(boolean updateTableStatistics) { |
396 |
this.updateTableStatistics = updateTableStatistics;
|
397 |
} |
398 |
|
399 |
@Override
|
400 |
public boolean getTranslateHyphens() { |
401 |
return this.translateHyphens; |
402 |
} |
403 |
|
404 |
@Override
|
405 |
public boolean getRemoveSpacesInIdentifiers() { |
406 |
return this.removeSpacesInIdentifiers; |
407 |
} |
408 |
|
409 |
@Override
|
410 |
public int getCaseIdentifiersMode() { |
411 |
return caseIdentifierMode;
|
412 |
} |
413 |
|
414 |
@Override
|
415 |
public void setDeleteRows(boolean deleteRows) { |
416 |
this.deleteRows = deleteRows;
|
417 |
} |
418 |
|
419 |
@Override
|
420 |
public boolean isDeleteRows() { |
421 |
return deleteRows;
|
422 |
} |
423 |
|
424 |
@Override
|
425 |
public void setDeleteRowsFilter(Expression deleteRowsFilter) { |
426 |
this.deleteRowsFilter = deleteRowsFilter;
|
427 |
} |
428 |
|
429 |
@Override
|
430 |
public Expression getDeleteRowsFilter() { |
431 |
return deleteRowsFilter;
|
432 |
} |
433 |
|
434 |
|
435 |
|
436 |
|
437 |
@Override
|
438 |
public ExportJDBCParameters clone() throws CloneNotSupportedException { |
439 |
ExportJDBCParameters clone = (ExportJDBCParameters) super.clone();
|
440 |
clone.setExplorerParameters((JDBCServerExplorerParameters) this.explorerParameters.getCopy());
|
441 |
return clone;
|
442 |
} |
443 |
|
444 |
public static void registerPersistence() { |
445 |
|
446 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
447 |
if (manager.getDefinition("ExportJDBCParametersImpl") == null) { |
448 |
DynStruct definition = manager.addDefinition(ExportJDBCParametersImpl.class, |
449 |
"ExportJDBCParametersImpl", "ExportJDBCParametersImpl persistence definition", null, null); |
450 |
definition.addDynFieldObject("explorerParameters").setClassOfValue(JDBCServerExplorerParameters.class);
|
451 |
definition.addDynFieldString("schema");
|
452 |
definition.addDynFieldString("tableName");
|
453 |
definition.addDynFieldBoolean("canCreatetable");
|
454 |
definition.addDynFieldString("primaryKeyName");
|
455 |
definition.addDynFieldString("storeName");
|
456 |
definition.addDynFieldString("explorerName");
|
457 |
definition.addDynFieldInt("caseIdentifierMode").setMandatory(false); |
458 |
definition.addDynFieldBoolean("removeSpacesInIdentifiers");
|
459 |
definition.addDynFieldBoolean("translateHyphens");
|
460 |
definition.addDynFieldString("selectRole");
|
461 |
definition.addDynFieldString("insertRole");
|
462 |
definition.addDynFieldString("updateRole");
|
463 |
definition.addDynFieldString("deleteRole");
|
464 |
definition.addDynFieldString("truncateRole");
|
465 |
definition.addDynFieldString("referenceRole");
|
466 |
definition.addDynFieldString("triggerRole");
|
467 |
definition.addDynFieldString("allRole");
|
468 |
definition.addDynFieldString("postCreatingStatement");
|
469 |
definition.addDynFieldBoolean("createIndexInGeometryRow");
|
470 |
definition.addDynFieldBoolean("updateTableStatistics");
|
471 |
definition.addDynFieldBoolean("deleteRows").setMandatory(false); |
472 |
definition.addDynFieldObject("deleteRowsFilter").setClassOfValue(Expression.class).setMandatory(false); |
473 |
definition.extend(manager.getDefinition("AbstractExportParametersGeometry"));
|
474 |
} |
475 |
} |
476 |
|
477 |
@Override
|
478 |
public void saveToState(PersistentState state) throws PersistenceException { |
479 |
super.saveToState(state);
|
480 |
state.set("explorerParameters", explorerParameters);
|
481 |
state.set("schema", schema);
|
482 |
state.set("tableName", tableName);
|
483 |
state.set("canCreatetable", canCreatetable);
|
484 |
state.set("primaryKeyName", primaryKeyName);
|
485 |
state.set("storeName", storeName);
|
486 |
state.set("explorerName", explorerName);
|
487 |
state.set("caseIdentifierMode", caseIdentifierMode);
|
488 |
state.set("removeSpacesInIdentifiers", removeSpacesInIdentifiers);
|
489 |
state.set("translateHyphens", translateHyphens);
|
490 |
state.set("selectRole", selectRole);
|
491 |
state.set("insertRole", insertRole);
|
492 |
state.set("updateRole", updateRole);
|
493 |
state.set("deleteRole", deleteRole);
|
494 |
state.set("truncateRole", truncateRole);
|
495 |
state.set("referenceRole", referenceRole);
|
496 |
state.set("triggerRole", triggerRole);
|
497 |
state.set("allRole", allRole);
|
498 |
state.set("postCreatingStatement", postCreatingStatement);
|
499 |
state.set("createIndexInGeometryRow", createIndexInGeometryRow);
|
500 |
state.set("updateTableStatistics", updateTableStatistics);
|
501 |
state.set("deleteRows", deleteRows);
|
502 |
state.set("deleteRowsFilter", deleteRowsFilter);
|
503 |
} |
504 |
|
505 |
@Override
|
506 |
public void loadFromState(PersistentState state) throws PersistenceException { |
507 |
super.loadFromState(state);
|
508 |
this.explorerParameters = (JDBCServerExplorerParameters) state.get("explorerParameters"); |
509 |
this.schema = state.getString("schema"); |
510 |
this.tableName = state.getString("tableName"); |
511 |
this.canCreatetable = state.getBoolean("canCreatetable"); |
512 |
this.primaryKeyName = state.getString("primaryKeyName"); |
513 |
this.storeName = state.getString("storeName"); |
514 |
this.explorerName = state.getString("explorerName"); |
515 |
this.caseIdentifierMode = state.getInt("caseIdentifierMode",CASE_IDENTIFIERS_UPPERCASE); |
516 |
this.removeSpacesInIdentifiers = state.getBoolean("removeSpacesInIdentifiers"); |
517 |
this.translateHyphens = state.getBoolean("translateHyphens"); |
518 |
this.selectRole = state.getString("selectRole"); |
519 |
this.insertRole = state.getString("insertRole"); |
520 |
this.updateRole = state.getString("updateRole"); |
521 |
this.deleteRole = state.getString("deleteRole"); |
522 |
this.truncateRole = state.getString("truncateRole"); |
523 |
this.referenceRole = state.getString("referenceRole"); |
524 |
this.triggerRole = state.getString("triggerRole"); |
525 |
this.allRole = state.getString("allRole"); |
526 |
this.postCreatingStatement = state.getString("postCreatingStatement"); |
527 |
this.createIndexInGeometryRow = state.getBoolean("createIndexInGeometryRow"); |
528 |
this.updateTableStatistics = state.getBoolean("updateTableStatistics"); |
529 |
this.deleteRows = state.getBoolean("deleteRows"); |
530 |
this.deleteRowsFilter = (Expression) state.get("deleteRowsFilter"); |
531 |
|
532 |
ExportJDBCAttributeNamesTranslator nameTranslator = (ExportJDBCAttributeNamesTranslator) this.exportAttributes.getNamesTranslator();
|
533 |
nameTranslator.setParameters(this);
|
534 |
} |
535 |
|
536 |
public String fixIdentifier(String name) { |
537 |
String target_name = name;
|
538 |
if (this.getRemoveSpacesInIdentifiers()) { |
539 |
target_name = StringUtils.normalizeSpace(target_name).replace(" ", "_"); |
540 |
} |
541 |
if (this.getTranslateHyphens()) { |
542 |
target_name = target_name.replace("-", "_"); |
543 |
} |
544 |
switch(this.getCaseIdentifiersMode()){ |
545 |
case CASE_IDENTIFIERS_UPPERCASE:
|
546 |
target_name = target_name.toUpperCase(); |
547 |
break;
|
548 |
case CASE_IDENTIFIERS_LOWERCASE:
|
549 |
target_name = target_name.toLowerCase(); |
550 |
break;
|
551 |
} |
552 |
return target_name;
|
553 |
} |
554 |
|
555 |
|
556 |
} |