Revision 47665 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

View differences:

DefaultFeatureStore.java
361 361
        this.metadataChildren.add(provider);
362 362
        if (!this.ignoreDALResource) {
363 363
            loadDALFile();
364

  
365
            // Habria que crear un metodo en el proveedor para que de prioidad
366
            // a los parametros frente a lo que se a leido en el fichero dal
367
            // DataStoreProvider arreglalo segun los parametros del usuario
368
            // fixFeatureTypeFromParameters
364
            // Este metodo en el proveedor da prioridad
365
            // a los parametros frente a lo que se ha leido en el fichero dal
369 366
            this.provider.fixFeatureTypeFromParameters();
370 367
            try {
371 368
                if (defaultFeatureType != null) {
......
599 596
        if (hasDynValue(DataStore.METADATA_ENVELOPE)) {
600 597
            return (Envelope) getDynValue(DataStore.METADATA_ENVELOPE);
601 598
        }
602
        Envelope envelope = this.provider.getEnvelope();
603
        if (envelope != null) {
604
            return envelope;
605
        }
606 599
        FeatureAttributeDescriptor attrdesc = this.getDefaultFeatureType().getDefaultGeometryAttribute();
607
        if (attrdesc == null || (!attrdesc.isComputed() && this.getTransforms().isEmpty())) {
600
        if (attrdesc == null) {
608 601
            return null;
609 602
        }
603
        if (!attrdesc.isComputed()) {
604
            Envelope envelope = this.provider.getEnvelope(attrdesc.getName());
605
            if (envelope != null) {
606
                return envelope;
607
            }
608
            if (this.getTransforms().isEmpty()) {
609
                return null;
610
            }
611
        }
610 612
        final int index = attrdesc.getIndex();
611 613
        final MutableObject<Envelope> envelopeValue = new MutableObject<>();
612 614
        try {
......
1558 1560
            throw new StoreUpdateFeatureTypeException(e, this.getName());
1559 1561
        }
1560 1562
    }
1561

  
1563
    
1562 1564
    @Override
1563 1565
    public void delete(Feature feature) throws DataException {
1564 1566
        switch (this.mode) {
......
2011 2013
        LOGGER.debug("finish editing of mode: {}", mode);
2012 2014
        LocalTransaction trans = new LocalTransaction(this.dataManager, this.getTransaction());
2013 2015
        try {
2014
            Map<String, List<FeatureAttributeDescriptor>> computedFields = this.getComputedFields();
2015 2016
            switch (mode) {
2016 2017
                case MODE_QUERY:
2017 2018
                    throw new NeedEditingModeException(this.getName());
......
2028 2029
                    saveDALFile();
2029 2030
                    provider.endAppend();
2030 2031
                    exitEditingMode();
2031
                    this.updateComputedFields(computedFields);
2032 2032
                    loadDALFile();
2033 2033
                    updateIndexes();
2034 2034
                    trans.commit();
......
2067 2067
                            provider.performChanges(featureManager.getDeleted(),
2068 2068
                                    featureManager.getInserted(),
2069 2069
                                    featureManager.getUpdated(),
2070
                                    removeCalculatedAttributes(featureTypeManager.getFeatureTypesChanged()).iterator());
2071

  
2070
                                    featureTypeManager.getFeatureTypesChanged().iterator());
2072 2071
                        }
2073
                        this.updateComputedFields(computedFields);
2074 2072
                        exitEditingMode();
2075 2073
                        loadDALFile();
2076 2074
                        updateIndexes();
......
2115 2113
        return this.editingSessionCode;
2116 2114
    }
2117 2115

  
2118
    private Map<String, List<FeatureAttributeDescriptor>> getComputedFields() throws DataException {
2119
        Map<String, List<FeatureAttributeDescriptor>> r = new HashMap<>();
2120

  
2121
        List<FeatureType> theTypes = new ArrayList<>();
2122
        theTypes.addAll(this.getFeatureTypes());
2123
        theTypes.add(this.getDefaultFeatureType());
2124
        for (int n = 0; n < theTypes.size(); n++) {
2125
            FeatureType type = theTypes.get(n);
2126
            for (FeatureAttributeDescriptor attrdesc : type) {
2127
                FeatureAttributeEmulator emulator = attrdesc.getFeatureAttributeEmulator();
2128
                if (emulator != null) {
2129
                    List<FeatureAttributeDescriptor> l = r.get(type.getId());
2130
                    if (l == null) {
2131
                        l = new ArrayList<>();
2132
                        r.put(type.getId(), l);
2133
                    }
2134
                    l.add(attrdesc);
2135
                }
2136
            }
2137
        }
2138
        return r;
2139
    }
2140

  
2141
    private void updateComputedFields(Map<String, List<FeatureAttributeDescriptor>> computedFields) throws DataException {
2142

  
2143
        List<FeatureType> theTypes = new ArrayList<>();
2144
        theTypes.addAll(this.getFeatureTypes());
2145
        theTypes.add(this.getDefaultFeatureType());
2146
        for (int n = 0; n < theTypes.size(); n++) {
2147
            DefaultFeatureType type = (DefaultFeatureType) theTypes.get(n);
2148
            List<FeatureAttributeDescriptor> x = computedFields.get(type.getId());
2149
            if (x != null && !x.isEmpty()) {
2150
                for (FeatureAttributeDescriptor attrdesc : x) {
2151
                    if (type.get(attrdesc.getName()) == null) {
2152
                        type.add(attrdesc);
2153
                    }
2154
                }
2155
            }
2156
        }
2157

  
2158
    }
2159

  
2160
    private List<FeatureTypeChanged> removeCalculatedAttributes(List<FeatureTypeChanged> ftypes) {
2161
        // FIXME: Falta por implementar
2162
//        for (FeatureStoreProvider.FeatureTypeChanged ftype : ftypes) {
2163
//            EditableFeatureType target = (EditableFeatureType) ftype.getTarget();
2164
//            for (FeatureAttributeDescriptor attributeDescriptor : ftype.getSource().getAttributeDescriptors()) {
2165
//                if (attributeDescriptor.isComputed()) {
2166
//                    target.remove(attributeDescriptor.getName());
2167
//                }
2168
//            }
2169
//        }
2170
        return ftypes;
2171
    }
2172

  
2173 2116
    private void clearResourcesCache() {
2174 2117
        ResourcesStorage theResourcesStorage = null;
2175 2118
        try {
......
2283 2226
                        provider.performChanges(featureManager.getDeleted(),
2284 2227
                                featureManager.getInserted(),
2285 2228
                                featureManager.getUpdated(),
2286
                                removeCalculatedAttributes(featureTypeManager.getFeatureTypesChanged()).iterator());
2229
//                                removeCalculatedAttributes(featureTypeManager.getFeatureTypesChanged()).iterator());
2230
                                featureTypeManager.getFeatureTypesChanged().iterator());
2287 2231
                    }
2288 2232
                    invalidateIndexes();
2289 2233
                    featureManager = new FeatureManager(this);

Also available in: Unified diff