Revision 45426
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/test/java/org/gvsig/fmap/dal/feature/DummyFetureStore.java | ||
---|---|---|
908 | 908 |
public FeatureQuery createFeatureQuery(Expression filter) { |
909 | 909 |
return null; |
910 | 910 |
} |
911 |
|
|
912 |
@Override |
|
913 |
public FeatureSelection createLargeFeatureSelection() throws DataException { |
|
914 |
return null; |
|
915 |
} |
|
916 |
|
|
917 |
@Override |
|
918 |
public FeatureSelection createMemoryFeatureSelection() throws DataException { |
|
919 |
return null; |
|
920 |
} |
|
911 | 921 |
|
912 | 922 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureStore.java | ||
---|---|---|
1167 | 1167 |
* @throws DataException |
1168 | 1168 |
*/ |
1169 | 1169 |
public FeatureSelection createFeatureSelection() throws DataException; |
1170 |
|
|
1171 |
public FeatureSelection createLargeFeatureSelection() throws DataException; |
|
1172 |
|
|
1173 |
/** |
|
1174 |
* Creates a {@link FeatureSelection} |
|
1175 |
* |
|
1176 |
* @return |
|
1177 |
* a {@link FeatureSelection} |
|
1178 |
* |
|
1179 |
* @throws DataException |
|
1180 |
*/ |
|
1181 |
public FeatureSelection createMemoryFeatureSelection() throws DataException; |
|
1170 | 1182 |
|
1183 |
|
|
1171 | 1184 |
/** |
1172 | 1185 |
* Returns the current {@link FeatureSelection}. |
1173 | 1186 |
* Create a empty selection if not exits. |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataManager.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
import java.io.File; |
26 | 26 |
import java.util.List; |
27 |
import java.util.Map; |
|
28 |
import java.util.Set; |
|
27 | 29 |
import javax.json.JsonObject; |
28 | 30 |
import org.gvsig.expressionevaluator.Expression; |
29 | 31 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
... | ... | |
584 | 586 |
public void removeStoreObserver(Observer observer); |
585 | 587 |
|
586 | 588 |
public String getServerExplorerFromStore(String name); |
589 |
|
|
590 |
public void setMaxSizeForSmallFeatureSelection(long size); |
|
591 |
|
|
592 |
public long getMaxSizeForSmallFeatureSelection(); |
|
593 |
|
|
594 |
public Map createLargeMap(); |
|
595 |
|
|
596 |
public Set createLargeSet(); |
|
587 | 597 |
} |
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/impl/LargeSetImpl.java | ||
---|---|---|
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.fmap.dal.impl; |
|
7 |
|
|
8 |
import java.io.File; |
|
9 |
import java.util.Collection; |
|
10 |
import java.util.Iterator; |
|
11 |
import java.util.Set; |
|
12 |
import org.gvsig.tools.ToolsLocator; |
|
13 |
import org.gvsig.tools.dispose.Disposable; |
|
14 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
|
15 |
import org.gvsig.tools.exception.BaseException; |
|
16 |
import org.gvsig.tools.folders.FoldersManager; |
|
17 |
import org.gvsig.tools.util.Size; |
|
18 |
import org.gvsig.tools.util.Size64; |
|
19 |
import org.h2.mvstore.MVMap; |
|
20 |
import org.h2.mvstore.MVStore; |
|
21 |
import org.slf4j.Logger; |
|
22 |
import org.slf4j.LoggerFactory; |
|
23 |
|
|
24 |
/** |
|
25 |
* |
|
26 |
* @author fdiaz |
|
27 |
* @param <K> |
|
28 |
*/ |
|
29 |
public class LargeSetImpl<K> extends AbstractDisposable implements Set<K>, Size64, Size, Disposable { |
|
30 |
|
|
31 |
protected static final Logger LOGGER = LoggerFactory.getLogger(LargeSetImpl.class); |
|
32 |
|
|
33 |
private MVStore mvstore; |
|
34 |
private MVMap<K, Boolean> mvMap; |
|
35 |
|
|
36 |
public LargeSetImpl() { |
|
37 |
super(); |
|
38 |
FoldersManager folderManager = ToolsLocator.getFoldersManager(); |
|
39 |
File f = folderManager.getUniqueTemporaryFile("MinLargeSet.mv"); |
|
40 |
this.mvstore = MVStore.open(f.getAbsolutePath()); |
|
41 |
this.mvMap = mvstore.openMap("DefaultMap"); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
protected void doDispose() throws BaseException { |
|
46 |
this.mvstore.close(); |
|
47 |
this.mvMap = null; |
|
48 |
this.mvstore = null; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public int size() { |
|
53 |
return this.mvMap.size(); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public boolean isEmpty() { |
|
58 |
return this.mvMap.isEmpty(); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public boolean contains(Object o) { |
|
63 |
return this.mvMap.containsKey((K)o); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public Iterator<K> iterator() { |
|
68 |
return this.mvMap.keySet().iterator(); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public Object[] toArray() { |
|
73 |
//FIXME: Ojo, si el set es grande, esto puede puede provocar un desbordamiento de memoria. |
|
74 |
//duda ?implementarlo o lanzar UnsupportedOperationException? |
|
75 |
// LOGGER.warn("Access to LargeSet's toArray() method."); |
|
76 |
// return this.mvMap.entrySet().toArray(); |
|
77 |
throw new UnsupportedOperationException("Not supported yet."); |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public <T> T[] toArray(T[] a) { |
|
82 |
//FIXME: Ojo, si el set es grande, esto puede puede provocar un desbordamiento de memoria. |
|
83 |
//duda ?implementarlo o lanzar UnsupportedOperationException? |
|
84 |
// LOGGER.warn("Access to LargeSet's toArray(T[] a) method."); |
|
85 |
// return this.mvMap.keySet().toArray((T[]) new K[this.size()]); |
|
86 |
throw new UnsupportedOperationException("Not supported yet."); |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public boolean add(K e) { |
|
91 |
return this.mvMap.put(e, Boolean.TRUE)!=null; |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public boolean remove(Object o) { |
|
96 |
return this.mvMap.remove((K)o)!=null; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public boolean containsAll(Collection<?> c) { |
|
101 |
//FIXME: Comprobar que esto no lo haga en memoria |
|
102 |
return this.mvMap.keySet().containsAll(c); |
|
103 |
//Si lo hace en memoria, usar lo siguiente; |
|
104 |
// if (!c.stream().noneMatch(object -> (!contains((K)object)))) { |
|
105 |
// return false; |
|
106 |
// } |
|
107 |
// return true; |
|
108 |
} |
|
109 |
|
|
110 |
@Override |
|
111 |
public boolean addAll(Collection<? extends K> c) { |
|
112 |
boolean result = false; |
|
113 |
for (K k : c) { |
|
114 |
result |= this.add(k); |
|
115 |
} |
|
116 |
return result; |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public boolean retainAll(Collection<?> c) { |
|
121 |
boolean result = false; |
|
122 |
for (Object next : this) { |
|
123 |
if(!c.contains(next)){ |
|
124 |
result |= remove((K)next); |
|
125 |
} |
|
126 |
} |
|
127 |
return result; |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public boolean removeAll(Collection<?> c) { |
|
132 |
boolean result = false; |
|
133 |
for (Object object : c) { |
|
134 |
result |= remove((K)object); |
|
135 |
} |
|
136 |
return result; |
|
137 |
} |
|
138 |
|
|
139 |
@Override |
|
140 |
public void clear() { |
|
141 |
this.mvMap.clear(); |
|
142 |
} |
|
143 |
|
|
144 |
@Override |
|
145 |
public long size64() { |
|
146 |
return this.mvMap.sizeAsLong(); |
|
147 |
} |
|
148 |
|
|
149 |
} |
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/impl/DefaultDataManager.java | ||
---|---|---|
24 | 24 |
import org.gvsig.expressionevaluator.impl.symboltable.FeatureSymbolTableImpl; |
25 | 25 |
import org.gvsig.fmap.dal.BaseStoresRepository; |
26 | 26 |
import org.gvsig.fmap.dal.DALLocator; |
27 |
|
|
28 | 27 |
import org.gvsig.fmap.dal.DataFactory; |
29 | 28 |
import org.gvsig.fmap.dal.DataManager; |
30 | 29 |
import org.gvsig.fmap.dal.DataServerExplorer; |
... | ... | |
38 | 37 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
39 | 38 |
import org.gvsig.fmap.dal.DataTypes; |
40 | 39 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
41 |
|
|
40 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager.DatabaseWorkspaceListener; |
|
42 | 41 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
43 | 42 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
44 | 43 |
import org.gvsig.fmap.dal.Register; |
45 | 44 |
import org.gvsig.fmap.dal.StoresRepository; |
45 |
import org.gvsig.fmap.dal.exception.CreateFileStoreException; |
|
46 | 46 |
import org.gvsig.fmap.dal.exception.DataException; |
47 | 47 |
import org.gvsig.fmap.dal.exception.InitializeException; |
48 | 48 |
import org.gvsig.fmap.dal.exception.OpenException; |
49 | 49 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
50 |
import org.gvsig.fmap.dal.exception.CreateFileStoreException; |
|
51 | 50 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
52 | 51 |
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder; |
53 | 52 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
... | ... | |
58 | 57 |
import org.gvsig.fmap.dal.feature.Feature; |
59 | 58 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
60 | 59 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
60 |
import org.gvsig.fmap.dal.feature.FeatureSet.DisposableFeatureSetIterable; |
|
61 | 61 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
62 | 62 |
import org.gvsig.fmap.dal.feature.FeatureType; |
63 | 63 |
import org.gvsig.fmap.dal.feature.ForeingKey; |
... | ... | |
76 | 76 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProviderFactory; |
77 | 77 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
78 | 78 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
79 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
|
79 | 80 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureExpressionEvaluator; |
80 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
|
81 | 81 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreFactory; |
82 | 82 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreOldFactory; |
83 | 83 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
84 | 84 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
85 | 85 |
import org.gvsig.fmap.dal.spi.DALSPILocator; |
86 | 86 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
87 |
import org.gvsig.fmap.dal.spi.DataServerExplorerPoolImpl; |
|
87 | 88 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
88 | 89 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
90 |
import static org.gvsig.fmap.dal.spi.DataStoreProviderServices.PROVIDER_PARAMTER_NAME; |
|
89 | 91 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreParameters; |
90 | 92 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreProvider; |
93 |
import org.gvsig.json.Json; |
|
91 | 94 |
import org.gvsig.tools.ToolsLocator; |
92 | 95 |
import org.gvsig.tools.dataTypes.DataType; |
93 | 96 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
97 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
94 | 98 |
import org.gvsig.tools.dynobject.DynObject; |
95 | 99 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
96 | 100 |
import org.gvsig.tools.dynobject.DynStruct; |
... | ... | |
102 | 106 |
import org.gvsig.tools.folders.FoldersManager; |
103 | 107 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
104 | 108 |
import org.gvsig.tools.identitymanagement.UnauthorizedException; |
109 |
import org.gvsig.tools.observer.Observer; |
|
105 | 110 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
106 | 111 |
import org.gvsig.tools.script.Script; |
107 | 112 |
import org.gvsig.tools.script.ScriptManager; |
108 | 113 |
import org.gvsig.tools.service.spi.Services; |
109 | 114 |
import org.slf4j.Logger; |
110 | 115 |
import org.slf4j.LoggerFactory; |
111 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager.DatabaseWorkspaceListener; |
|
112 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
113 |
import org.gvsig.tools.observer.Observer; |
|
114 |
import org.gvsig.fmap.dal.feature.FeatureSet.DisposableFeatureSetIterable; |
|
115 |
import org.gvsig.fmap.dal.spi.DataServerExplorerPoolImpl; |
|
116 |
import static org.gvsig.fmap.dal.spi.DataStoreProviderServices.PROVIDER_PARAMTER_NAME; |
|
117 |
import org.gvsig.json.Json; |
|
118 | 116 |
|
119 | 117 |
@SuppressWarnings("UseSpecificCatch") |
120 | 118 |
public class DefaultDataManager |
... | ... | |
127 | 125 |
"DAL cache providers"; |
128 | 126 |
|
129 | 127 |
public static final String FILESYSTEM_EXPLORER_NAME = "FilesystemExplorer"; |
130 |
|
|
131 |
|
|
128 |
|
|
129 |
public static final long DEFAULT_MAX_SIZE_FOR_SMALL_FEATURE_SELECTION = 10000; |
|
130 |
|
|
132 | 131 |
private class Registers { |
133 | 132 |
|
134 | 133 |
private final Register store; |
... | ... | |
179 | 178 |
|
180 | 179 |
private final Set<Observer>storeObservers = new HashSet<>(); |
181 | 180 |
|
181 |
private long maxSizeForSmallFeatureSelection; |
|
182 |
|
|
182 | 183 |
public DefaultDataManager() { |
183 | 184 |
this.registers = new Registers(); |
184 | 185 |
this.defaultDataIndexProviders = new HashMap<>(); |
186 |
this.maxSizeForSmallFeatureSelection = DEFAULT_MAX_SIZE_FOR_SMALL_FEATURE_SELECTION; |
|
185 | 187 |
} |
186 | 188 |
|
187 | 189 |
@Override |
... | ... | |
1388 | 1390 |
} |
1389 | 1391 |
return null; |
1390 | 1392 |
} |
1393 |
|
|
1394 |
@Override |
|
1395 |
public void setMaxSizeForSmallFeatureSelection(long size){ |
|
1396 |
this.maxSizeForSmallFeatureSelection = size; |
|
1397 |
} |
|
1391 | 1398 |
|
1392 |
|
|
1399 |
@Override |
|
1400 |
public long getMaxSizeForSmallFeatureSelection() { |
|
1401 |
return this.maxSizeForSmallFeatureSelection; |
|
1402 |
} |
|
1403 |
|
|
1404 |
@Override |
|
1405 |
public Map createLargeMap() { |
|
1406 |
return new LargeMapImpl(); |
|
1407 |
} |
|
1408 |
|
|
1409 |
@Override |
|
1410 |
public Set createLargeSet() { |
|
1411 |
return new LargeSetImpl(); |
|
1412 |
} |
|
1393 | 1413 |
} |
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/impl/LargeMapImpl.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
18 |
* |
|
19 |
* For any additional information, do not hesitate to contact us |
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
21 |
*/ |
|
22 |
package org.gvsig.fmap.dal.impl; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.util.AbstractList; |
|
26 |
import java.util.Collection; |
|
27 |
import java.util.List; |
|
28 |
import java.util.Map; |
|
29 |
import java.util.Map.Entry; |
|
30 |
import java.util.Set; |
|
31 |
import org.gvsig.tools.ToolsLocator; |
|
32 |
import org.gvsig.tools.dispose.Disposable; |
|
33 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
|
34 |
import org.gvsig.tools.exception.BaseException; |
|
35 |
import org.gvsig.tools.folders.FoldersManager; |
|
36 |
import org.gvsig.tools.util.GetItemByKey; |
|
37 |
import org.gvsig.tools.util.GetKeys; |
|
38 |
import org.gvsig.tools.util.Size; |
|
39 |
import org.gvsig.tools.util.Size64; |
|
40 |
import org.h2.mvstore.MVMap; |
|
41 |
import org.h2.mvstore.MVStore; |
|
42 |
import org.slf4j.Logger; |
|
43 |
import org.slf4j.LoggerFactory; |
|
44 |
|
|
45 |
/** |
|
46 |
* |
|
47 |
* @author gvSIG Team |
|
48 |
*/ |
|
49 |
public class LargeMapImpl<K, V> extends AbstractDisposable implements Map<K, V>, GetItemByKey<K, V>, Size64, Size, GetKeys<K>, Disposable { |
|
50 |
|
|
51 |
protected static final Logger LOGGER = LoggerFactory.getLogger(LargeMapImpl.class); |
|
52 |
|
|
53 |
private MVStore mvstore; |
|
54 |
private MVMap<K, V> mvMap; |
|
55 |
|
|
56 |
public LargeMapImpl() { |
|
57 |
super(); |
|
58 |
FoldersManager folderManager = ToolsLocator.getFoldersManager(); |
|
59 |
File f = folderManager.getUniqueTemporaryFile("MinLargeMap.mv"); |
|
60 |
this.mvstore = MVStore.open(f.getAbsolutePath()); |
|
61 |
this.mvMap = mvstore.openMap("DefaultMap"); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public long size64() { |
|
66 |
return this.mvMap.sizeAsLong(); |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
protected void doDispose() throws BaseException { |
|
71 |
this.mvstore.close(); |
|
72 |
this.mvMap = null; |
|
73 |
this.mvstore = null; |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public Set<Entry<K, V>> entrySet() { |
|
78 |
return this.mvMap.entrySet(); |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public List<K> getKeys() { |
|
83 |
List<K> keys = new AbstractList<K>() { |
|
84 |
@Override |
|
85 |
public K get(int index) { |
|
86 |
K key = mvMap.getKey(index); |
|
87 |
return key; |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public int size() { |
|
92 |
return mvMap.size(); |
|
93 |
} |
|
94 |
}; |
|
95 |
return keys; |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public int size() { |
|
100 |
return this.mvMap.size(); |
|
101 |
} |
|
102 |
|
|
103 |
@Override |
|
104 |
public boolean isEmpty() { |
|
105 |
return this.mvMap.isEmpty(); |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public boolean containsKey(Object key) { |
|
110 |
return this.mvMap.containsKey(key); |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public boolean containsValue(Object value) { |
|
115 |
return this.mvMap.containsValue(value); |
|
116 |
} |
|
117 |
|
|
118 |
@Override |
|
119 |
public V get(Object key) { |
|
120 |
return this.mvMap.get(key); |
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
public V put(K key, V value) { |
|
125 |
return this.mvMap.put(key, value); |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public V remove(Object key) { |
|
130 |
return this.mvMap.remove(key); |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public void putAll(Map<? extends K, ? extends V> m) { |
|
135 |
this.mvMap.putAll(m); |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
public void clear() { |
|
140 |
this.mvMap.clear(); |
|
141 |
} |
|
142 |
|
|
143 |
@Override |
|
144 |
public Set<K> keySet() { |
|
145 |
return this.mvMap.keySet(); |
|
146 |
} |
|
147 |
|
|
148 |
@Override |
|
149 |
public Collection<V> values() { |
|
150 |
return this.mvMap.values(); |
|
151 |
} |
|
152 |
} |
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/impl/DALDefaultImplLibrary.java | ||
---|---|---|
48 | 48 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStoreTransforms; |
49 | 49 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureType; |
50 | 50 |
import org.gvsig.fmap.dal.feature.impl.DefaultForeingKey; |
51 |
import org.gvsig.fmap.dal.feature.impl.LargeFeatureReferenceSelection; |
|
52 |
import org.gvsig.fmap.dal.feature.impl.LargeFeatureSelection; |
|
51 | 53 |
import org.gvsig.fmap.dal.feature.impl.indexes.jsir.JSIRSpatialIndexProviderFactory; |
52 | 54 |
import org.gvsig.fmap.dal.feature.impl.indexes.memoryspatial.MemorySpatialIndexProviderFactory; |
53 | 55 |
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.ComputeAvailableValuesFromTable; |
... | ... | |
136 | 138 |
AbstractFeatureStoreTransform.registerPersistent(); |
137 | 139 |
DefaultFeatureReferenceSelection.registerPersistent(); |
138 | 140 |
DefaultFeatureSelection.registerPersistent(); |
141 |
LargeFeatureReferenceSelection.registerPersistent(); |
|
142 |
LargeFeatureSelection.registerPersistent(); |
|
139 | 143 |
DefaultForeingKey.registerPersistenceDefinition(); |
140 | 144 |
DefaultFeatureExtraColumns.registerPersistent(); |
141 | 145 |
DefaultFeatureExpressionEvaluator.registerPersistence(); |
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/LargeFeatureSelection.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify it under |
|
7 |
* the terms of the GNU General Public License as published by the Free Software |
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later |
|
9 |
* version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
14 |
* details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us at info AT |
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.fmap.dal.feature.impl; |
|
24 |
|
|
25 |
import java.util.HashMap; |
|
26 |
import java.util.Iterator; |
|
27 |
import java.util.List; |
|
28 |
import java.util.Map; |
|
29 |
import org.gvsig.fmap.dal.exception.DataException; |
|
30 |
import org.gvsig.fmap.dal.exception.DataRuntimeException; |
|
31 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
32 |
import org.gvsig.fmap.dal.feature.Feature; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
|
39 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
40 |
import org.gvsig.fmap.dal.feature.impl.featureset.AbstractFeatureSet; |
|
41 |
import org.gvsig.fmap.dal.feature.impl.featureset.DefaultFeatureSet; |
|
42 |
import org.gvsig.tools.ToolsLocator; |
|
43 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
44 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
45 |
import org.gvsig.tools.dynobject.DynStruct; |
|
46 |
import org.gvsig.tools.exception.BaseException; |
|
47 |
import org.gvsig.tools.observer.Observable; |
|
48 |
import org.gvsig.tools.observer.Observer; |
|
49 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
50 |
import org.gvsig.tools.persistence.PersistentState; |
|
51 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
52 |
import org.gvsig.tools.visitor.Visitor; |
|
53 |
import org.slf4j.Logger; |
|
54 |
import org.slf4j.LoggerFactory; |
|
55 |
|
|
56 |
/** |
|
57 |
* Default implementation of the FeatureSelection interface. Internally, only |
|
58 |
* FeatureReference values are stored. |
|
59 |
* |
|
60 |
* This implementation performs better if used with the selection related |
|
61 |
* methods: select, deselect and isSelected ones. |
|
62 |
* |
|
63 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
64 |
*/ |
|
65 |
public class LargeFeatureSelection extends AbstractFeatureSet |
|
66 |
implements FeatureSelection { |
|
67 |
|
|
68 |
|
|
69 |
private static final String DYNCLASS_PERSISTENT_NAME = "LargeFeatureSelection"; |
|
70 |
|
|
71 |
public class RemoveFromFeatureSelectionException extends DataRuntimeException { |
|
72 |
|
|
73 |
/** |
|
74 |
* |
|
75 |
*/ |
|
76 |
private static final long serialVersionUID = 2636692469445838928L; |
|
77 |
private final static String MESSAGE_FORMAT = "Can't remove feature from reversed selection."; |
|
78 |
private final static String MESSAGE_KEY = "_RemoveFromFeatureSelectionException"; |
|
79 |
|
|
80 |
public RemoveFromFeatureSelectionException(Throwable cause) { |
|
81 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID); |
|
82 |
//setValue("store", store); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* Facade over a Iterator of FeatureReferences, to return Features instead. |
|
88 |
* |
|
89 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
90 |
*/ |
|
91 |
private class FeatureIteratorFacade implements DisposableIterator { |
|
92 |
|
|
93 |
private final Logger LOGGER = LoggerFactory |
|
94 |
.getLogger(FeatureIteratorFacade.class); |
|
95 |
|
|
96 |
private java.util.Iterator refIterator; |
|
97 |
|
|
98 |
private FeatureStore featureStore; |
|
99 |
private Feature currentFeature = null; |
|
100 |
|
|
101 |
public FeatureIteratorFacade(java.util.Iterator iter, |
|
102 |
FeatureStore featureStore) { |
|
103 |
this.refIterator = iter; |
|
104 |
this.featureStore = featureStore; |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public boolean hasNext() { |
|
109 |
return refIterator.hasNext(); |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public Object next() { |
|
114 |
FeatureReference ref = nextFeatureReference(); |
|
115 |
try { |
|
116 |
currentFeature = featureStore.getFeatureByReference(ref); |
|
117 |
return currentFeature; |
|
118 |
} catch (DataException ex) { |
|
119 |
LOGGER.error( |
|
120 |
"Error loading the Feature with FeatureReference: " |
|
121 |
+ ref, ex); |
|
122 |
return null; |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
/** |
|
127 |
* Returns the next FeatureReference. |
|
128 |
* |
|
129 |
* @return the next FeatureReference |
|
130 |
*/ |
|
131 |
public FeatureReference nextFeatureReference() { |
|
132 |
return (FeatureReference) refIterator.next(); |
|
133 |
} |
|
134 |
|
|
135 |
@Override |
|
136 |
public void remove() { |
|
137 |
try { |
|
138 |
featureStore.delete(currentFeature); |
|
139 |
refIterator.remove(); |
|
140 |
} catch (DataException e) { |
|
141 |
throw new RemoveFromFeatureSelectionException(e); |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
public class RemoveFromFeatureSelectionException extends DataRuntimeException { |
|
146 |
|
|
147 |
/** |
|
148 |
* |
|
149 |
*/ |
|
150 |
private static final long serialVersionUID = 2636692469445838928L; |
|
151 |
private final static String MESSAGE_FORMAT = "Can't remove feature from selection."; |
|
152 |
private final static String MESSAGE_KEY = "_RemoveFromFeatureSelectionException"; |
|
153 |
|
|
154 |
public RemoveFromFeatureSelectionException(Throwable cause) { |
|
155 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID); |
|
156 |
//setValue("store", store); |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
@Override |
|
161 |
public void dispose() { |
|
162 |
if (refIterator instanceof DisposableIterator) { |
|
163 |
((DisposableIterator) refIterator).dispose(); |
|
164 |
} |
|
165 |
refIterator = null; |
|
166 |
featureStore = null; |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
170 |
// /** |
|
171 |
// * Facade over a Iterator of FeatureReferences, to return Features instead, |
|
172 |
// * when the Selection is reversed |
|
173 |
// * |
|
174 |
// * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
175 |
// */ |
|
176 |
// private class ReversedFeatureIteratorFacade implements DisposableIterator { |
|
177 |
// |
|
178 |
// private SelectionData selectionData; |
|
179 |
// |
|
180 |
// private DisposableIterator iterator; |
|
181 |
// |
|
182 |
// private Feature nextFeature = null; |
|
183 |
// private Feature currentFeature = null; |
|
184 |
// |
|
185 |
// private FeatureSet featureSet; |
|
186 |
// |
|
187 |
// public ReversedFeatureIteratorFacade(SelectionData selectionData, |
|
188 |
// FeatureStore featureStore, boolean fastIterator) { |
|
189 |
// this.selectionData = selectionData; |
|
190 |
// |
|
191 |
// // Load a Set with all the store features |
|
192 |
// try { |
|
193 |
// featureSet = new IgnoreInsertAndUpdateFeatureSet( |
|
194 |
// (DefaultFeatureStore) featureStore, |
|
195 |
// new DefaultFeatureQuery(featureStore.getDefaultFeatureType()) |
|
196 |
// ); |
|
197 |
// iterator = featureSet.fastIterator(); |
|
198 |
// } catch (DataException ex) { |
|
199 |
// throw new ReversedSelectionIteratorException(ex); |
|
200 |
// } |
|
201 |
// |
|
202 |
// // Filter the features not selected and position in the next |
|
203 |
// // selected feature |
|
204 |
// positionInNextElement(); |
|
205 |
// } |
|
206 |
// |
|
207 |
// @Override |
|
208 |
// public boolean hasNext() { |
|
209 |
// return nextFeature != null; |
|
210 |
// } |
|
211 |
// |
|
212 |
// @Override |
|
213 |
// public Object next() { |
|
214 |
// featureIterators.remove(currentFeature); |
|
215 |
// currentFeature = nextFeature.getCopy(); |
|
216 |
// featureIterators.put(currentFeature, this); |
|
217 |
// positionInNextElement(); |
|
218 |
// return currentFeature; |
|
219 |
// } |
|
220 |
// |
|
221 |
// @Override |
|
222 |
// public void remove() { |
|
223 |
// try { |
|
224 |
// featureSet.delete(currentFeature); |
|
225 |
// } catch (DataException e) { |
|
226 |
// throw new RemoveFromFeatureSelectionException(e); |
|
227 |
// |
|
228 |
// } |
|
229 |
// } |
|
230 |
// |
|
231 |
// private void positionInNextElement() { |
|
232 |
// nextFeature = null; |
|
233 |
// while (iterator.hasNext()) { |
|
234 |
// nextFeature = (Feature) iterator.next(); |
|
235 |
// if (selectionData.contains(nextFeature.getReference())) { |
|
236 |
// nextFeature = null; |
|
237 |
// } else { |
|
238 |
// break; |
|
239 |
// } |
|
240 |
// } |
|
241 |
// } |
|
242 |
// |
|
243 |
// @Override |
|
244 |
// public void dispose() { |
|
245 |
// this.featureSet.dispose(); |
|
246 |
// this.iterator.dispose(); |
|
247 |
// this.selectionData = null; |
|
248 |
// this.nextFeature = null; |
|
249 |
// } |
|
250 |
// } |
|
251 |
|
|
252 |
// private Map featureTypeCounts = new HashMap(1); |
|
253 |
private final Map<Feature, Iterator> featureIterators = new HashMap<>(); |
|
254 |
private final LargeFeatureReferenceSelection featureReferenceSelection; |
|
255 |
|
|
256 |
/** |
|
257 |
* Creates a DefaultFeatureSelection, with a FeatureStore. |
|
258 |
* |
|
259 |
* @param featureStore the FeatureStore to load Features from |
|
260 |
* @throws DataException if there is an error while getting the total number |
|
261 |
* of Features of the Store. |
|
262 |
* @see AbstractSetBasedDataSelection#DefaultSelection(int) |
|
263 |
*/ |
|
264 |
public LargeFeatureSelection(DefaultFeatureStore featureStore) |
|
265 |
throws DataException { |
|
266 |
this.featureReferenceSelection = new LargeFeatureReferenceSelection(featureStore); |
|
267 |
} |
|
268 |
|
|
269 |
/** |
|
270 |
* Creates a new Selection with the total size of Features from which the |
|
271 |
* selection will be performed. |
|
272 |
* |
|
273 |
* @param featureStore the FeatureStore of the selected FeatureReferences |
|
274 |
* @param helper to get some information of the Store |
|
275 |
* @throws DataException if there is an error while getting the total number |
|
276 |
* of Features of the Store. |
|
277 |
*/ |
|
278 |
public LargeFeatureSelection(FeatureStore featureStore, |
|
279 |
FeatureSelectionHelper helper) throws DataException { |
|
280 |
this.featureReferenceSelection = new LargeFeatureReferenceSelection(featureStore, helper); |
|
281 |
} |
|
282 |
|
|
283 |
/** |
|
284 |
* Constructor used by the persistence manager. Don't use directly. After to |
|
285 |
* invoke this method, the persistence manager calls the the method |
|
286 |
* {@link #loadFromState(PersistentState)} to set the values of the internal |
|
287 |
* attributes that this class needs to work. |
|
288 |
*/ |
|
289 |
public LargeFeatureSelection() { |
|
290 |
this.featureReferenceSelection = new LargeFeatureReferenceSelection(); |
|
291 |
} |
|
292 |
|
|
293 |
@Override |
|
294 |
public FeatureStore getFeatureStore() { |
|
295 |
return this.featureReferenceSelection.getFeatureStore(); |
|
296 |
} |
|
297 |
|
|
298 |
private void notifyObservers(String notificationType) { |
|
299 |
this.featureReferenceSelection.notifyObservers(notificationType); |
|
300 |
} |
|
301 |
|
|
302 |
@Override |
|
303 |
public void enableNotifications() { |
|
304 |
this.featureReferenceSelection.enableNotifications(); |
|
305 |
} |
|
306 |
|
|
307 |
@Override |
|
308 |
public void disableNotifications() { |
|
309 |
this.featureReferenceSelection.disableNotifications(); |
|
310 |
} |
|
311 |
|
|
312 |
// public boolean isReversed() { |
|
313 |
// return this.featureReferenceSelection.isReversed(); |
|
314 |
// } |
|
315 |
|
|
316 |
@Override |
|
317 |
public long getSelectedCount() { |
|
318 |
return this.featureReferenceSelection.getSelectedCount(); |
|
319 |
} |
|
320 |
|
|
321 |
@Override |
|
322 |
public boolean select(FeatureReference reference) { |
|
323 |
return this.featureReferenceSelection.select(reference); |
|
324 |
} |
|
325 |
|
|
326 |
@Override |
|
327 |
public boolean deselect(FeatureReference reference) { |
|
328 |
return this.featureReferenceSelection.deselect(reference); |
|
329 |
} |
|
330 |
|
|
331 |
@Override |
|
332 |
public Iterator referenceIterator() { |
|
333 |
return this.featureReferenceSelection.referenceIterator(); |
|
334 |
} |
|
335 |
|
|
336 |
@Override |
|
337 |
public void selectAll() throws DataException { |
|
338 |
this.featureReferenceSelection.selectAll(); |
|
339 |
} |
|
340 |
|
|
341 |
@Override |
|
342 |
public void deselectAll() throws DataException { |
|
343 |
this.featureReferenceSelection.deselectAll(); |
|
344 |
} |
|
345 |
|
|
346 |
@Override |
|
347 |
public boolean isSelected(FeatureReference reference) { |
|
348 |
return this.featureReferenceSelection.isSelected(reference); |
|
349 |
} |
|
350 |
|
|
351 |
@Override |
|
352 |
public void reverse() { |
|
353 |
this.featureReferenceSelection.reverse(); |
|
354 |
} |
|
355 |
|
|
356 |
@Override |
|
357 |
public void dispose() { |
|
358 |
this.featureReferenceSelection.dispose(); |
|
359 |
} |
|
360 |
|
|
361 |
@Override |
|
362 |
public void update(Observable o, Object o1) { |
|
363 |
this.featureReferenceSelection.update(o, o1); |
|
364 |
} |
|
365 |
|
|
366 |
@Override |
|
367 |
public void addObserver(Observer obsrvr) { |
|
368 |
this.featureReferenceSelection.addObserver(obsrvr); |
|
369 |
} |
|
370 |
|
|
371 |
@Override |
|
372 |
public void deleteObserver(Observer obsrvr) { |
|
373 |
this.featureReferenceSelection.deleteObserver(obsrvr); |
|
374 |
} |
|
375 |
|
|
376 |
@Override |
|
377 |
public void deleteObservers() { |
|
378 |
this.featureReferenceSelection.deleteObservers(); |
|
379 |
} |
|
380 |
|
|
381 |
@Override |
|
382 |
public void beginComplexNotification() { |
|
383 |
this.featureReferenceSelection.beginComplexNotification(); |
|
384 |
} |
|
385 |
|
|
386 |
@Override |
|
387 |
public void endComplexNotification() { |
|
388 |
this.featureReferenceSelection.endComplexNotification(); |
|
389 |
} |
|
390 |
|
|
391 |
@Override |
|
392 |
public void saveToState(PersistentState ps) throws PersistenceException { |
|
393 |
this.featureReferenceSelection.saveToState(ps); |
|
394 |
} |
|
395 |
|
|
396 |
@Override |
|
397 |
public boolean select(Feature feature) { |
|
398 |
return this.featureReferenceSelection.select(feature.getReference()); |
|
399 |
} |
|
400 |
|
|
401 |
@Override |
|
402 |
public boolean select(FeatureSet features) throws DataException { |
|
403 |
boolean change = false; |
|
404 |
boolean inComplex = false; |
|
405 |
disableNotifications(); |
|
406 |
DisposableIterator iter = null; |
|
407 |
try { |
|
408 |
for (iter = features.fastIterator(); iter.hasNext();) { |
|
409 |
change |= this.featureReferenceSelection.select(((Feature) iter.next()).getReference()); |
|
410 |
} |
|
411 |
} finally { |
|
412 |
DisposeUtils.disposeQuietly(iter); |
|
413 |
} |
|
414 |
enableNotifications(); |
|
415 |
return change; |
|
416 |
} |
|
417 |
|
|
418 |
@Override |
|
419 |
public boolean deselect(Feature feature) { |
|
420 |
return this.featureReferenceSelection.deselect(feature.getReference()); //, true); |
|
421 |
} |
|
422 |
|
|
423 |
@Override |
|
424 |
public boolean deselect(FeatureSet features) throws DataException { |
|
425 |
boolean change = false; |
|
426 |
disableNotifications(); |
|
427 |
DisposableIterator iter = null; |
|
428 |
try { |
|
429 |
for (iter = features.fastIterator(); iter.hasNext();) { |
|
430 |
change |= deselect((Feature) iter.next()); |
|
431 |
} |
|
432 |
} finally { |
|
433 |
DisposeUtils.disposeQuietly(iter); |
|
434 |
} |
|
435 |
enableNotifications(); |
|
436 |
return change; |
|
437 |
} |
|
438 |
|
|
439 |
@Override |
|
440 |
public boolean isSelected(Feature feature) { |
|
441 |
if (feature == null) { |
|
442 |
return false; |
|
443 |
} |
|
444 |
if( this.featureReferenceSelection.isEmpty() ) { |
|
445 |
return false; |
|
446 |
} |
|
447 |
return this.featureReferenceSelection.isSelected(feature.getReference()); |
|
448 |
} |
|
449 |
|
|
450 |
@Override |
|
451 |
public FeatureType getDefaultFeatureType() { |
|
452 |
try { |
|
453 |
return getFeatureStore().getDefaultFeatureType(); |
|
454 |
} catch (DataException ex) { |
|
455 |
LOG.error("Error getting the default feature type " |
|
456 |
+ "of the FeatureStore: " + getFeatureStore(), ex); |
|
457 |
} |
|
458 |
return null; |
|
459 |
} |
|
460 |
|
|
461 |
@Override |
|
462 |
public List getFeatureTypes() { |
|
463 |
return this.featureReferenceSelection.getFeatureTypes(); |
|
464 |
// // Go through the map of FeatureTypes, and return only the ones that |
|
465 |
// // have at least a Feature. |
|
466 |
// List types = new ArrayList(); |
|
467 |
// for (java.util.Iterator iterator = featureTypeCounts.entrySet() |
|
468 |
// .iterator(); iterator.hasNext();) { |
|
469 |
// Map.Entry entry = (Entry) iterator.next(); |
|
470 |
// FeatureType type = (FeatureType) entry.getKey(); |
|
471 |
// Long count = (Long) entry.getValue(); |
|
472 |
// |
|
473 |
// if (count > 0) { |
|
474 |
// types.add(type); |
|
475 |
// } |
|
476 |
// } |
|
477 |
// |
|
478 |
// return types; |
|
479 |
} |
|
480 |
|
|
481 |
@Override |
|
482 |
public long getSize() throws DataException { |
|
483 |
return getSelectedCount(); |
|
484 |
} |
|
485 |
|
|
486 |
/** |
|
487 |
* Returns the list of selected values, or the deselected ones if the |
|
488 |
* selection has been reversed. |
|
489 |
* |
|
490 |
* WARN: not very good performance implementation. |
|
491 |
*/ |
|
492 |
@Override |
|
493 |
public DisposableIterator iterator(long index) { |
|
494 |
return iterator(index, 0, false); |
|
495 |
} |
|
496 |
|
|
497 |
@Override |
|
498 |
public DisposableIterator iterator(long index, long elements) { |
|
499 |
return iterator(index, elements, false); |
|
500 |
} |
|
501 |
|
|
502 |
/** |
|
503 |
* Returns the list of selected values, or the deselected ones if the |
|
504 |
* selection has been reversed. |
|
505 |
* |
|
506 |
* WARN: not really a fast implementation. |
|
507 |
*/ |
|
508 |
@Override |
|
509 |
public DisposableIterator fastIterator(long index) { |
|
510 |
return fastIterator(index, 0); |
|
511 |
} |
|
512 |
|
|
513 |
@Override |
|
514 |
public DisposableIterator fastIterator(long index, long elements) { |
|
515 |
return iterator(index, elements, true); |
|
516 |
} |
|
517 |
|
|
518 |
|
|
519 |
protected void clearFeatureReferences() { |
|
520 |
this.featureReferenceSelection.clearFeatureReferences(); |
|
521 |
// featureTypeCounts.clear(); |
|
522 |
} |
|
523 |
|
|
524 |
/** |
|
525 |
* Creates an iterator for the Selection. |
|
526 |
*/ |
|
527 |
private DisposableIterator iterator(long index, long elements, boolean fastIterator) { |
|
528 |
Iterator iter = this.featureReferenceSelection.referenceIterator(); |
|
529 |
for (long l = 0; l < index && iter.hasNext(); l++) { |
|
530 |
iter.next(); |
|
531 |
} |
|
532 |
return new FeatureIteratorFacade(iter, getFeatureStore()); |
|
533 |
// if (isReversed()) { |
|
534 |
// DisposableIterator iter = new ReversedFeatureIteratorFacade( |
|
535 |
// getData(), getFeatureStore(), fastIterator); |
|
536 |
// for (long l = 0; l < index && iter.hasNext(); l++) { |
|
537 |
// iter.next(); |
|
538 |
// } |
|
539 |
// return iter; |
|
540 |
// |
|
541 |
// } else { |
|
542 |
// // TODO: maybe we could add a new referenceIterator(int index) |
|
543 |
// // method that could be implemented in a more performant way |
|
544 |
// |
|
545 |
// java.util.Iterator iter = getData().getSelected().iterator(); |
|
546 |
// for (long l = 0; l < index && iter.hasNext(); l++) { |
|
547 |
// iter.next(); |
|
548 |
// } |
|
549 |
// return new FeatureIteratorFacade(iter, getFeatureStore()); |
|
550 |
// } |
|
551 |
} |
|
552 |
|
|
553 |
// private Long removeFeatureTypeCount(FeatureType featureType) { |
|
554 |
// Long count = (Long) featureTypeCounts.get(featureType); |
|
555 |
// if (count == null) { |
|
556 |
// count = new Long(-1); |
|
557 |
// } else { |
|
558 |
// count = count - 1; |
|
559 |
// } |
|
560 |
// featureTypeCounts.put(featureType, count); |
|
561 |
// return count; |
|
562 |
// } |
|
563 |
// |
|
564 |
// private Long addFeatureTypeCount(FeatureType featureType) { |
|
565 |
// Long count = (Long) featureTypeCounts.get(featureType); |
|
566 |
// if (count == null) { |
|
567 |
// count = new Long(1); |
|
568 |
// } else { |
|
569 |
// count = count + 1; |
|
570 |
// } |
|
571 |
// featureTypeCounts.put(featureType, count); |
|
572 |
// return count; |
|
573 |
// } |
|
574 |
|
|
575 |
@Override |
|
576 |
public void delete(Feature feature) throws DataException { |
|
577 |
Iterator it = this.featureIterators.get(feature); |
|
578 |
if (it != null) { |
|
579 |
it.remove(); |
|
580 |
return; |
|
581 |
} |
|
582 |
feature.getStore().delete(feature); |
|
583 |
} |
|
584 |
|
|
585 |
@Override |
|
586 |
public void insert(EditableFeature feature) throws DataException { |
|
587 |
feature.getStore().insert(feature); |
|
588 |
} |
|
589 |
|
|
590 |
@Override |
|
591 |
public void update(EditableFeature feature) throws DataException { |
|
592 |
feature.getStore().update(feature); |
|
593 |
} |
|
594 |
|
|
595 |
|
|
596 |
@Override |
|
597 |
public void commitChanges() throws DataException { |
|
598 |
} |
|
599 |
|
|
600 |
/* |
|
601 |
* (non-Javadoc) |
|
602 |
* |
|
603 |
* @seeorg.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection# |
|
604 |
* loadFromState(org.gvsig.tools.persistence.PersistentState) |
|
605 |
*/ |
|
606 |
@Override |
|
607 |
public void loadFromState(PersistentState state) |
|
608 |
throws PersistenceException { |
|
609 |
this.featureReferenceSelection.loadFromState(state); |
|
610 |
} |
|
611 |
|
|
612 |
protected void doDispose() throws BaseException { |
|
613 |
this.featureReferenceSelection.doDispose(); |
|
614 |
// featureTypeCounts.clear(); |
|
615 |
} |
|
616 |
|
|
617 |
public static void registerPersistent() { |
|
618 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
619 |
DynStruct definition = manager.addDefinition(LargeFeatureSelection.class, DYNCLASS_PERSISTENT_NAME, |
|
620 |
"LargeFeatureSelection Persistent definition", null, null); |
|
621 |
|
|
622 |
definition.extend(manager.getDefinition(LargeFeatureReferenceSelection.DYNCLASS_PERSISTENT_NAME)); |
|
623 |
// definition.addDynFieldMap("featureTypeCounts") |
|
624 |
// .setClassOfItems(Long.class).setMandatory(false); |
|
625 |
|
|
626 |
} |
|
627 |
|
|
628 |
@Override |
|
629 |
public Object clone() throws CloneNotSupportedException { |
|
630 |
LargeFeatureSelection clone = (LargeFeatureSelection) super.clone(); |
|
631 |
// clone.featureTypeCounts = new HashMap(featureTypeCounts); |
|
632 |
return clone; |
|
633 |
} |
|
634 |
|
|
635 |
@Override |
|
636 |
protected void doAccept(Visitor visitor, long firstValueIndex, long elements) throws BaseException { |
|
637 |
if( this.featureReferenceSelection.isEmpty() ) { |
|
638 |
return; |
|
639 |
} |
|
640 |
DisposableIterator iterator = fastIterator(firstValueIndex, elements); |
|
641 |
if (iterator != null) { |
|
642 |
try { |
|
643 |
while (iterator.hasNext()) { |
|
644 |
Feature feature = (Feature) iterator.next(); |
|
645 |
visitor.visit(feature); |
|
646 |
} |
|
647 |
} finally { |
|
648 |
iterator.dispose(); |
|
649 |
} |
|
650 |
} |
|
651 |
} |
|
652 |
|
|
653 |
private static class IgnoreInsertAndUpdateFeatureSet extends DefaultFeatureSet { |
|
654 |
|
|
655 |
public IgnoreInsertAndUpdateFeatureSet(DefaultFeatureStore store, FeatureQuery query) throws DataException { |
|
656 |
super(store, query); |
|
657 |
} |
|
658 |
|
|
659 |
@Override |
|
660 |
public void update(Observable obsevable, Object notification) { |
|
661 |
String type = ((FeatureStoreNotification) notification).getType(); |
|
662 |
if (type.equalsIgnoreCase(FeatureStoreNotification.AFTER_INSERT) |
|
663 |
|| type.equalsIgnoreCase(FeatureStoreNotification.AFTER_UPDATE)) { |
|
664 |
return; |
|
665 |
} |
|
666 |
super.update(obsevable, notification); |
|
667 |
} |
|
668 |
|
|
669 |
} |
|
670 |
|
|
671 |
@Override |
|
672 |
public boolean isAvailable() { |
|
673 |
return this.featureReferenceSelection.isAvailable(); |
|
674 |
} |
|
675 |
|
|
676 |
} |
|
0 | 677 |
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 | ||
---|---|---|
909 | 909 |
|
910 | 910 |
@Override |
911 | 911 |
public FeatureSelection createFeatureSelection() throws DataException { |
912 |
long maxSize = dataManager.getMaxSizeForSmallFeatureSelection(); |
|
913 |
if(this.provider.getFeatureCount()>maxSize) { |
|
914 |
return createLargeFeatureSelection(); |
|
915 |
} |
|
912 | 916 |
return this.provider.createFeatureSelection(); |
913 | 917 |
} |
918 |
|
|
919 |
@Override |
|
920 |
public FeatureSelection createLargeFeatureSelection() throws DataException { |
|
921 |
return new LargeFeatureSelection(this); |
|
922 |
|
|
923 |
} |
|
924 |
|
|
925 |
@Override |
|
926 |
public FeatureSelection createMemoryFeatureSelection() throws DataException { |
|
927 |
return this.provider.createFeatureSelection(); |
|
928 |
} |
|
914 | 929 |
|
915 | 930 |
@Override |
916 | 931 |
public FeatureSelection getFeatureSelection() throws DataException { |
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/LargeFeatureReferenceSelection.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
18 |
* |
|
19 |
* For any additional information, do not hesitate to contact us |
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
21 |
*/ |
|
22 |
package org.gvsig.fmap.dal.feature.impl; |
|
23 |
|
|
24 |
import java.util.Iterator; |
|
25 |
import java.util.List; |
|
26 |
import java.util.Set; |
|
27 |
import org.gvsig.fmap.dal.DataStore; |
|
28 |
import org.gvsig.fmap.dal.DataStoreNotification; |
|
29 |
import org.gvsig.fmap.dal.exception.DataException; |
|
30 |
import org.gvsig.fmap.dal.feature.Feature; |
|
31 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureReferenceSelection; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
36 |
import org.gvsig.fmap.dal.impl.LargeSetImpl; |
|
37 |
import org.gvsig.tools.ToolsLocator; |
|
38 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
39 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
|
40 |
import org.gvsig.tools.dynobject.DynStruct; |
|
41 |
import org.gvsig.tools.exception.BaseException; |
|
42 |
import org.gvsig.tools.observer.Observable; |
|
43 |
import org.gvsig.tools.observer.Observer; |
|
44 |
import org.gvsig.tools.observer.impl.DelegateWeakReferencingObservable; |
|
45 |
import org.gvsig.tools.persistence.PersistentState; |
|
46 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
47 |
import org.gvsig.tools.visitor.Visitor; |
|
48 |
|
|
49 |
/** |
|
50 |
* |
|
51 |
* @author gvSIG Team |
|
52 |
*/ |
|
53 |
public class LargeFeatureReferenceSelection extends AbstractDisposable |
|
54 |
implements FeatureReferenceSelection { |
|
55 |
|
|
56 |
public static final String DYNCLASS_PERSISTENT_NAME = "LargeFeatureReferenceSelection"; |
|
57 |
|
|
58 |
private Set<String> selection; |
|
59 |
private FeatureStore featureStore; |
|
60 |
private Boolean available = null; |
|
61 |
private DelegateWeakReferencingObservable delegateObservable |
|
62 |
= new DelegateWeakReferencingObservable(this); |
|
63 |
|
|
64 |
public LargeFeatureReferenceSelection(DefaultFeatureStore featureStore) { |
|
65 |
super(); |
|
66 |
this.featureStore = featureStore; |
|
67 |
DisposeUtils.bind(this.featureStore); |
|
68 |
this.selection = new LargeSetImpl<>(); |
|
69 |
|
|
70 |
} |
|
71 |
|
|
72 |
LargeFeatureReferenceSelection(FeatureStore featureStore, FeatureSelectionHelper helper) { |
|
73 |
super(); |
|
74 |
this.featureStore = featureStore; |
|
75 |
DisposeUtils.bind(this.featureStore); |
|
76 |
this.selection = new LargeSetImpl<>(); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Constructor used by the persistence manager. Don't use directly. After to |
|
81 |
* invoke this method, the persistence manager calls the the method |
|
82 |
* {@link #loadFromState(PersistentState)} to set the values of the internal |
|
83 |
* attributes that this class needs to work. |
|
84 |
*/ |
|
85 |
LargeFeatureReferenceSelection() { |
|
86 |
super(); |
|
87 |
} |
|
88 |
|
|
89 |
public FeatureStore getFeatureStore() { |
|
90 |
return featureStore; |
|
91 |
} |
|
92 |
|
|
93 |
@Override |
|
94 |
public boolean select(FeatureReference reference) { |
|
95 |
return this.selection.add(reference.getCode()); |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public boolean deselect(FeatureReference reference) { |
|
100 |
boolean change; |
|
101 |
change = this.selection.contains(reference.getCode()); |
|
102 |
this.selection.remove(reference.getCode()); |
|
103 |
if (change) { |
|
104 |
notifyObservers(DataStoreNotification.SELECTION_CHANGE); |
|
105 |
} |
|
106 |
return change; |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public void selectAll() throws DataException { |
|
111 |
try { |
|
112 |
this.featureStore.accept((Object obj) -> { |
|
113 |
selection.add(((Feature) obj).getReference().getCode()); |
|
114 |
}); |
|
115 |
} catch (BaseException ex) { |
|
116 |
throw new RuntimeException("Can't select all", ex); |
|
117 |
} |
|
118 |
} |
|
119 |
|
|
120 |
@Override |
|
121 |
public void deselectAll() throws DataException { |
|
122 |
this.selection.clear(); |
|
123 |
} |
|
124 |
|
|
125 |
@Override |
|
126 |
public boolean isSelected(FeatureReference reference) { |
|
127 |
return this.selection.contains(reference.getCode()); |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public void reverse() { |
|
132 |
try { |
|
133 |
this.featureStore.accept((Object obj) -> { |
|
134 |
String key = ((Feature) obj).getReference().getCode(); |
|
135 |
if(selection.contains(key)) { |
|
136 |
selection.remove(key); |
|
137 |
} else { |
|
138 |
selection.add(key); |
|
139 |
} |
|
140 |
}); |
|
141 |
} catch (BaseException ex) { |
|
142 |
throw new RuntimeException("Can't reverse selection", ex); |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
public boolean isEmpty() { |
|
147 |
if (this.selection == null) { |
|
148 |
return true; |
|
149 |
} |
|
150 |
return this.getSelectedCount() == 0; |
|
151 |
} |
|
152 |
|
|
153 |
@Override |
|
154 |
public long getSelectedCount() { |
|
155 |
return ((LargeSetImpl)selection).size64(); |
|
156 |
} |
|
157 |
|
|
158 |
@Override |
|
159 |
public Iterator referenceIterator() { |
|
160 |
|
|
161 |
Iterator<String> it = selection.iterator(); |
|
162 |
|
|
163 |
Iterator<FeatureReference> itFeatureReferences = new Iterator<FeatureReference>() { |
|
164 |
@Override |
|
165 |
public boolean hasNext() { |
|
166 |
return it.hasNext(); |
|
167 |
} |
|
168 |
|
|
169 |
@Override |
|
170 |
public FeatureReference next() { |
|
171 |
String code = it.next(); |
|
172 |
FeatureReference fref = featureStore.getFeatureReference(code); |
|
173 |
return fref; |
|
174 |
} |
|
175 |
}; |
|
176 |
return itFeatureReferences; |
|
177 |
} |
|
178 |
|
|
179 |
@Override |
|
180 |
public boolean isAvailable() { |
|
181 |
if (this.available == null) { |
|
182 |
this.available = false; |
|
183 |
if(this.featureStore != null){ |
|
184 |
try { |
|
185 |
FeatureType type = this.featureStore.getDefaultFeatureType(); |
|
186 |
this.available = type.supportReferences(); |
|
187 |
} catch (DataException ex) { |
|
188 |
this.available = false; |
|
189 |
} |
|
190 |
} |
|
191 |
} |
|
192 |
return this.available; |
|
193 |
} |
|
194 |
|
|
195 |
@Override |
|
196 |
public boolean isFromStore(DataStore store) { |
|
197 |
return featureStore.equals(store); |
|
198 |
} |
|
199 |
|
|
200 |
@Override |
|
201 |
public void accept(Visitor visitor) throws BaseException { |
|
202 |
for (String string : selection) { |
|
203 |
FeatureReference fref = featureStore.getFeatureReference(string); |
|
204 |
visitor.visit(fref); |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
208 |
@Override |
|
209 |
protected void doDispose() throws BaseException { |
|
210 |
delegateObservable.deleteObservers(); |
|
211 |
deselectAll(); |
|
212 |
DisposeUtils.dispose(this.featureStore); |
|
213 |
DisposeUtils.dispose(this.selection); |
|
214 |
this.delegateObservable = null; |
|
215 |
this.featureStore = null; |
|
216 |
this.selection = null; |
|
217 |
} |
|
218 |
|
|
219 |
@Override |
|
220 |
public void addObserver(Observer observer) { |
|
221 |
delegateObservable.addObserver(observer); |
|
222 |
} |
|
223 |
|
|
224 |
@Override |
|
225 |
public void beginComplexNotification() { |
|
226 |
delegateObservable.beginComplexNotification(); |
|
227 |
} |
|
228 |
|
|
229 |
@Override |
|
230 |
public void deleteObserver(Observer observer) { |
|
231 |
delegateObservable.deleteObserver(observer); |
|
232 |
} |
|
233 |
|
|
234 |
@Override |
|
235 |
public void deleteObservers() { |
|
236 |
delegateObservable.deleteObservers(); |
|
237 |
} |
|
238 |
|
Also available in: Unified diff