Revision 45739 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java
DefaultFeatureStore.java | ||
---|---|---|
21 | 21 |
* For any additional information, do not hesitate to contact us |
22 | 22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
23 | 23 |
*/ |
24 |
|
|
25 | 24 |
package org.gvsig.fmap.dal.feature.impl; |
26 | 25 |
|
27 | 26 |
import java.util.ArrayList; |
... | ... | |
73 | 72 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
74 | 73 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
75 | 74 |
import org.gvsig.fmap.dal.feature.Feature; |
75 |
import static org.gvsig.fmap.dal.feature.Feature.CHECK_REQUIREDS; |
|
76 |
import static org.gvsig.fmap.dal.feature.Feature.CHECK_RULES_AT_EDITING; |
|
77 |
import static org.gvsig.fmap.dal.feature.Feature.CHECK_RULES_AT_FINISH; |
|
76 | 78 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
77 | 79 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
78 | 80 |
import org.gvsig.fmap.dal.feature.FeatureCache; |
... | ... | |
96 | 98 |
import org.gvsig.fmap.dal.feature.FeatureType.FeatureTypeChanged; |
97 | 99 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
98 | 100 |
import org.gvsig.fmap.dal.feature.exception.AlreadyEditingException; |
99 |
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException; |
|
100 | 101 |
import org.gvsig.fmap.dal.feature.exception.CreateFeatureException; |
101 | 102 |
import org.gvsig.fmap.dal.feature.exception.DataExportException; |
102 | 103 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
... | ... | |
175 | 176 |
import org.gvsig.tools.undo.RedoException; |
176 | 177 |
import org.gvsig.tools.undo.UndoException; |
177 | 178 |
import org.gvsig.tools.undo.command.Command; |
179 |
import org.gvsig.tools.util.ChainedIterator; |
|
178 | 180 |
import org.gvsig.tools.util.GetItemWithSizeIsEmptyAndIterator64; |
179 | 181 |
import org.gvsig.tools.util.HasAFile; |
180 | 182 |
import org.gvsig.tools.util.PropertiesSupportHelper; |
... | ... | |
184 | 186 |
|
185 | 187 |
@SuppressWarnings("UseSpecificCatch") |
186 | 188 |
public class DefaultFeatureStore extends AbstractDataStore implements |
187 |
DataStoreInitializer2, FeatureStoreProviderServices, FeatureStore, |
|
188 |
SupportTransactions, Observer { |
|
189 |
DataStoreInitializer2, FeatureStoreProviderServices, FeatureStore,
|
|
190 |
SupportTransactions, Observer {
|
|
189 | 191 |
|
190 | 192 |
private static final String PERSISTENCE_DEFINITION_NAME = "FeatureStore"; |
191 | 193 |
|
... | ... | |
193 | 195 |
private FeatureSelection selection; |
194 | 196 |
private FeatureLocks locks; |
195 | 197 |
|
196 |
private DelegateWeakReferencingObservable delegateObservable =
|
|
197 |
new DelegateWeakReferencingObservable(this); |
|
198 |
private DelegateWeakReferencingObservable delegateObservable |
|
199 |
= new DelegateWeakReferencingObservable(this);
|
|
198 | 200 |
|
199 | 201 |
private FeatureCommandsStack commands; |
200 |
|
|
202 |
|
|
201 | 203 |
/* |
202 | 204 |
TODO: Sustituir estos tres manager por un EditingManager |
203 |
*/ |
|
205 |
*/
|
|
204 | 206 |
private FeatureTypeManager featureTypeManager; |
205 | 207 |
private FeatureManager featureManager; |
206 | 208 |
private SpatialManager spatialManager; |
... | ... | |
234 | 236 |
private final StateInformation state; |
235 | 237 |
|
236 | 238 |
private FeatureStoreTimeSupport timeSupport; |
237 |
|
|
239 |
|
|
238 | 240 |
private PropertiesSupportHelper propertiesSupportHelper; |
239 | 241 |
private DataTransaction transaction; |
240 |
|
|
242 |
|
|
241 | 243 |
private String editingSessionCode; |
242 | 244 |
|
243 | 245 |
private class StateInformation extends HashMap<Object, Object> { |
... | ... | |
272 | 274 |
} |
273 | 275 |
|
274 | 276 |
public void setBreakingsCause(Throwable cause) { |
275 |
if( this.breakingsCause==null ) {
|
|
277 |
if (this.breakingsCause == null) {
|
|
276 | 278 |
this.breakingsCause = cause; |
277 | 279 |
} |
278 | 280 |
this.broken = true; |
279 | 281 |
} |
280 | 282 |
} |
281 | 283 |
|
282 |
|
|
283 |
|
|
284 | 284 |
/* |
285 | 285 |
* TODO: |
286 | 286 |
* |
... | ... | |
289 | 289 |
* featureType al que se le han cambiado las reglas de validacion cuando |
290 | 290 |
* hasStrongChanges=false. |
291 | 291 |
*/ |
292 |
|
|
293 | 292 |
public DefaultFeatureStore() { |
294 | 293 |
this.state = new StateInformation(); |
295 | 294 |
} |
296 |
|
|
295 |
|
|
297 | 296 |
@Override |
298 | 297 |
protected DataManager getDataManager() { |
299 | 298 |
return this.dataManager; |
... | ... | |
301 | 300 |
|
302 | 301 |
@Override |
303 | 302 |
public void intialize(DataManager dataManager, |
304 |
DataStoreParameters parameters) throws InitializeException { |
|
303 |
DataStoreParameters parameters) throws InitializeException {
|
|
305 | 304 |
|
306 | 305 |
DynObjectManager dynManager = ToolsLocator.getDynObjectManager(); |
307 | 306 |
|
308 | 307 |
this.metadata = (DelegatedDynObject) dynManager.createDynObject( |
309 |
FeatureStore.METADATA_DEFINITION_NAME, |
|
310 |
MetadataManager.METADATA_NAMESPACE |
|
308 |
FeatureStore.METADATA_DEFINITION_NAME,
|
|
309 |
MetadataManager.METADATA_NAMESPACE
|
|
311 | 310 |
); |
312 | 311 |
|
313 | 312 |
this.dataManager = (DefaultDataManager) dataManager; |
... | ... | |
336 | 335 |
// fixFeatureTypeFromParameters |
337 | 336 |
this.provider.fixFeatureTypeFromParameters(); |
338 | 337 |
try { |
339 |
if( defaultFeatureType!=null ) {
|
|
338 |
if (defaultFeatureType != null) {
|
|
340 | 339 |
FeatureAttributeDescriptor attrGeom = defaultFeatureType.getDefaultGeometryAttribute(); |
341 |
if (attrGeom!=null) {
|
|
340 |
if (attrGeom != null) {
|
|
342 | 341 |
DefaultFeatureAttributeDescriptor gattr = (DefaultFeatureAttributeDescriptor) attrGeom; |
343 | 342 |
IProjection srs = (IProjection) this.getDynValue(METADATA_CRS); |
344 |
if( srs!=null && srs!=gattr.getSRS() ) {
|
|
343 |
if (srs != null && srs != gattr.getSRS()) {
|
|
345 | 344 |
gattr.setSRSForced(srs); |
346 | 345 |
} |
347 | 346 |
} |
348 | 347 |
} |
349 |
} catch(Throwable th) { |
|
350 |
LOGGER.warn("Can't patch DAL file",th); |
|
348 |
} catch (Throwable th) {
|
|
349 |
LOGGER.warn("Can't patch DAL file", th);
|
|
351 | 350 |
} |
352 | 351 |
} |
353 |
|
|
352 |
|
|
354 | 353 |
@Override |
355 | 354 |
public DataStoreParameters getParameters() { |
356 |
if( this.parameters==null ) {
|
|
355 |
if (this.parameters == null) {
|
|
357 | 356 |
LOGGER.warn("Store parametes are null"); |
358 | 357 |
} |
359 | 358 |
return parameters; |
... | ... | |
370 | 369 |
} |
371 | 370 |
|
372 | 371 |
@Override |
373 |
public UnmodifiableBasicMap<String,DataStore> getChildren() { |
|
372 |
public UnmodifiableBasicMap<String, DataStore> getChildren() {
|
|
374 | 373 |
UnmodifiableBasicMap<String, DataStore> children = this.provider.getChildren(); |
375 |
if( children == null ) {
|
|
374 |
if (children == null) {
|
|
376 | 375 |
return UnmodifiableBasicMap.EMPTY_UNMODIFIABLEBASICMAP; |
377 | 376 |
} |
378 | 377 |
return children; |
... | ... | |
398 | 397 |
// TODO: Se puede hacer un open estando en edicion ? |
399 | 398 |
try { |
400 | 399 |
throw new IllegalStateException(); |
401 |
} catch(Exception ex) { |
|
402 |
LOGGER.warn("Opening a store in editing/append mode ("+this.getFullName()+").",ex);
|
|
400 |
} catch (Exception ex) {
|
|
401 |
LOGGER.warn("Opening a store in editing/append mode (" + this.getFullName() + ").", ex);
|
|
403 | 402 |
} |
404 | 403 |
} |
405 |
if( this.notifyChange(DataStoreNotification.BEFORE_OPEN).isCanceled() ) {
|
|
406 |
return; |
|
404 |
if (this.notifyChange(DataStoreNotification.BEFORE_OPEN).isCanceled()) {
|
|
405 |
return;
|
|
407 | 406 |
} |
408 | 407 |
this.provider.open(); |
409 | 408 |
this.notifyChange(DataStoreNotification.AFTER_OPEN); |
... | ... | |
414 | 413 |
if (this.mode != MODE_QUERY) { |
415 | 414 |
throw new IllegalStateException(); |
416 | 415 |
} |
417 |
if( this.notifyChange(FeatureStoreNotification.BEFORE_REFRESH).isCanceled() ) {
|
|
418 |
return; |
|
416 |
if (this.notifyChange(FeatureStoreNotification.BEFORE_REFRESH).isCanceled()) {
|
|
417 |
return;
|
|
419 | 418 |
} |
420 |
if( state.isBroken() ) {
|
|
419 |
if (state.isBroken()) {
|
|
421 | 420 |
this.load(state); |
422 | 421 |
} else { |
423 | 422 |
this.featureCount = null; |
... | ... | |
431 | 430 |
// TODO: Se puede hacer un close estando en edicion ? |
432 | 431 |
try { |
433 | 432 |
throw new IllegalStateException(); |
434 |
} catch(Exception ex) { |
|
435 |
LOGGER.warn("Clossing a store in editing/append mode ("+this.getFullName()+").",ex);
|
|
433 |
} catch (Exception ex) {
|
|
434 |
LOGGER.warn("Clossing a store in editing/append mode (" + this.getFullName() + ").", ex);
|
|
436 | 435 |
} |
437 | 436 |
} |
438 |
if( this.notifyChange(DataStoreNotification.BEFORE_CLOSE).isCanceled() ) {
|
|
439 |
return; |
|
437 |
if (this.notifyChange(DataStoreNotification.BEFORE_CLOSE).isCanceled()) {
|
|
438 |
return;
|
|
440 | 439 |
} |
441 | 440 |
this.featureCount = null; |
442 | 441 |
this.provider.close(); |
... | ... | |
449 | 448 |
// TODO: Se puede hacer un dispose estando en edicion ? |
450 | 449 |
try { |
451 | 450 |
throw new IllegalStateException(); |
452 |
} catch(Exception ex) { |
|
453 |
LOGGER.warn("Dispossing a store in editing/append mode ("+this.getFullName()+").",ex);
|
|
451 |
} catch (Exception ex) {
|
|
452 |
LOGGER.warn("Dispossing a store in editing/append mode (" + this.getFullName() + ").", ex);
|
|
454 | 453 |
} |
455 | 454 |
} |
456 |
if( this.notifyChange(DataStoreNotification.BEFORE_DISPOSE).isCanceled() ) {
|
|
457 |
return; |
|
455 |
if (this.notifyChange(DataStoreNotification.BEFORE_DISPOSE).isCanceled()) {
|
|
456 |
return;
|
|
458 | 457 |
} |
459 | 458 |
this.disposeIndexes(); |
460 |
if( this.provider!=null ) {
|
|
459 |
if (this.provider != null) {
|
|
461 | 460 |
this.provider.dispose(); |
462 | 461 |
} |
463 | 462 |
if (this.selection != null) { |
... | ... | |
490 | 489 |
@Override |
491 | 490 |
public boolean allowWrite() { |
492 | 491 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
493 |
if( ! identityManager.getCurrentIdentity().isAuthorized(DataManager.WRITE_STORE_AUTHORIZATION,this.getParameters(), this.getName()) ) {
|
|
492 |
if (!identityManager.getCurrentIdentity().isAuthorized(DataManager.WRITE_STORE_AUTHORIZATION, this.getParameters(), this.getName())) {
|
|
494 | 493 |
return false; |
495 | 494 |
} |
496 | 495 |
return this.provider.allowWrite(); |
... | ... | |
503 | 502 |
|
504 | 503 |
@Override |
505 | 504 |
public DataServerExplorer getExplorer() throws ReadException, |
506 |
ValidateDataParametersException { |
|
507 |
if( this.state.isBroken() ) {
|
|
505 |
ValidateDataParametersException {
|
|
506 |
if (this.state.isBroken()) {
|
|
508 | 507 |
try { |
509 | 508 |
return this.provider.getExplorer(); |
510 |
} catch(Throwable th) { |
|
509 |
} catch (Throwable th) {
|
|
511 | 510 |
return null; |
512 | 511 |
} |
513 | 512 |
} else { |
... | ... | |
526 | 525 |
* return this.provider.getMetadata(); |
527 | 526 |
* } |
528 | 527 |
*/ |
529 |
|
|
530 | 528 |
@Override |
531 | 529 |
public Envelope getEnvelope() throws DataException { |
532 | 530 |
if (this.mode == MODE_FULLEDIT) { |
533 |
// Just in case another thread tries to write in the store
|
|
534 |
synchronized (this) {
|
|
535 |
return this.spatialManager.getEnvelope();
|
|
536 |
}
|
|
531 |
// Just in case another thread tries to write in the store
|
|
532 |
synchronized (this) {
|
|
533 |
return this.spatialManager.getEnvelope();
|
|
534 |
}
|
|
537 | 535 |
} |
538 |
if (hasDynValue(DataStore.METADATA_ENVELOPE)){ |
|
539 |
return (Envelope)getDynValue(DataStore.METADATA_ENVELOPE); |
|
536 |
if (hasDynValue(DataStore.METADATA_ENVELOPE)) {
|
|
537 |
return (Envelope) getDynValue(DataStore.METADATA_ENVELOPE);
|
|
540 | 538 |
} |
541 | 539 |
Envelope envelope = this.provider.getEnvelope(); |
542 |
if( envelope!=null ) {
|
|
540 |
if (envelope != null) {
|
|
543 | 541 |
return envelope; |
544 | 542 |
} |
545 | 543 |
FeatureAttributeDescriptor attrdesc = this.getDefaultFeatureType().getDefaultGeometryAttribute(); |
546 |
if( attrdesc == null || !attrdesc.isComputed() ) {
|
|
544 |
if (attrdesc == null || !attrdesc.isComputed()) {
|
|
547 | 545 |
return null; |
548 | 546 |
} |
549 | 547 |
final int index = attrdesc.getIndex(); |
... | ... | |
551 | 549 |
try { |
552 | 550 |
this.accept((Object obj) -> { |
553 | 551 |
Feature f = (Feature) obj; |
554 |
Geometry g = (Geometry) f.get(index);
|
|
555 |
if( g == null ) {
|
|
552 |
Geometry g = (Geometry) f.get(index); |
|
553 |
if (g == null) {
|
|
556 | 554 |
return; |
557 | 555 |
} |
558 |
if( envelopeValue.getValue()==null ) {
|
|
556 |
if (envelopeValue.getValue() == null) {
|
|
559 | 557 |
envelopeValue.setValue(g.getEnvelope()); |
560 | 558 |
} else { |
561 | 559 |
envelopeValue.getValue().add(g); |
... | ... | |
579 | 577 |
|
580 | 578 |
@Override |
581 | 579 |
public FeatureSelection createDefaultFeatureSelection() |
582 |
throws DataException { |
|
580 |
throws DataException {
|
|
583 | 581 |
return new DefaultFeatureSelection(this); |
584 | 582 |
} |
585 | 583 |
|
586 | 584 |
@Override |
587 | 585 |
public FeatureProvider createDefaultFeatureProvider(FeatureType type) |
588 |
throws DataException { |
|
586 |
throws DataException {
|
|
589 | 587 |
if (type.hasOID()) { |
590 | 588 |
return new DefaultFeatureProvider(type, |
591 |
this.provider.createNewOID()); |
|
589 |
this.provider.createNewOID());
|
|
592 | 590 |
} |
593 | 591 |
return new DefaultFeatureProvider(type); |
594 | 592 |
} |
... | ... | |
620 | 618 |
while (iterAttr.hasNext()) { |
621 | 619 |
attr = (DefaultFeatureAttributeDescriptor) iterAttr.next(); |
622 | 620 |
if ((attr.getEvaluator() != null) |
623 |
&& (attr.getEvaluator() instanceof Persistent)) { |
|
621 |
&& (attr.getEvaluator() instanceof Persistent)) {
|
|
624 | 622 |
attrs.add(attr); |
625 | 623 |
} |
626 | 624 |
} |
... | ... | |
641 | 639 |
|
642 | 640 |
@Override |
643 | 641 |
public void loadFromState(final PersistentState persistentState) |
644 |
throws PersistenceException { |
|
642 |
throws PersistenceException {
|
|
645 | 643 |
if (this.provider != null) { |
646 | 644 |
throw new PersistenceStoreAlreadyLoadedException(this.getName()); |
647 | 645 |
} |
... | ... | |
651 | 649 |
state.clear(); |
652 | 650 |
try { |
653 | 651 |
state.put("parameters", persistentState.get("parameters")); |
654 |
} catch(Throwable th) { |
|
652 |
} catch (Throwable th) {
|
|
655 | 653 |
state.setBreakingsCause(th); |
656 | 654 |
} |
657 | 655 |
try { |
658 | 656 |
state.put("selection", persistentState.get("selection")); |
659 |
} catch(Throwable th) { |
|
657 |
} catch (Throwable th) {
|
|
660 | 658 |
state.setBreakingsCause(th); |
661 | 659 |
} |
662 |
try {
|
|
663 |
state.put("transforms", persistentState.get("transforms"));
|
|
664 |
} catch(Throwable th) { |
|
660 |
try {
|
|
661 |
state.put("transforms", persistentState.get("transforms")); |
|
662 |
} catch (Throwable th) {
|
|
665 | 663 |
state.setBreakingsCause(th); |
666 | 664 |
} |
667 | 665 |
try { |
668 |
state.put("evaluatedAttributes", persistentState.get("evaluatedAttributes"));
|
|
669 |
} catch(Throwable th) { |
|
666 |
state.put("evaluatedAttributes", persistentState.get("evaluatedAttributes")); |
|
667 |
} catch (Throwable th) {
|
|
670 | 668 |
state.setBreakingsCause(th); |
671 | 669 |
} |
672 | 670 |
try { |
673 | 671 |
state.put("defaultFeatureTypeId", persistentState.getString("defaultFeatureTypeId")); |
674 |
} catch(Throwable th) { |
|
672 |
} catch (Throwable th) {
|
|
675 | 673 |
state.setBreakingsCause(th); |
676 | 674 |
} |
677 | 675 |
load(state); |
678 |
((DefaultDataManager)this.getDataManager()).addObservers(this); |
|
676 |
((DefaultDataManager) this.getDataManager()).addObservers(this);
|
|
679 | 677 |
} |
680 | 678 |
|
681 | 679 |
private void load(StateInformation state) { |
... | ... | |
686 | 684 |
DataStoreParameters params = (DataStoreParameters) state.get("parameters"); |
687 | 685 |
try { |
688 | 686 |
intialize(dataManager, params); |
689 |
} catch(Throwable th) { |
|
687 |
} catch (Throwable th) {
|
|
690 | 688 |
state.setBreakingsCause(th); |
691 | 689 |
} |
692 | 690 |
|
693 | 691 |
try { |
694 | 692 |
DataStoreProvider prov = dataManager.createProvider( |
695 |
getStoreProviderServices(), |
|
696 |
params |
|
693 |
getStoreProviderServices(),
|
|
694 |
params
|
|
697 | 695 |
); |
698 | 696 |
setProvider(prov); |
699 |
} catch(Throwable th) { |
|
697 |
} catch (Throwable th) {
|
|
700 | 698 |
LOGGER.warn("Can't load store from state.", th); |
701 | 699 |
state.setBreakingsCause(th); |
702 | 700 |
} |
703 | 701 |
try { |
704 | 702 |
selection = (FeatureSelection) state.get("selection"); |
705 |
} catch(Throwable th) { |
|
703 |
} catch (Throwable th) {
|
|
706 | 704 |
state.setBreakingsCause(th); |
707 | 705 |
} |
708 | 706 |
|
709 |
try {
|
|
707 |
try {
|
|
710 | 708 |
this.transforms = (DefaultFeatureStoreTransforms) state.get("transforms"); |
711 | 709 |
this.transforms.setFeatureStore(this); |
712 |
for( FeatureStoreTransform transform : this.transforms ) {
|
|
710 |
for (FeatureStoreTransform transform : this.transforms) {
|
|
713 | 711 |
try { |
714 | 712 |
transform.setUp(); |
715 |
} catch(Throwable th) { |
|
713 |
} catch (Throwable th) {
|
|
716 | 714 |
state.setBreakingsCause(th); |
717 | 715 |
} |
718 | 716 |
} |
719 |
} catch(Throwable th) { |
|
717 |
} catch (Throwable th) {
|
|
720 | 718 |
state.setBreakingsCause(th); |
721 | 719 |
} |
722 | 720 |
|
723 | 721 |
try { |
724 | 722 |
Map evaluatedAttributes = (Map) state.get("evaluatedAttributes"); |
725 | 723 |
if ((evaluatedAttributes != null) && !evaluatedAttributes.isEmpty()) { |
726 |
Iterator iterEntries = evaluatedAttributes.entrySet().iterator(); |
|
727 |
while (iterEntries.hasNext()) { |
|
728 |
Entry entry = (Entry) iterEntries.next(); |
|
729 |
List attrs = (List) entry.getValue(); |
|
730 |
if (attrs.isEmpty()) { |
|
731 |
continue; |
|
732 |
} |
|
733 |
int fTypePos = -1; |
|
734 |
DefaultFeatureType type = null; |
|
735 |
for (int i = 0; i < featureTypes.size(); i++) { |
|
736 |
type = (DefaultFeatureType) featureTypes.get(i); |
|
737 |
if (type.getId().equals(entry.getKey())) { |
|
738 |
fTypePos = i; |
|
739 |
break; |
|
740 |
} |
|
741 |
} |
|
742 |
if (type == null) { |
|
743 |
throw new PersistenceCantFindFeatureTypeException( |
|
744 |
getName(), (String) entry.getKey()); |
|
745 |
} |
|
746 |
DefaultEditableFeatureType eType = (DefaultEditableFeatureType) type.getEditable(); |
|
747 |
Iterator<FeatureAttributeDescriptor> iterAttr = attrs.iterator(); |
|
748 |
while (iterAttr.hasNext()) { |
|
749 |
FeatureAttributeDescriptor attr = iterAttr.next(); |
|
750 |
eType.addLike(attr); |
|
751 |
} |
|
752 |
featureTypes.set(fTypePos, eType.getNotEditableCopy()); |
|
753 |
|
|
724 |
Iterator iterEntries = evaluatedAttributes.entrySet().iterator(); |
|
725 |
while (iterEntries.hasNext()) { |
|
726 |
Entry entry = (Entry) iterEntries.next(); |
|
727 |
List attrs = (List) entry.getValue(); |
|
728 |
if (attrs.isEmpty()) { |
|
729 |
continue; |
|
754 | 730 |
} |
731 |
int fTypePos = -1; |
|
732 |
DefaultFeatureType type = null; |
|
733 |
for (int i = 0; i < featureTypes.size(); i++) { |
|
734 |
type = (DefaultFeatureType) featureTypes.get(i); |
|
735 |
if (type.getId().equals(entry.getKey())) { |
|
736 |
fTypePos = i; |
|
737 |
break; |
|
738 |
} |
|
739 |
} |
|
740 |
if (type == null) { |
|
741 |
throw new PersistenceCantFindFeatureTypeException( |
|
742 |
getName(), (String) entry.getKey()); |
|
743 |
} |
|
744 |
DefaultEditableFeatureType eType = (DefaultEditableFeatureType) type.getEditable(); |
|
745 |
Iterator<FeatureAttributeDescriptor> iterAttr = attrs.iterator(); |
|
746 |
while (iterAttr.hasNext()) { |
|
747 |
FeatureAttributeDescriptor attr = iterAttr.next(); |
|
748 |
eType.addLike(attr); |
|
749 |
} |
|
750 |
featureTypes.set(fTypePos, eType.getNotEditableCopy()); |
|
755 | 751 |
|
752 |
} |
|
753 |
|
|
756 | 754 |
} |
757 |
} catch(Throwable th) { |
|
755 |
} catch (Throwable th) {
|
|
758 | 756 |
state.setBreakingsCause(th); |
759 | 757 |
} |
760 | 758 |
|
761 |
|
|
762 | 759 |
try { |
763 | 760 |
String defaultFeatureTypeId = (String) state.get("defaultFeatureTypeId"); |
764 | 761 |
FeatureType ftype; |
765 | 762 |
|
766 |
if (defaultFeatureType == null ||
|
|
767 |
defaultFeatureType.getId() == null ||
|
|
768 |
!defaultFeatureType.getId().equals(defaultFeatureTypeId)) { |
|
763 |
if (defaultFeatureType == null |
|
764 |
|| defaultFeatureType.getId() == null
|
|
765 |
|| !defaultFeatureType.getId().equals(defaultFeatureTypeId)) {
|
|
769 | 766 |
|
770 |
ftype = getFeatureType(defaultFeatureTypeId);
|
|
771 |
if (ftype == null) {
|
|
772 |
/*
|
|
767 |
ftype = getFeatureType(defaultFeatureTypeId); |
|
768 |
if (ftype == null) { |
|
769 |
/* |
|
773 | 770 |
* Un error en el m�todo de PostgreSQL getName(), hace que |
774 | 771 |
* el nombre del featureType sea valor retornado por el getProviderName() |
775 | 772 |
* De momento se pone este parche para apa�arlo y poder mantener compatibilidad |
776 | 773 |
* con proyectos antiguos (2.1 y 2.2) |
777 |
*/ |
|
778 |
ftype = getFeatureType(getName()); |
|
779 |
if(ftype == null ) { |
|
780 |
throw new RuntimeException("Can't locate feature type"); |
|
781 |
} |
|
774 |
*/ |
|
775 |
ftype = getFeatureType(getName()); |
|
776 |
if (ftype == null) { |
|
777 |
throw new RuntimeException("Can't locate feature type"); |
|
782 | 778 |
} |
783 |
defaultFeatureType = ftype; |
|
779 |
} |
|
780 |
defaultFeatureType = ftype; |
|
784 | 781 |
} |
785 |
} catch(Throwable th) { |
|
782 |
} catch (Throwable th) {
|
|
786 | 783 |
state.setBreakingsCause(th); |
787 | 784 |
} |
788 | 785 |
|
789 | 786 |
LOGGER.info("load() broken:{}, {}, {}.", |
790 |
new Object[] { state.isBroken(), this.getProviderName(), params }
|
|
787 |
new Object[]{state.isBroken(), this.getProviderName(), params}
|
|
791 | 788 |
); |
792 | 789 |
} |
793 | 790 |
|
... | ... | |
798 | 795 |
public static void registerPersistenceDefinition() { |
799 | 796 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
800 | 797 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
801 |
DynStruct definition =
|
|
802 |
manager.addDefinition(DefaultFeatureStore.class, |
|
803 |
PERSISTENCE_DEFINITION_NAME, PERSISTENCE_DEFINITION_NAME |
|
804 |
+ " Persistent definition", null, null); |
|
798 |
DynStruct definition |
|
799 |
= manager.addDefinition(DefaultFeatureStore.class,
|
|
800 |
PERSISTENCE_DEFINITION_NAME, PERSISTENCE_DEFINITION_NAME
|
|
801 |
+ " Persistent definition", null, null);
|
|
805 | 802 |
definition.addDynFieldString("dataStoreName").setMandatory(true) |
806 |
.setPersistent(true); |
|
803 |
.setPersistent(true);
|
|
807 | 804 |
|
808 | 805 |
definition.addDynFieldObject("parameters") |
809 |
.setClassOfValue(DynObject.class).setMandatory(true) |
|
810 |
.setPersistent(true); |
|
806 |
.setClassOfValue(DynObject.class).setMandatory(true)
|
|
807 |
.setPersistent(true);
|
|
811 | 808 |
|
812 | 809 |
definition.addDynFieldObject("selection") |
813 |
.setClassOfValue(FeatureSelection.class).setMandatory(false) |
|
814 |
.setPersistent(true); |
|
810 |
.setClassOfValue(FeatureSelection.class).setMandatory(false)
|
|
811 |
.setPersistent(true);
|
|
815 | 812 |
|
816 | 813 |
definition.addDynFieldObject("transforms") |
817 |
.setClassOfValue(DefaultFeatureStoreTransforms.class) |
|
818 |
.setMandatory(true).setPersistent(true); |
|
814 |
.setClassOfValue(DefaultFeatureStoreTransforms.class)
|
|
815 |
.setMandatory(true).setPersistent(true);
|
|
819 | 816 |
|
820 | 817 |
definition.addDynFieldMap("evaluatedAttributes") |
821 |
.setClassOfItems(List.class) // List<DefaultFeatureAttributeDescriptor> |
|
822 |
.setMandatory(false).setPersistent(true); |
|
818 |
.setClassOfItems(List.class) // List<DefaultFeatureAttributeDescriptor>
|
|
819 |
.setMandatory(false).setPersistent(true);
|
|
823 | 820 |
|
824 | 821 |
definition.addDynFieldString("defaultFeatureTypeId") |
825 |
.setMandatory(true).setPersistent(true); |
|
822 |
.setMandatory(true).setPersistent(true);
|
|
826 | 823 |
} |
827 | 824 |
} |
828 | 825 |
|
829 | 826 |
public static void registerMetadataDefinition() throws MetadataException { |
830 | 827 |
MetadataManager manager = MetadataLocator.getMetadataManager(); |
831 | 828 |
if (manager.getDefinition(FeatureStore.METADATA_DEFINITION_NAME) == null) { |
832 |
DynStruct metadataDefinition =
|
|
833 |
manager.addDefinition(FeatureStore.METADATA_DEFINITION_NAME, null); |
|
829 |
DynStruct metadataDefinition |
|
830 |
= manager.addDefinition(FeatureStore.METADATA_DEFINITION_NAME, null);
|
|
834 | 831 |
metadataDefinition.extend(manager |
835 |
.getDefinition(DataStore.METADATA_DEFINITION_NAME)); |
|
832 |
.getDefinition(DataStore.METADATA_DEFINITION_NAME));
|
|
836 | 833 |
} |
837 | 834 |
} |
838 | 835 |
|
... | ... | |
840 | 837 |
// ==================================================================== |
841 | 838 |
// Gestion de la seleccion |
842 | 839 |
// |
843 |
|
|
844 | 840 |
@Override |
845 | 841 |
public void setSelection(DataSet selection) throws DataException { |
846 | 842 |
this.setSelection((FeatureSet) selection); |
... | ... | |
862 | 858 |
} |
863 | 859 |
|
864 | 860 |
public void setSelection(FeatureSet selection, boolean undoable) |
865 |
throws DataException { |
|
861 |
throws DataException {
|
|
866 | 862 |
if (selection == null) { |
867 | 863 |
if (undoable) { |
868 | 864 |
throw new SelectionNotAllowedException(getName()); |
... | ... | |
890 | 886 |
if (selection instanceof FeatureSelection) { |
891 | 887 |
if (undoable && isEditing()) { |
892 | 888 |
commands.selectionSet(this, this.selection, |
893 |
(FeatureSelection) selection); |
|
889 |
(FeatureSelection) selection);
|
|
894 | 890 |
} |
895 | 891 |
if (this.selection != null) { |
896 | 892 |
this.selection.dispose(); |
... | ... | |
901 | 897 |
commands.startComplex("_selectionSet"); |
902 | 898 |
} |
903 | 899 |
if (selection instanceof DefaultFeatureSelection) { |
904 |
DefaultFeatureSelection defSelection =
|
|
905 |
(DefaultFeatureSelection) selection; |
|
900 |
DefaultFeatureSelection defSelection |
|
901 |
= (DefaultFeatureSelection) selection;
|
|
906 | 902 |
defSelection.deselectAll(undoable); |
907 | 903 |
defSelection.select(selection, undoable); |
908 | 904 |
} else { |
... | ... | |
921 | 917 |
@Override |
922 | 918 |
public FeatureSelection createFeatureSelection() throws DataException { |
923 | 919 |
long maxSize = dataManager.getMaxSizeForSmallFeatureSelection(); |
924 |
if(this.provider.getFeatureCount()>maxSize) {
|
|
920 |
if (this.provider.getFeatureCount() > maxSize) {
|
|
925 | 921 |
return createLargeFeatureSelection(); |
926 | 922 |
} |
927 | 923 |
return this.provider.createFeatureSelection(); |
928 | 924 |
} |
929 |
|
|
925 |
|
|
930 | 926 |
@Override |
931 | 927 |
public FeatureSelection createLargeFeatureSelection() throws DataException { |
932 | 928 |
return new LargeFeatureSelection(this); |
933 |
|
|
929 |
|
|
934 | 930 |
} |
935 |
|
|
931 |
|
|
936 | 932 |
@Override |
937 | 933 |
public FeatureSelection createMemoryFeatureSelection() throws DataException { |
938 | 934 |
return this.provider.createFeatureSelection(); |
... | ... | |
951 | 947 |
// ==================================================================== |
952 | 948 |
// Gestion de notificaciones |
953 | 949 |
// |
954 |
|
|
955 | 950 |
@Override |
956 | 951 |
public FeatureStoreNotification notifyChange(FeatureStoreNotification storeNotification) { |
957 | 952 |
if (delegateObservable != null) { |
958 |
try { |
|
959 |
delegateObservable.notifyObservers(storeNotification); |
|
960 |
} catch (Throwable ex) { |
|
961 |
LOGGER.warn("Problems notifying changes in the store '"+this.getName()+" ("+storeNotification.getType()+").",ex);
|
|
962 |
} |
|
953 |
try {
|
|
954 |
delegateObservable.notifyObservers(storeNotification);
|
|
955 |
} catch (Throwable ex) {
|
|
956 |
LOGGER.warn("Problems notifying changes in the store '" + this.getName() + " (" + storeNotification.getType() + ").", ex);
|
|
957 |
}
|
|
963 | 958 |
} |
964 | 959 |
return storeNotification; |
965 | 960 |
} |
966 | 961 |
|
967 | 962 |
@Override |
968 | 963 |
public FeatureStoreNotification notifyChange(String notification) { |
969 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification)); |
|
964 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification));
|
|
970 | 965 |
} |
971 |
|
|
966 |
|
|
972 | 967 |
public FeatureStoreNotification notifyChange(String notification, String editingSessionCode) { |
973 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, editingSessionCode)); |
|
968 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, editingSessionCode));
|
|
974 | 969 |
} |
975 |
|
|
970 |
|
|
976 | 971 |
public FeatureStoreNotification notifyChange(String notification, String editingSessionCode, int editMode) { |
977 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, editingSessionCode, editMode)); |
|
972 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, editingSessionCode, editMode));
|
|
978 | 973 |
} |
979 |
|
|
974 |
|
|
980 | 975 |
public FeatureStoreNotification notifyChange(String notification, |
981 |
String editingSessionCode, |
|
982 |
Iterator<FeatureReference> deleteds,
|
|
983 |
Iterator<Feature> inserteds,
|
|
984 |
Iterator<Feature> updateds,
|
|
985 |
Iterator<FeatureTypeChanged> featureTypesChanged,
|
|
986 |
boolean isSelectionCompromised) { |
|
976 |
String editingSessionCode,
|
|
977 |
Iterator<FeatureReference> deleteds,
|
|
978 |
Iterator<EditableFeature> inserteds,
|
|
979 |
Iterator<EditableFeature> updateds,
|
|
980 |
Iterator<FeatureTypeChanged> featureTypesChanged,
|
|
981 |
boolean isSelectionCompromised) {
|
|
987 | 982 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, editingSessionCode, |
988 |
deleteds, inserteds, updateds, featureTypesChanged, isSelectionCompromised)); |
|
983 |
deleteds, inserteds, updateds, featureTypesChanged, isSelectionCompromised));
|
|
989 | 984 |
} |
990 | 985 |
|
991 | 986 |
@Override |
992 | 987 |
public FeatureStoreNotification notifyChange(String notification, FeatureProvider data) { |
993 | 988 |
Feature f = null; |
994 |
if( data !=null ) {
|
|
995 |
try { |
|
996 |
f = createFeature(data); |
|
997 |
} catch (Throwable ex) { |
|
998 |
LOGGER.warn("Problems creating a feature to notifying changes in the store '"+this.getName()+" ("+notification+").",ex);
|
|
999 |
} |
|
989 |
if (data != null) {
|
|
990 |
try {
|
|
991 |
f = createFeature(data);
|
|
992 |
} catch (Throwable ex) {
|
|
993 |
LOGGER.warn("Problems creating a feature to notifying changes in the store '" + this.getName() + " (" + notification + ").", ex);
|
|
994 |
}
|
|
1000 | 995 |
} |
1001 | 996 |
return notifyChange(notification, f); |
1002 | 997 |
} |
1003 | 998 |
|
1004 | 999 |
public FeatureStoreNotification notifyChange(String notification, Feature feature) { |
1005 | 1000 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, |
1006 |
feature)); |
|
1001 |
feature));
|
|
1007 | 1002 |
} |
1008 | 1003 |
|
1009 | 1004 |
public FeatureStoreNotification notifyChange(String notification, Command command) { |
1010 | 1005 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, |
1011 |
command)); |
|
1006 |
command));
|
|
1012 | 1007 |
} |
1013 | 1008 |
|
1014 | 1009 |
public FeatureStoreNotification notifyChange(String notification, EditableFeatureType type) { |
1015 | 1010 |
return notifyChange(new DefaultFeatureStoreNotification(this, notification, |
1016 |
type)); |
|
1011 |
type));
|
|
1017 | 1012 |
} |
1018 | 1013 |
|
1019 | 1014 |
@Override |
1020 | 1015 |
public FeatureStoreNotification notifyChange(String notification, Resource resource) { |
1021 | 1016 |
return notifyChange(new DefaultFeatureStoreNotification(this, |
1022 |
DataStoreNotification.RESOURCE_CHANGED)); |
|
1017 |
DataStoreNotification.RESOURCE_CHANGED));
|
|
1023 | 1018 |
} |
1024 | 1019 |
|
1025 | 1020 |
// |
1026 | 1021 |
// ==================================================================== |
1027 | 1022 |
// Gestion de bloqueos |
1028 | 1023 |
// |
1029 |
|
|
1030 | 1024 |
@Override |
1031 | 1025 |
public boolean isLocksSupported() { |
1032 | 1026 |
return this.provider.isLocksSupported(); |
... | ... | |
1048 | 1042 |
// ==================================================================== |
1049 | 1043 |
// Interface Observable |
1050 | 1044 |
// |
1051 |
|
|
1052 | 1045 |
@Override |
1053 | 1046 |
public void disableNotifications() { |
1054 | 1047 |
this.delegateObservable.disableNotifications(); |
... | ... | |
1101 | 1094 |
// - sus bloqueos |
1102 | 1095 |
// - sus recursos |
1103 | 1096 |
// |
1104 |
|
|
1105 | 1097 |
@Override |
1106 | 1098 |
public void update(Observable observable, Object notification) { |
1107 | 1099 |
if (observable instanceof FeatureSet) { |
... | ... | |
1116 | 1108 |
|
1117 | 1109 |
} |
1118 | 1110 |
} else if (observable instanceof FeatureReferenceSelection) { |
1119 |
if(notification instanceof String){
|
|
1120 |
this.notifyChange((String)notification);
|
|
1111 |
if (notification instanceof String) {
|
|
1112 |
this.notifyChange((String) notification);
|
|
1121 | 1113 |
} |
1122 | 1114 |
} |
1123 | 1115 |
} |
... | ... | |
1126 | 1118 |
// ==================================================================== |
1127 | 1119 |
// Edicion |
1128 | 1120 |
// |
1129 |
|
|
1130 | 1121 |
private void newVersionOfUpdate() { |
1131 | 1122 |
this.versionOfUpdate++; |
1132 | 1123 |
} |
... | ... | |
1143 | 1134 |
|
1144 | 1135 |
private void checkNotInAppendMode() throws IllegalStateException { |
1145 | 1136 |
if (mode == MODE_APPEND) { |
1146 |
throw new IllegalStateException("Error: store "
|
|
1147 |
+ this.getFullName() + " is in append mode");
|
|
1137 |
throw new IllegalStateException("Error: store "
|
|
1138 |
+ this.getFullName() + " is in append mode");
|
|
1148 | 1139 |
} |
1149 | 1140 |
} |
1150 | 1141 |
|
1151 | 1142 |
private void checkIsOwnFeature(Feature feature) |
1152 |
throws IllegalFeatureException { |
|
1143 |
throws IllegalFeatureException {
|
|
1153 | 1144 |
if (((DefaultFeature) feature).getStore() != this) { |
1154 | 1145 |
throw new IllegalFeatureException(this.getName()); |
1155 | 1146 |
} |
... | ... | |
1161 | 1152 |
if (commands != null) { |
1162 | 1153 |
try { |
1163 | 1154 |
commands.clear(); |
1164 |
} catch(Exception ex) { |
|
1165 |
LOGGER.trace("Can't clear commands",ex); |
|
1155 |
} catch (Exception ex) {
|
|
1156 |
LOGGER.trace("Can't clear commands", ex);
|
|
1166 | 1157 |
} |
1167 | 1158 |
commands = null; |
1168 | 1159 |
} |
... | ... | |
1182 | 1173 |
mode = MODE_QUERY; |
1183 | 1174 |
hasStrongChanges = true; // Lo deja a true por si las moscas |
1184 | 1175 |
hasInserts = true; |
1185 |
|
|
1176 |
|
|
1186 | 1177 |
this.editingSessionCode = null; |
1187 | 1178 |
} |
1188 | 1179 |
|
... | ... | |
1203 | 1194 |
mode = MODE_FULLEDIT; |
1204 | 1195 |
} |
1205 | 1196 |
switch (mode) { |
1206 |
case MODE_QUERY: |
|
1207 |
throw new IllegalStateException(this.getName()); |
|
1208 |
|
|
1209 |
case MODE_FULLEDIT: |
|
1210 |
if (!this.transforms.isEmpty()) { |
|
1197 |
case MODE_QUERY: |
|
1211 | 1198 |
throw new IllegalStateException(this.getName()); |
1212 |
} |
|
1213 |
if( notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING, |
|
1214 |
newSessionCode, mode).isCanceled() ) { |
|
1215 |
return; |
|
1216 |
} |
|
1217 |
this.editingSessionCode = newSessionCode; |
|
1218 |
invalidateIndexes(); |
|
1219 |
featureManager = new FeatureManager(this); |
|
1220 |
featureTypeManager = new FeatureTypeManager(this); |
|
1221 |
spatialManager = new SpatialManager(this, provider.getEnvelope()); |
|
1222 | 1199 |
|
1223 |
commands = new DefaultFeatureCommandsStack( |
|
1224 |
this, featureManager, |
|
1225 |
spatialManager, featureTypeManager); |
|
1226 |
this.mode = MODE_FULLEDIT; |
|
1227 |
hasStrongChanges = false; |
|
1228 |
hasInserts = false; |
|
1229 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING, newSessionCode, this.mode); |
|
1230 |
break; |
|
1200 |
case MODE_FULLEDIT: |
|
1201 |
if (!this.transforms.isEmpty()) { |
|
1202 |
throw new IllegalStateException(this.getName()); |
|
1203 |
} |
|
1204 |
if (notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING, |
|
1205 |
newSessionCode, mode).isCanceled()) { |
|
1206 |
return; |
|
1207 |
} |
|
1208 |
this.editingSessionCode = newSessionCode; |
|
1209 |
invalidateIndexes(); |
|
1210 |
featureManager = new FeatureManager(this); |
|
1211 |
featureTypeManager = new FeatureTypeManager(this); |
|
1212 |
spatialManager = new SpatialManager(this, provider.getEnvelope()); |
|
1231 | 1213 |
|
1232 |
case MODE_APPEND: |
|
1233 |
if (!this.transforms.isEmpty()) { |
|
1234 |
throw new IllegalStateException(this.getName()); |
|
1235 |
} |
|
1236 |
if( notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING, |
|
1237 |
newSessionCode, mode).isCanceled() ) { |
|
1238 |
return; |
|
1239 |
} |
|
1240 |
this.editingSessionCode = newSessionCode; |
|
1241 |
invalidateIndexes(); |
|
1242 |
this.provider.beginAppend(); |
|
1243 |
this.mode = MODE_APPEND; |
|
1244 |
hasInserts = false; |
|
1245 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING, |
|
1246 |
newSessionCode, this.mode); |
|
1247 |
break; |
|
1248 |
case MODE_PASS_THROUGH: |
|
1249 |
if(!this.provider.supportsPassThroughMode()){ |
|
1250 |
throw new IllegalStateException(this.getName()); |
|
1251 |
} |
|
1252 |
if (!this.transforms.isEmpty()) { |
|
1253 |
throw new IllegalStateException(this.getName()); |
|
1254 |
} |
|
1255 |
if( notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING, |
|
1256 |
newSessionCode, mode).isCanceled() ) { |
|
1257 |
return; |
|
1258 |
} |
|
1259 |
this.editingSessionCode = newSessionCode; |
|
1260 |
invalidateIndexes(); |
|
1261 |
this.mode = MODE_PASS_THROUGH; |
|
1262 |
hasInserts = false; |
|
1263 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING, |
|
1264 |
newSessionCode, this.mode); |
|
1265 |
break; |
|
1266 |
|
|
1267 |
|
|
1214 |
commands = new DefaultFeatureCommandsStack( |
|
1215 |
this, featureManager, |
|
1216 |
spatialManager, featureTypeManager); |
|
1217 |
this.mode = MODE_FULLEDIT; |
|
1218 |
hasStrongChanges = false; |
|
1219 |
hasInserts = false; |
|
1220 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING, newSessionCode, this.mode); |
|
1221 |
break; |
|
1222 |
|
|
1223 |
case MODE_APPEND: |
|
1224 |
if (!this.transforms.isEmpty()) { |
|
1225 |
throw new IllegalStateException(this.getName()); |
|
1226 |
} |
|
1227 |
if (notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING, |
|
1228 |
newSessionCode, mode).isCanceled()) { |
|
1229 |
return; |
|
1230 |
} |
|
1231 |
this.editingSessionCode = newSessionCode; |
|
1232 |
invalidateIndexes(); |
|
1233 |
this.provider.beginAppend(); |
|
1234 |
this.mode = MODE_APPEND; |
|
1235 |
hasInserts = false; |
|
1236 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING, |
|
1237 |
newSessionCode, this.mode); |
|
1238 |
break; |
|
1239 |
case MODE_PASS_THROUGH: |
|
1240 |
if (!this.provider.supportsPassThroughMode()) { |
|
1241 |
throw new IllegalStateException(this.getName()); |
|
1242 |
} |
|
1243 |
if (!this.transforms.isEmpty()) { |
|
1244 |
throw new IllegalStateException(this.getName()); |
|
1245 |
} |
|
1246 |
if (notifyChange(FeatureStoreNotification.BEFORE_STARTEDITING, |
|
1247 |
newSessionCode, mode).isCanceled()) { |
|
1248 |
return; |
|
1249 |
} |
|
1250 |
this.editingSessionCode = newSessionCode; |
|
1251 |
invalidateIndexes(); |
|
1252 |
this.mode = MODE_PASS_THROUGH; |
|
1253 |
hasInserts = false; |
|
1254 |
notifyChange(FeatureStoreNotification.AFTER_STARTEDITING, |
|
1255 |
newSessionCode, this.mode); |
|
1256 |
break; |
|
1257 |
|
|
1268 | 1258 |
} |
1269 | 1259 |
} catch (Exception e) { |
1270 | 1260 |
try { |
1271 | 1261 |
if (this.mode != MODE_QUERY) { |
1272 |
exitEditingMode(); |
|
1262 |
exitEditingMode();
|
|
1273 | 1263 |
} |
1274 |
notifyChange(FeatureStoreNotification.FAILED_STARTEDITING,
|
|
1264 |
notifyChange(FeatureStoreNotification.FAILED_STARTEDITING, |
|
1275 | 1265 |
newSessionCode, mode); |
1276 |
} catch(Throwable th) { |
|
1277 |
LOGGER.warn("Can't cleanup after error in start editing.",th); |
|
1266 |
} catch (Throwable th) {
|
|
1267 |
LOGGER.warn("Can't cleanup after error in start editing.", th);
|
|
1278 | 1268 |
} |
1279 | 1269 |
throw new StoreEditException(e, this.getName()); |
1280 | 1270 |
} |
... | ... | |
1287 | 1277 |
private void setIndexesValidStatus(boolean valid) { |
1288 | 1278 |
FeatureIndexes theIndexes = getIndexes(); |
1289 | 1279 |
LOGGER.debug("Setting the store indexes to valid status {}: {}", (valid |
1290 |
? Boolean.TRUE : Boolean.FALSE), theIndexes); |
|
1280 |
? Boolean.TRUE : Boolean.FALSE), theIndexes);
|
|
1291 | 1281 |
for (Iterator iterator = theIndexes.iterator(); iterator.hasNext();) { |
1292 | 1282 |
FeatureIndex index = (FeatureIndex) iterator.next(); |
1293 | 1283 |
if (index instanceof FeatureIndexProviderServices) { |
1294 |
FeatureIndexProviderServices indexServices =
|
|
1295 |
(FeatureIndexProviderServices) index; |
|
1284 |
FeatureIndexProviderServices indexServices |
|
1285 |
= (FeatureIndexProviderServices) index;
|
|
1296 | 1286 |
indexServices.setValid(valid); |
1297 | 1287 |
} |
1298 | 1288 |
} |
... | ... | |
1304 | 1294 |
for (Iterator iterator = theIndexes.iterator(); iterator.hasNext();) { |
1305 | 1295 |
FeatureIndex index = (FeatureIndex) iterator.next(); |
1306 | 1296 |
if (index instanceof FeatureIndexProviderServices) { |
1307 |
FeatureIndexProviderServices indexServices =
|
|
1308 |
(FeatureIndexProviderServices) index; |
|
1297 |
FeatureIndexProviderServices indexServices |
|
1298 |
= (FeatureIndexProviderServices) index;
|
|
1309 | 1299 |
indexServices.fill(true, null); |
1310 | 1300 |
} |
1311 | 1301 |
} |
... | ... | |
1317 | 1307 |
for (Iterator iterator = theIndexes.iterator(); iterator.hasNext();) { |
1318 | 1308 |
FeatureIndex index = (FeatureIndex) iterator.next(); |
1319 | 1309 |
if (index instanceof FeatureIndexProviderServices) { |
1320 |
FeatureIndexProviderServices indexServices =
|
|
1321 |
(FeatureIndexProviderServices) index; |
|
1310 |
FeatureIndexProviderServices indexServices |
|
1311 |
= (FeatureIndexProviderServices) index;
|
|
1322 | 1312 |
indexServices.waitForIndex(); |
1323 | 1313 |
} |
1324 | 1314 |
} |
... | ... | |
1327 | 1317 |
private void disposeIndexes() { |
1328 | 1318 |
FeatureIndexes theIndexes = getIndexes(); |
1329 | 1319 |
LOGGER.debug("Disposing indexes: {}", theIndexes); |
1330 |
if( theIndexes==null ) {
|
|
1320 |
if (theIndexes == null) {
|
|
1331 | 1321 |
return; |
1332 | 1322 |
} |
1333 | 1323 |
for (Iterator iterator = theIndexes.iterator(); iterator.hasNext();) { |
1334 | 1324 |
FeatureIndex index = (FeatureIndex) iterator.next(); |
1335 | 1325 |
if (index instanceof FeatureIndexProviderServices) { |
1336 |
FeatureIndexProviderServices indexServices =
|
|
1337 |
(FeatureIndexProviderServices) index; |
|
1326 |
FeatureIndexProviderServices indexServices |
|
1327 |
= (FeatureIndexProviderServices) index;
|
|
1338 | 1328 |
indexServices.dispose(); |
1339 | 1329 |
} |
1340 | 1330 |
} |
... | ... | |
1342 | 1332 |
|
1343 | 1333 |
@Override |
1344 | 1334 |
public boolean isEditing() { |
1345 |
return mode == MODE_FULLEDIT;
|
|
1335 |
return mode == MODE_FULLEDIT; |
|
1346 | 1336 |
} |
1347 | 1337 |
|
1348 | 1338 |
@Override |
... | ... | |
1352 | 1342 |
|
1353 | 1343 |
@Override |
1354 | 1344 |
synchronized public void update(EditableFeatureType type) |
1355 |
throws DataException { |
|
1345 |
throws DataException {
|
|
1356 | 1346 |
try { |
1357 | 1347 |
if (type == null) { |
1358 | 1348 |
throw new NullFeatureTypeException(getName()); |
1359 | 1349 |
} |
1360 |
|
|
1361 |
switch(this.mode) { |
|
1350 |
|
|
1351 |
switch (this.mode) {
|
|
1362 | 1352 |
case MODE_QUERY: |
1363 | 1353 |
if (type.hasOnlyMetadataChanges(this.defaultFeatureType)) { |
1364 |
if( notifyChange(FeatureStoreNotification.BEFORE_UPDATE_TYPE, type).isCanceled() ) {
|
|
1365 |
return; |
|
1354 |
if (notifyChange(FeatureStoreNotification.BEFORE_UPDATE_TYPE, type).isCanceled()) {
|
|
1355 |
return;
|
|
1366 | 1356 |
} |
1367 | 1357 |
FeatureType theType = type.getNotEditableCopy(); |
1368 |
if( defaultFeatureType.getId().equals(theType.getId()) ) {
|
|
1358 |
if (defaultFeatureType.getId().equals(theType.getId())) {
|
|
1369 | 1359 |
defaultFeatureType = theType; |
1370 | 1360 |
} |
1371 | 1361 |
List newtypes = new ArrayList(); |
1372 | 1362 |
for (FeatureType featureType : this.featureTypes) { |
1373 |
if( featureType.getId().equals(theType.getId()) ) {
|
|
1363 |
if (featureType.getId().equals(theType.getId())) {
|
|
1374 | 1364 |
newtypes.add(theType); |
1375 | 1365 |
} else { |
1376 | 1366 |
newtypes.add(featureType); |
1377 |
}
|
|
1367 |
} |
|
1378 | 1368 |
} |
1379 | 1369 |
this.featureTypes = newtypes; |
1380 | 1370 |
saveDALFile(); |
1381 | 1371 |
notifyChange(FeatureStoreNotification.AFTER_UPDATE_TYPE, type); |
1382 | 1372 |
} |
1383 |
|
|
1373 |
|
|
1384 | 1374 |
break; |
1385 | 1375 |
case MODE_FULLEDIT: |
1386 |
if( notifyChange(FeatureStoreNotification.BEFORE_UPDATE_TYPE, type).isCanceled() ) {
|
|
1387 |
return; |
|
1376 |
if (notifyChange(FeatureStoreNotification.BEFORE_UPDATE_TYPE, type).isCanceled()) {
|
|
1377 |
return;
|
|
1388 | 1378 |
} |
1389 | 1379 |
newVersionOfUpdate(); |
1390 | 1380 |
|
... | ... | |
1392 | 1382 |
FeatureType newt = type.getCopy(); |
1393 | 1383 |
commands.update(newt, oldt); |
1394 | 1384 |
hasStrongChanges = ((DefaultEditableFeatureType) type).hasStrongChanges(); |
1395 |
notifyChange(FeatureStoreNotification.AFTER_UPDATE_TYPE, type);
|
|
1385 |
notifyChange(FeatureStoreNotification.AFTER_UPDATE_TYPE, type); |
|
1396 | 1386 |
break; |
1397 | 1387 |
case MODE_APPEND: |
1398 | 1388 |
case MODE_PASS_THROUGH: |
1399 | 1389 |
throw new NeedEditingModeException(this.getName()); |
1400 |
|
|
1390 |
|
|
1401 | 1391 |
} |
1402 | 1392 |
} catch (Exception e) { |
1403 | 1393 |
throw new StoreUpdateFeatureTypeException(e, this.getName()); |
... | ... | |
1406 | 1396 |
|
1407 | 1397 |
@Override |
1408 | 1398 |
public void delete(Feature feature) throws DataException { |
1409 |
switch (this.mode){ |
|
1399 |
switch (this.mode) {
|
|
1410 | 1400 |
case MODE_PASS_THROUGH: |
1411 | 1401 |
checkIsOwnFeature(feature); |
1412 |
if( notifyChange(FeatureStoreNotification.BEFORE_DELETE, feature).isCanceled() ) {
|
|
1413 |
return; |
|
1402 |
if (notifyChange(FeatureStoreNotification.BEFORE_DELETE, feature).isCanceled()) {
|
|
1403 |
return;
|
|
1414 | 1404 |
} |
1415 |
feature.validate(Feature.UPDATE); |
|
1416 | 1405 |
this.provider.passThroughDelete((FeatureReferenceProviderServices) feature.getReference()); |
1417 | 1406 |
notifyChange(FeatureStoreNotification.AFTER_DELETE, feature); |
1418 | 1407 |
break; |
1419 | 1408 |
default: |
1420 | 1409 |
this.commands.delete(feature); |
1421 | 1410 |
break; |
1422 |
|
|
1411 |
|
|
1423 | 1412 |
} |
1424 | 1413 |
} |
1425 |
|
|
1414 |
|
|
1426 | 1415 |
@Override |
1427 | 1416 |
public void delete(String filter) { |
1428 |
if( StringUtils.isBlank(filter) ) {
|
|
1417 |
if (StringUtils.isBlank(filter)) {
|
|
1429 | 1418 |
return; |
1430 | 1419 |
} |
1431 | 1420 |
this.delete(ExpressionUtils.createExpression(filter)); |
1432 | 1421 |
} |
1433 |
|
|
1422 |
|
|
1434 | 1423 |
@Override |
1435 | 1424 |
public void delete(Expression filter) { |
1436 | 1425 |
// TODO: Optimizar pasandolo directamente al proveedor si no estamos en edicion y lo soporta. |
1437 |
if( filter == null ) {
|
|
1426 |
if (filter == null) {
|
|
1438 | 1427 |
return; |
1439 | 1428 |
} |
1440 | 1429 |
boolean pendingFinishEditing = false; |
1441 | 1430 |
DisposableFeatureSetIterable features = null; |
1442 | 1431 |
try { |
1443 |
switch(this.mode) { |
|
1432 |
switch (this.mode) {
|
|
1444 | 1433 |
case MODE_QUERY: |
1445 | 1434 |
pendingFinishEditing = true; |
1446 | 1435 |
this.edit(); |
... | ... | |
1454 | 1443 |
// return; |
1455 | 1444 |
break; |
1456 | 1445 |
default: |
1457 |
throw new IllegalStateException("Mode "+this.mode+" not supported.");
|
|
1446 |
throw new IllegalStateException("Mode " + this.mode + " not supported.");
|
|
1458 | 1447 |
} |
1459 |
|
|
1448 |
|
|
1460 | 1449 |
FeatureSet fset = this.getFeatureSet(filter); |
1461 |
features = fset.iterable();
|
|
1450 |
features = fset.iterable(); |
|
1462 | 1451 |
for (Feature f : features) { |
1463 | 1452 |
fset.delete(f); |
1464 | 1453 |
} |
1465 |
} catch(DataException ex) { |
|
1466 |
throw new DataRuntimeException(ex.getFormatString(), ex.getMessageKey(), ex.getCode()) {}; |
|
1467 |
} catch(Exception ex) { |
|
1468 |
throw new RuntimeException("Can't delete features ("+filter.getPhrase()+").", ex); |
|
1454 |
} catch (DataException ex) { |
|
1455 |
throw new DataRuntimeException(ex.getFormatString(), ex.getMessageKey(), ex.getCode()) { |
|
1456 |
}; |
|
1457 |
} catch (Exception ex) { |
|
1458 |
throw new RuntimeException("Can't delete features (" + filter.getPhrase() + ").", ex); |
|
1469 | 1459 |
} finally { |
1470 |
if( pendingFinishEditing ) {
|
|
1460 |
if (pendingFinishEditing) {
|
|
1471 | 1461 |
this.finishEditingQuietly(); |
1472 | 1462 |
} |
1473 | 1463 |
DisposeUtils.disposeQuietly(features); |
1474 | 1464 |
} |
1475 | 1465 |
} |
1476 |
|
|
1466 |
|
|
1477 | 1467 |
synchronized public void doDelete(Feature feature) throws DataException { |
1478 |
if( feature==null ) {
|
|
1468 |
if (feature == null) {
|
|
1479 | 1469 |
throw new IllegalArgumentException("feature argument can't be null."); |
1480 | 1470 |
} |
1481 | 1471 |
try { |
... | ... | |
1484 | 1474 |
if (feature instanceof EditableFeature) { |
1485 | 1475 |
throw new StoreDeleteEditableFeatureException(getName()); |
1486 | 1476 |
} |
1487 |
if( notifyChange(FeatureStoreNotification.BEFORE_DELETE, feature).isCanceled() ) {
|
|
1488 |
return; |
|
1477 |
if (notifyChange(FeatureStoreNotification.BEFORE_DELETE, feature).isCanceled()) {
|
|
1478 |
return;
|
|
1489 | 1479 |
} |
1490 | 1480 |
|
1491 | 1481 |
//Update the featureManager and the spatialManager |
... | ... | |
1503 | 1493 |
@Override |
1504 | 1494 |
public synchronized void insert(FeatureSet set) throws DataException { |
1505 | 1495 |
switch (mode) { |
1506 |
case MODE_QUERY: |
|
1507 |
throw new NeedEditingModeException(this.getName()); |
|
1496 |
case MODE_QUERY:
|
|
1497 |
throw new NeedEditingModeException(this.getName());
|
|
1508 | 1498 |
|
1509 |
case MODE_APPEND: |
|
1510 |
case MODE_FULLEDIT: |
|
1511 |
case MODE_PASS_THROUGH: |
|
1499 |
case MODE_APPEND:
|
|
1500 |
case MODE_FULLEDIT:
|
|
1501 |
case MODE_PASS_THROUGH:
|
|
1512 | 1502 |
try { |
1513 | 1503 |
set.accept((Object obj) -> { |
1514 | 1504 |
EditableFeature ef = createNewFeature((Feature) obj); |
... | ... | |
1520 | 1510 |
break; |
1521 | 1511 |
} |
1522 | 1512 |
} |
1523 |
|
|
1513 |
|
|
1524 | 1514 |
private static EditableFeature lastChangedFeature = null; |
1525 | 1515 |
|
1526 | 1516 |
@Override |
1527 | 1517 |
public synchronized void insert(EditableFeature feature) |
1528 |
throws DataException { |
|
1518 |
throws DataException {
|
|
1529 | 1519 |
LOGGER.debug("In editing mode {}, insert feature: {}", mode, feature); |
1530 | 1520 |
try { |
1531 | 1521 |
switch (mode) { |
1532 |
case MODE_QUERY: |
|
1533 |
throw new NeedEditingModeException(this.getName()); |
|
1522 |
case MODE_QUERY:
|
|
1523 |
throw new NeedEditingModeException(this.getName());
|
|
1534 | 1524 |
|
1535 |
case MODE_APPEND: |
|
1536 |
checkIsOwnFeature(feature); |
|
1537 |
if (feature.isUpdatable() ) {
|
|
1538 |
throw new NoNewFeatureInsertException(this.getName()); |
|
1539 |
} |
|
1540 |
if( notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature).isCanceled() ) {
|
|
1541 |
return; |
|
1542 |
} |
|
1543 |
this.featureCount = null; |
|
1544 |
feature.validate(Feature.UPDATE);
|
|
1545 |
provider.append(((DefaultEditableFeature) feature).getData()); |
|
1546 |
hasStrongChanges = true; |
|
1547 |
hasInserts = true; |
|
1548 |
notifyChange(FeatureStoreNotification.AFTER_INSERT, feature); |
|
1549 |
break; |
|
1525 |
case MODE_APPEND:
|
|
1526 |
checkIsOwnFeature(feature);
|
|
1527 |
if (feature.isUpdatable()) {
|
|
1528 |
throw new NoNewFeatureInsertException(this.getName());
|
|
1529 |
}
|
|
1530 |
if (notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature).isCanceled()) {
|
|
1531 |
return;
|
|
1532 |
}
|
|
1533 |
this.featureCount = null;
|
|
1534 |
feature.validate(CHECK_RULES_AT_EDITING);
|
|
1535 |
provider.append(((DefaultEditableFeature) feature).getData());
|
|
1536 |
hasStrongChanges = true;
|
|
1537 |
hasInserts = true;
|
|
1538 |
notifyChange(FeatureStoreNotification.AFTER_INSERT, feature);
|
|
1539 |
break;
|
|
1550 | 1540 |
|
1551 |
case MODE_FULLEDIT: |
|
1552 |
if (feature.isUpdatable() ) {
|
|
1553 |
throw new NoNewFeatureInsertException(this.getName()); |
|
1554 |
} |
|
1555 |
feature.validate(Feature.UPDATE);
|
|
1556 |
commands.insert(feature); |
|
1557 |
break; |
|
1558 |
|
|
1559 |
case MODE_PASS_THROUGH: |
|
1560 |
checkIsOwnFeature(feature); |
|
1561 |
if (feature.isUpdatable() ) {
|
|
1562 |
throw new NoNewFeatureInsertException(this.getName()); |
|
1563 |
} |
|
1564 |
if( notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature).isCanceled() ) {
|
|
1565 |
return; |
|
1566 |
} |
|
1567 |
feature.validate(Feature.UPDATE);
|
|
1568 |
this.provider.passThroughInsert(((DefaultEditableFeature) feature).getData()); |
|
1569 |
notifyChange(FeatureStoreNotification.AFTER_INSERT, feature); |
|
1570 |
break; |
|
1541 |
case MODE_FULLEDIT:
|
|
1542 |
if (feature.isUpdatable()) {
|
|
1543 |
throw new NoNewFeatureInsertException(this.getName());
|
|
1544 |
}
|
|
1545 |
feature.validate(CHECK_RULES_AT_EDITING);
|
|
1546 |
commands.insert(feature);
|
|
1547 |
break;
|
|
1548 |
|
|
1549 |
case MODE_PASS_THROUGH:
|
|
1550 |
checkIsOwnFeature(feature);
|
|
1551 |
if (feature.isUpdatable()) {
|
|
1552 |
throw new NoNewFeatureInsertException(this.getName());
|
|
1553 |
}
|
|
1554 |
if (notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature).isCanceled()) {
|
|
1555 |
return;
|
|
1556 |
}
|
|
1557 |
feature.validate(CHECK_RULES_AT_EDITING);
|
|
1558 |
this.provider.passThroughInsert(((DefaultEditableFeature) feature).getData());
|
|
1559 |
notifyChange(FeatureStoreNotification.AFTER_INSERT, feature);
|
|
1560 |
break;
|
|
1571 | 1561 |
} |
1572 | 1562 |
} catch (Exception e) { |
1573 | 1563 |
throw new StoreInsertFeatureException(e, this.getName()); |
... | ... | |
1575 | 1565 |
} |
1576 | 1566 |
|
1577 | 1567 |
synchronized public void doInsert(EditableFeature feature) |
1578 |
throws DataException { |
|
1568 |
throws DataException {
|
|
1579 | 1569 |
checkIsOwnFeature(feature); |
1580 | 1570 |
|
1581 | 1571 |
waitForIndexes(); |
1582 | 1572 |
|
1583 |
if( notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature).isCanceled() ) {
|
|
1584 |
return; |
|
1573 |
if (notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature).isCanceled()) {
|
|
1574 |
return;
|
|
1585 | 1575 |
} |
1586 | 1576 |
newVersionOfUpdate(); |
1587 | 1577 |
if ((lastChangedFeature == null) |
1588 |
|| (lastChangedFeature.getSource() != feature.getSource())) { |
|
1578 |
|| (lastChangedFeature.getSource() != feature.getSource())) {
|
|
1589 | 1579 |
lastChangedFeature = feature; |
1590 |
feature.validate(Feature.UPDATE);
|
|
1580 |
feature.validate(CHECK_RULES_AT_EDITING);
|
|
1591 | 1581 |
lastChangedFeature = null; |
1592 | 1582 |
} |
1593 | 1583 |
//Update the featureManager and the spatialManager |
1594 | 1584 |
((DefaultFeature) feature).setInserted(true); |
1595 | 1585 |
DefaultFeature newFeature = (DefaultFeature) feature.getNotEditableCopy(); |
1596 | 1586 |
|
1597 |
|
|
1598 |
featureManager.add(newFeature); |
|
1587 |
featureManager.add(feature); |
|
1599 | 1588 |
spatialManager.insertFeature(newFeature); |
1600 | 1589 |
|
1601 | 1590 |
hasStrongChanges = true; |
... | ... | |
1605 | 1594 |
|
1606 | 1595 |
@Override |
1607 | 1596 |
public void update(EditableFeature feature) |
1608 |
throws DataException { |
|
1609 |
switch (this.mode){ |
|
1610 |
case MODE_PASS_THROUGH: |
|
1611 |
checkIsOwnFeature(feature); |
|
1612 |
if (!feature.isUpdatable()) { |
|
1613 |
throw new NoNewFeatureInsertException(this.getName()); |
|
1614 |
} |
|
1615 |
if( notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature).isCanceled() ) {
|
|
1616 |
return; |
|
1617 |
} |
|
1618 |
feature.validate(Feature.UPDATE);
|
|
1619 |
this.provider.passThroughUpdate(((DefaultEditableFeature)feature).getData());
|
|
1620 |
notifyChange(FeatureStoreNotification.AFTER_INSERT, feature); |
|
1621 |
break; |
|
1622 |
case MODE_FULLEDIT: |
|
1623 |
if (feature.isUpdatable()) { |
|
1624 |
commands.update(feature, feature.getSource()); |
|
1625 |
return; |
|
1626 |
} |
|
1627 |
// FIXME: Deberiamos lanzar aqui un error en lugar de hacer el insert. |
|
1628 |
// O lanzar un mensaje al log? |
|
1629 |
insert(feature); |
|
1630 |
break; |
|
1631 |
default: |
|
1632 |
throw new NeedEditingModeException(this.getName()); |
|
1597 |
throws DataException {
|
|
1598 |
switch (this.mode) {
|
|
1599 |
case MODE_PASS_THROUGH:
|
|
1600 |
checkIsOwnFeature(feature);
|
|
1601 |
if (!feature.isUpdatable()) {
|
|
1602 |
throw new NoNewFeatureInsertException(this.getName());
|
|
1603 |
}
|
|
1604 |
if (notifyChange(FeatureStoreNotification.BEFORE_INSERT, feature).isCanceled()) {
|
|
1605 |
return;
|
|
1606 |
}
|
|
1607 |
feature.validate(CHECK_RULES_AT_EDITING);
|
|
1608 |
this.provider.passThroughUpdate(((DefaultEditableFeature) feature).getData());
|
|
1609 |
notifyChange(FeatureStoreNotification.AFTER_INSERT, feature);
|
|
1610 |
break;
|
|
1611 |
case MODE_FULLEDIT:
|
|
1612 |
if (feature.isUpdatable()) {
|
|
1613 |
commands.update(feature, feature.getSource());
|
|
1614 |
return;
|
|
1615 |
}
|
|
1616 |
// FIXME: Deberiamos lanzar aqui un error en lugar de hacer el insert.
|
|
1617 |
// O lanzar un mensaje al log?
|
|
1618 |
insert(feature);
|
|
1619 |
break;
|
|
1620 |
default:
|
|
1621 |
throw new NeedEditingModeException(this.getName());
|
|
1633 | 1622 |
} |
1634 | 1623 |
} |
1635 | 1624 |
|
1636 | 1625 |
@Override |
1637 | 1626 |
public void update(Object... parameters) throws DataException { |
1638 |
if(parameters.length == 1){
|
|
1627 |
if (parameters.length == 1) {
|
|
1639 | 1628 |
Object param0 = parameters[0]; |
1640 |
if(param0 instanceof EditableFeature){
|
|
1641 |
this.update((EditableFeature)param0); |
|
1642 |
} else if(param0 instanceof EditableFeatureType) { |
|
1643 |
this.update((EditableFeatureType)param0); |
|
1629 |
if (param0 instanceof EditableFeature) {
|
|
1630 |
this.update((EditableFeature) param0);
|
|
1631 |
} else if (param0 instanceof EditableFeatureType) {
|
|
1632 |
this.update((EditableFeatureType) param0);
|
|
1644 | 1633 |
} else { |
1645 | 1634 |
throw new IllegalArgumentException("Type of first parameter isn't supported"); |
1646 | 1635 |
} |
1647 | 1636 |
return; |
1648 | 1637 |
} |
1649 |
|
|
1638 |
|
|
1650 | 1639 |
Expression filter = null; |
1651 | 1640 |
long end = parameters.length; |
1652 |
if(parameters.length % 2 == 1){
|
|
1653 |
Object param = parameters[parameters.length-1];
|
|
1654 |
if(param != null){
|
|
1655 |
if(param instanceof Expression){
|
|
1641 |
if (parameters.length % 2 == 1) {
|
|
1642 |
Object param = parameters[parameters.length - 1];
|
|
1643 |
if (param != null) {
|
|
1644 |
if (param instanceof Expression) {
|
|
1656 | 1645 |
filter = (Expression) param; |
1657 | 1646 |
} else { |
1658 | 1647 |
filter = ExpressionUtils.createExpression(param.toString()); |
1659 | 1648 |
} |
1660 | 1649 |
} |
1661 | 1650 |
} else { |
1662 |
end = parameters.length-1;
|
|
1651 |
end = parameters.length - 1;
|
|
1663 | 1652 |
} |
1664 |
|
|
1665 |
switch (this.mode){ |
|
1666 |
case MODE_PASS_THROUGH: |
|
1667 |
this.provider.passThroughUpdate( |
|
1668 |
// this.getName(), |
|
1669 |
parameters, |
|
1670 |
filter); |
|
1671 |
break; |
|
1672 |
case MODE_FULLEDIT: |
|
1673 |
FeatureSet set = this.getFeatureSet(filter); |
|
1674 |
DisposableIterator it = set.fastIterator(); |
|
1675 |
while (it.hasNext()) { |
|
1676 |
Feature feature = (Feature) it.next(); |
|
1677 |
EditableFeature ef = feature.getEditable(); |
|
1678 |
for (int i = 0; i < end; i+=2) { |
|
1679 |
String name = (String) parameters[i]; |
|
1680 |
Object value = parameters[i+1]; |
|
1681 |
ef.set(name, value); |
|
1653 |
|
|
1654 |
switch (this.mode) { |
|
1655 |
case MODE_PASS_THROUGH: |
|
1656 |
this.provider.passThroughUpdate( |
|
1657 |
// this.getName(), |
|
1658 |
parameters, |
|
1659 |
filter); |
|
1660 |
break; |
|
1661 |
case MODE_FULLEDIT: |
|
1662 |
FeatureSet set = this.getFeatureSet(filter); |
|
1663 |
DisposableIterator it = set.fastIterator(); |
|
1664 |
while (it.hasNext()) { |
Also available in: Unified diff