Revision 46629 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/copytable/CopyTable2ProcessParametersImpl.java
CopyTable2ProcessParametersImpl.java | ||
---|---|---|
9 | 9 |
import java.util.LinkedHashMap; |
10 | 10 |
import java.util.Map; |
11 | 11 |
import org.gvsig.expressionevaluator.Expression; |
12 |
import org.gvsig.fmap.dal.DALLocator; |
|
13 |
import org.gvsig.fmap.dal.DataManager; |
|
14 |
import org.gvsig.fmap.dal.DataParameters; |
|
15 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
12 | 16 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
17 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
|
18 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
19 |
import org.gvsig.tools.ToolsLocator; |
|
13 | 20 |
import org.gvsig.tools.dispose.DisposeUtils; |
14 | 21 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
22 |
import org.gvsig.tools.dynobject.DynStruct; |
|
15 | 23 |
import org.gvsig.tools.exception.BaseException; |
24 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
25 |
import org.gvsig.tools.persistence.PersistentState; |
|
26 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
27 |
import org.slf4j.LoggerFactory; |
|
16 | 28 |
|
17 | 29 |
/** |
18 | 30 |
* |
19 | 31 |
* @author jjdelcerro |
20 | 32 |
*/ |
21 | 33 |
public class CopyTable2ProcessParametersImpl extends AbstractDisposable implements CopyTable2ProcessParameters{ |
34 |
|
|
35 |
final static private org.slf4j.Logger LOGGER = LoggerFactory.getLogger(CopyTable2ProcessParametersImpl.class); |
|
22 | 36 |
|
23 | 37 |
public static class ProcessFieldParametersImpl implements ProcessFieldParameters { |
24 | 38 |
|
25 |
private final String name;
|
|
26 |
private final boolean copyThisField;
|
|
27 |
private final Expression expression;
|
|
39 |
private String name; |
|
40 |
private boolean copyThisField; |
|
41 |
private Expression expression; |
|
28 | 42 |
|
43 |
public ProcessFieldParametersImpl() { |
|
44 |
//For persistence only |
|
45 |
} |
|
46 |
|
|
29 | 47 |
public ProcessFieldParametersImpl(String name, boolean update, Expression expression) { |
30 | 48 |
this.name = name; |
31 | 49 |
this.copyThisField = update; |
... | ... | |
55 | 73 |
public Expression getExpression() { |
56 | 74 |
return expression; |
57 | 75 |
} |
76 |
|
|
77 |
public static void selfRegister() { |
|
78 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
79 |
|
|
80 |
DynStruct definition |
|
81 |
= manager.addDefinition(ProcessFieldParametersImpl.class, |
|
82 |
"ProcessFieldParameters", |
|
83 |
"ProcessFieldParameters Persistence definition", |
|
84 |
null, |
|
85 |
null); |
|
86 |
|
|
87 |
definition.addDynFieldString("name") |
|
88 |
.setMandatory(true); |
|
89 |
definition.addDynFieldBoolean("copyThisField") |
|
90 |
.setMandatory(true); |
|
91 |
definition.addDynFieldObject("expression") |
|
92 |
.setClassOfValue(Expression.class) |
|
93 |
.setMandatory(false); |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
98 |
this.name = state.getString("name"); |
|
99 |
this.copyThisField = state.getBoolean("copyThisField"); |
|
100 |
this.expression = (Expression)state.get("expression"); |
|
101 |
} |
|
102 |
|
|
103 |
@Override |
|
104 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
105 |
state.set("name", this.name ); |
|
106 |
state.set("copyThisField", this.copyThisField); |
|
107 |
state.set("expression", this.expression); |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
|
|
58 | 112 |
} |
59 | 113 |
|
60 | 114 |
|
... | ... | |
62 | 116 |
private FeatureStore sourceStore; |
63 | 117 |
private FeatureStore targetStore; |
64 | 118 |
|
65 |
private final Map<String,ProcessFieldParameters> fields;
|
|
119 |
private Map<String,ProcessFieldParameters> fields; |
|
66 | 120 |
|
67 | 121 |
private int editMode; |
68 | 122 |
private int finishAndRestarEditEach; |
... | ... | |
323 | 377 |
return this; |
324 | 378 |
} |
325 | 379 |
|
380 |
@Override |
|
381 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
382 |
state.set("sourceFilter", this.sourceFilter ); |
|
383 |
if(this.sourceStore != null){ |
|
384 |
state.set("sourceStoreParams", this.sourceStore.getParameters()); |
|
385 |
} |
|
386 |
if(this.targetStore != null){ |
|
387 |
state.set("targetStoreParams", this.targetStore.getParameters()); |
|
388 |
} |
|
389 |
|
|
390 |
state.set("fields", this.fields ); |
|
391 |
state.set("editMode", this.editMode ); |
|
392 |
state.set("finishAndRestarEditEach", this.finishAndRestarEditEach ); |
|
393 |
state.set("finishAndRestarEdit", this.finishAndRestarEdit ); |
|
394 |
state.set("beginEditIfNeed", this.beginEditIfNeed ); |
|
395 |
state.set("finishEditAfterTerminate", this.finishEditAfterTerminate ); |
|
396 |
state.set("notifyUserIfNeedBeginEditing", this.notifyUserIfNeedBeginEditing ); |
|
397 |
state.set("sourceFieldJoin", this.sourceFieldJoin ); |
|
398 |
state.set("targetFieldJoin", this.targetFieldJoin ); |
|
399 |
state.set("insertIfNotExistsTarget", this.insertIfNotExistsTarget ); |
|
400 |
state.set("updateIfExistsTarget", this.updateIfExistsTarget ); |
|
401 |
state.set("deleteIfNotExiststInSource", this.deleteIfNotExiststInSource ); |
|
402 |
state.set("updateIfExistsInTargetCondition", this.updateIfExistsInTargetCondition ); |
|
403 |
|
|
404 |
} |
|
405 |
|
|
406 |
@Override |
|
407 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
408 |
this.sourceFilter = (Expression)state.get("sourceFilter"); |
|
409 |
|
|
410 |
|
|
411 |
DataManager dataManager = DALLocator.getDataManager(); |
|
412 |
DataStoreParameters sourceStoreParams = (DataStoreParameters) state.get("sourceStoreParams"); |
|
413 |
if (sourceStoreParams != null && sourceStoreParams instanceof DataStoreParameters) { |
|
414 |
try { |
|
415 |
this.sourceStore = (FeatureStore) dataManager.openStore(sourceStoreParams.getProviderName(), sourceStoreParams); |
|
416 |
} catch (Exception ex) { |
|
417 |
LOGGER.warn("Can't open source store '"+sourceStoreParams.getDescription()+"'", ex); |
|
418 |
} |
|
419 |
} |
|
420 |
|
|
421 |
DataStoreParameters targetStoreParams = (DataStoreParameters)state.get("targetStoreParams"); |
|
422 |
if(targetStoreParams != null && targetStoreParams instanceof DataStoreParameters){ |
|
423 |
try { |
|
424 |
this.targetStore = (FeatureStore) dataManager.openStore(targetStoreParams.getProviderName(), targetStoreParams); |
|
425 |
} catch (Exception ex) { |
|
426 |
LOGGER.warn("Can't open target store '"+sourceStoreParams.getDescription()+"'", ex); |
|
427 |
} |
|
428 |
} |
|
429 |
|
|
430 |
this.fields = state.getMap("fields"); |
|
431 |
this.editMode = state.getInt("editMode"); |
|
432 |
this.finishAndRestarEditEach = state.getInt("finishAndRestarEditEach"); |
|
433 |
this.finishAndRestarEdit = state.getBoolean("finishAndRestarEdit"); |
|
434 |
this.beginEditIfNeed = state.getBoolean("beginEditIfNeed"); |
|
435 |
this.finishEditAfterTerminate = state.getBoolean("finishEditAfterTerminate"); |
|
436 |
this.notifyUserIfNeedBeginEditing = state.getBoolean("notifyUserIfNeedBeginEditing"); |
|
437 |
this.sourceFieldJoin = state.getString("sourceFieldJoin"); |
|
438 |
this.targetFieldJoin = state.getString("targetFieldJoin"); |
|
439 |
this.insertIfNotExistsTarget = state.getBoolean("insertIfNotExistsTarget"); |
|
440 |
this.updateIfExistsTarget = state.getBoolean("updateIfExistsTarget"); |
|
441 |
this.deleteIfNotExiststInSource = state.getBoolean("deleteIfNotExiststInSource"); |
|
442 |
this.updateIfExistsInTargetCondition = (Expression)state.get("updateIfExistsInTargetCondition"); |
|
443 |
} |
|
444 |
|
|
445 |
public static void selfRegister() { |
|
446 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
447 |
|
|
448 |
DynStruct definition |
|
449 |
= manager.addDefinition(CopyTable2ProcessParametersImpl.class, |
|
450 |
"CopyTable2ProcessParameters", |
|
451 |
"CopyTable2ProcessParameters Persistence definition", |
|
452 |
null, |
|
453 |
null); |
|
454 |
|
|
455 |
ProcessFieldParametersImpl.selfRegister(); |
|
456 |
|
|
457 |
definition.addDynFieldObject("sourceStoreParams") |
|
458 |
.setClassOfValue(DataParameters.class) |
|
459 |
.setMandatory(true); |
|
460 |
definition.addDynFieldObject("targetStoreParams") |
|
461 |
.setClassOfValue(DataParameters.class) |
|
462 |
.setMandatory(true); |
|
463 |
definition.addDynFieldObject("sourceFilter") |
|
464 |
.setClassOfValue(Expression.class) |
|
465 |
.setMandatory(false); |
|
466 |
definition.addDynFieldObject("updateIfExistsInTargetCondition") |
|
467 |
.setClassOfValue(Expression.class) |
|
468 |
.setMandatory(false); |
|
469 |
definition.addDynFieldMap("fields") |
|
470 |
.setClassOfItems(ProcessFieldParametersImpl.class) |
|
471 |
.setMandatory(true); |
|
472 |
definition.addDynFieldInt("editMode") |
|
473 |
.setMandatory(true); |
|
474 |
definition.addDynFieldInt("finishAndRestarEditEach") |
|
475 |
.setMandatory(true); |
|
476 |
definition.addDynFieldBoolean("finishAndRestarEdit") |
|
477 |
.setMandatory(true); |
|
478 |
definition.addDynFieldBoolean("beginEditIfNeed") |
|
479 |
.setMandatory(true); |
|
480 |
definition.addDynFieldBoolean("finishEditAfterTerminate") |
|
481 |
.setMandatory(true); |
|
482 |
definition.addDynFieldBoolean("notifyUserIfNeedBeginEditing") |
|
483 |
.setMandatory(true); |
|
484 |
definition.addDynFieldString("sourceFieldJoin") |
|
485 |
.setMandatory(true); |
|
486 |
definition.addDynFieldString("targetFieldJoin") |
|
487 |
.setMandatory(true); |
|
488 |
definition.addDynFieldBoolean("insertIfNotExistsTarget") |
|
489 |
.setMandatory(true); |
|
490 |
definition.addDynFieldBoolean("updateIfExistsTarget") |
|
491 |
.setMandatory(true); |
|
492 |
definition.addDynFieldBoolean("deleteIfNotExiststInSource") |
|
493 |
.setMandatory(true); |
|
494 |
} |
|
495 |
|
|
496 |
public String toString() { |
|
497 |
StringBuilder builder = new StringBuilder(); |
|
498 |
builder.append("SOURCE: "); |
|
499 |
DataStoreParameters sourceParameters = this.sourceStore.getParameters(); |
|
500 |
if(sourceParameters instanceof JDBCStoreParameters) { |
|
501 |
builder.append(((JDBCStoreParameters)sourceParameters).getUrl()); |
|
502 |
builder.append(" -> "); |
|
503 |
builder.append(((JDBCStoreParameters) sourceParameters).getTable()); |
|
504 |
} else if(sourceParameters instanceof FilesystemStoreParameters) { |
|
505 |
builder.append(((FilesystemStoreParameters)sourceParameters).getFile().getAbsolutePath()); |
|
506 |
} |
|
507 |
builder.append("\n"); |
|
508 |
builder.append("TARGET: "); |
|
509 |
DataStoreParameters targetParameters = this.targetStore.getParameters(); |
|
510 |
if(targetParameters instanceof JDBCStoreParameters) { |
|
511 |
builder.append(((JDBCStoreParameters)targetParameters).getUrl()); |
|
512 |
builder.append(" -> "); |
|
513 |
builder.append(((JDBCStoreParameters) targetParameters).getTable()); |
|
514 |
} else if(targetParameters instanceof FilesystemStoreParameters) { |
|
515 |
builder.append(((FilesystemStoreParameters)sourceParameters).getFile().getAbsolutePath()); |
|
516 |
} |
|
517 |
builder.append("\n"); |
|
518 |
builder.append("FIELDS: "); |
|
519 |
for (Map.Entry<String, ProcessFieldParameters> entry : this.fields.entrySet()) { |
|
520 |
builder.append("\n"); |
|
521 |
builder.append(" "); |
|
522 |
builder.append(entry.getKey()); |
|
523 |
builder.append(": "); |
|
524 |
ProcessFieldParameters value = entry.getValue(); |
|
525 |
if(value != null){ |
|
526 |
Expression expression = value.getExpression(); |
|
527 |
if(expression != null){ |
|
528 |
builder.append(expression.getPhrase()); |
|
529 |
} |
|
530 |
} |
|
531 |
} |
|
532 |
builder.append("\n"); |
|
533 |
builder.append("EDIT MODE: "); |
|
534 |
builder.append(this.editMode); |
|
535 |
builder.append("\n"); |
|
536 |
builder.append("FINISH AND RESTART EDIT EACH: "); |
|
537 |
builder.append(this.finishAndRestarEditEach); |
|
538 |
builder.append("\n"); |
|
539 |
builder.append("FINISH AND RESTART EDIT: "); |
|
540 |
builder.append(this.finishAndRestarEdit); |
|
541 |
|
|
542 |
builder.append("\n"); |
|
543 |
builder.append("BEGIN EDIT IF NEED: "); |
|
544 |
builder.append(this.beginEditIfNeed); |
|
545 |
builder.append("\n"); |
|
546 |
builder.append("FINISH EDIT AFTER TERMINATE: "); |
|
547 |
builder.append(this.finishEditAfterTerminate); |
|
548 |
builder.append("\n"); |
|
549 |
builder.append("NOTIFY USER IF NEED BEGIN EDITING: "); |
|
550 |
builder.append(this.notifyUserIfNeedBeginEditing); |
|
551 |
builder.append("\n"); |
|
552 |
builder.append("SOURCE FIELD JOIN: "); |
|
553 |
builder.append(this.sourceFieldJoin); |
|
554 |
builder.append("\n"); |
|
555 |
builder.append("TARGET FIELD JOIN: "); |
|
556 |
builder.append(this.targetFieldJoin); |
|
557 |
builder.append("\n"); |
|
558 |
builder.append("INSERT IF NOT EXISTS TARGET: "); |
|
559 |
builder.append(this.insertIfNotExistsTarget); |
|
560 |
builder.append("\n"); |
|
561 |
builder.append("UPDATE IF EXISTS TARGET: "); |
|
562 |
builder.append(this.updateIfExistsTarget); |
|
563 |
builder.append("\n"); |
|
564 |
builder.append("DELETE IF NOT EXISTS IN SOURCE: "); |
|
565 |
builder.append(this.deleteIfNotExiststInSource); |
|
566 |
builder.append("\n"); |
|
567 |
builder.append("UPDATE IF EXISTS IN TARGET CONDITION: "); |
|
568 |
if(this.updateIfExistsInTargetCondition != null){ |
|
569 |
builder.append(this.updateIfExistsInTargetCondition.getPhrase()); |
|
570 |
} |
|
571 |
return builder.toString(); |
|
572 |
} |
|
573 |
|
|
574 |
|
|
575 |
|
|
326 | 576 |
} |
Also available in: Unified diff