Revision 31824
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/README.txt | ||
---|---|---|
1 |
The project structure of this project is the following: |
|
2 |
|
|
3 |
Project |
|
4 |
|-pom.xml: Maven 2 configuration file. |
|
5 |
`-src |
|
6 |
|-main: Project source code, resources and configuration |
|
7 |
| |-java: Java source code |
|
8 |
| |-resources: Resources needed by the code (resource bundles, images, etc.) |
|
9 |
|`-javadoc: Javadoc common resources |
|
10 |
`-test: Unit tests source code, resources and configuration |
|
11 |
|-java: Unit tests java source code |
|
12 |
`-resources: Resources needed by the test code (resource bundles, images, etc.) |
|
13 |
|
|
14 |
Look at the main folders for a README.txt file with more information on the |
|
15 |
contents of each folder. |
|
0 | 16 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/test/java/org/gvsig/fmap/dal/store/memory/MemoryStoreProviderCacheTest.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 2 |
|
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, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.store.memory; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
|
|
32 |
import org.gvsig.fmap.dal.DALLocator; |
|
33 |
import org.gvsig.fmap.dal.DataManager; |
|
34 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
35 |
import org.gvsig.fmap.dal.DataTypes; |
|
36 |
import org.gvsig.fmap.dal.exception.DataException; |
|
37 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
38 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
39 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
40 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
|
41 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
42 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
43 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
44 |
import org.gvsig.fmap.dal.feature.Feature; |
|
45 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
46 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
47 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
48 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreParameters; |
|
49 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreProvider; |
|
50 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
51 |
import org.gvsig.fmap.geom.GeometryManager; |
|
52 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
53 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
54 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
55 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
56 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
57 |
import org.slf4j.Logger; |
|
58 |
import org.slf4j.LoggerFactory; |
|
59 |
|
|
60 |
/** |
|
61 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
62 |
*/ |
|
63 |
public class MemoryStoreProviderCacheTest extends org.gvsig.fmap.dal.store.memory.MemoryStoreProviderTest { |
|
64 |
private Logger logger = LoggerFactory.getLogger(getClass());; |
|
65 |
|
|
66 |
protected FeatureStore createEditableFeatureStore() throws ValidateDataParametersException, InitializeException, ProviderNotRegisteredException, DataException{ |
|
67 |
FeatureStore store = (FeatureStore) dataManager.createStore(this |
|
68 |
.getDefaultDataStoreParameters()); |
|
69 |
|
|
70 |
store.edit(); |
|
71 |
|
|
72 |
EditableFeatureType editableFeatureType = store.getDefaultFeatureType().getEditable(); |
|
73 |
|
|
74 |
editableFeatureType.add(ID, DataTypes.OBJECT).setObjectClass(Object.class); |
|
75 |
EditableFeatureAttributeDescriptor geometryDescriptor = |
|
76 |
editableFeatureType.add(GEOM, DataTypes.GEOMETRY); |
|
77 |
geometryDescriptor.setGeometryType(TYPES.GEOMETRY); |
|
78 |
editableFeatureType.setDefaultGeometryAttributeName(GEOM); |
|
79 |
|
|
80 |
editableFeatureType.add(IDSYM, DataTypes.OBJECT).setObjectClass(Object.class); |
|
81 |
editableFeatureType.add(LABEL, DataTypes.STRING); |
|
82 |
EditableFeatureAttributeDescriptor featureIdDescriptor = |
|
83 |
editableFeatureType.add(FEATUREID, DataTypes.OBJECT).setObjectClass(Object.class); |
|
84 |
featureIdDescriptor.setIsPrimaryKey(true); |
|
85 |
editableFeatureType.setHasOID(true); |
|
86 |
|
|
87 |
store.update(editableFeatureType); |
|
88 |
store.finishEditing(); |
|
89 |
return store; |
|
90 |
} |
|
91 |
|
|
92 |
public void testEdition() throws ValidateDataParametersException, InitializeException, ProviderNotRegisteredException, DataException, CreateGeometryException{ |
|
93 |
FeatureStore store = createEditableFeatureStore(); |
|
94 |
|
|
95 |
store.edit(); |
|
96 |
|
|
97 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
98 |
feature.set(ID, "0"); |
|
99 |
feature.set(GEOM, geomManager.createPoint(0, 0, SUBTYPES.GEOM2D)); |
|
100 |
|
|
101 |
store.insert(feature); |
|
102 |
store.finishEditing(); |
|
103 |
|
|
104 |
store.edit(); |
|
105 |
DisposableIterator it = store.getFeatureSet().fastIterator(); |
|
106 |
ArrayList features = new ArrayList(); |
|
107 |
while (it.hasNext()){ |
|
108 |
features.add(it.next()); |
|
109 |
} |
|
110 |
|
|
111 |
for (int i=0 ; i<features.size() ; i++){ |
|
112 |
store.delete((Feature)features.get(i)); |
|
113 |
} |
|
114 |
|
|
115 |
store.finishEditing(); |
|
116 |
|
|
117 |
assertEquals(0, store.getFeatureCount()); |
|
118 |
|
|
119 |
} |
|
120 |
|
|
121 |
|
|
122 |
} |
|
123 |
|
|
0 | 124 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/test/java/org/gvsig/fmap/dal/cache/AbstractFeatureCacheProviderTest.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 2 |
|
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, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.cache; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.DALLocator; |
|
31 |
import org.gvsig.fmap.dal.DataManager; |
|
32 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureCache; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
37 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider; |
|
38 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
39 |
import org.gvsig.fmap.dal.store.shp.SHPLibrary; |
|
40 |
import org.gvsig.fmap.dal.store.wfs.WFSLibrary; |
|
41 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
42 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
43 |
|
|
44 |
/** |
|
45 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
46 |
*/ |
|
47 |
public abstract class AbstractFeatureCacheProviderTest extends AbstractLibraryAutoInitTestCase{ |
|
48 |
protected DataManagerProviderServices dataManager; |
|
49 |
protected FeatureStore store0; |
|
50 |
protected FeatureStore store1; |
|
51 |
|
|
52 |
protected void doSetUp() throws Exception { |
|
53 |
new SHPLibrary().postInitialize(); |
|
54 |
new WFSLibrary().postInitialize(); |
|
55 |
|
|
56 |
dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
|
57 |
} |
|
58 |
|
|
59 |
protected abstract FeatureStore createStore1() throws Exception; |
|
60 |
|
|
61 |
protected abstract FeatureStore createStore2() throws Exception;; |
|
62 |
|
|
63 |
public void testCreateProvider() throws DataException{ |
|
64 |
FeatureCacheProvider cacheProvider = |
|
65 |
dataManager.createFeatureCacheProvider(getCacheProviderName(), |
|
66 |
getParameters()); |
|
67 |
|
|
68 |
assertNotNull(cacheProvider); |
|
69 |
} |
|
70 |
|
|
71 |
public void testCreateCache() throws Exception{ |
|
72 |
store0 = createStore1(); |
|
73 |
|
|
74 |
store0.createCache(getCacheProviderName(), |
|
75 |
getParameters()); |
|
76 |
|
|
77 |
FeatureCache cache = store0.getCache(); |
|
78 |
|
|
79 |
|
|
80 |
assertNotNull(cache); |
|
81 |
|
|
82 |
store0.dispose(); |
|
83 |
} |
|
84 |
|
|
85 |
public void testNumberOfFeatures() throws Exception{ |
|
86 |
store0 = createStore1(); |
|
87 |
|
|
88 |
long featureNumber = store0.getFeatureCount(); |
|
89 |
FeatureSet featureSet = store0.getFeatureSet(); |
|
90 |
Envelope envelope = store0.getEnvelope(); |
|
91 |
|
|
92 |
store0.createCache(getCacheProviderName(), |
|
93 |
getParameters()); |
|
94 |
FeatureCache cache = store0.getCache(); |
|
95 |
cache.addAllFeatures(featureSet, envelope, 0); |
|
96 |
|
|
97 |
assertEquals(featureNumber, store0.getFeatureCount()); |
|
98 |
store0.dispose(); |
|
99 |
} |
|
100 |
|
|
101 |
public void testAddFeatures() throws Exception{ |
|
102 |
store0 = createStore1(); |
|
103 |
store1 = createStore2(); |
|
104 |
|
|
105 |
long featureNumber = store0.getFeatureCount(); |
|
106 |
featureNumber = featureNumber + store1.getFeatureCount(); |
|
107 |
|
|
108 |
FeatureSet featureSet = store0.getFeatureSet(); |
|
109 |
Envelope envelope = store0.getEnvelope(); |
|
110 |
|
|
111 |
store0.createCache(getCacheProviderName(), |
|
112 |
getParameters()); |
|
113 |
FeatureCache cache = store0.getCache(); |
|
114 |
cache.addAllFeatures(featureSet, envelope, 0); |
|
115 |
|
|
116 |
cache.addAllFeatures(store1.getFeatureSet(), |
|
117 |
store1.getEnvelope(), |
|
118 |
0); |
|
119 |
|
|
120 |
assertEquals(featureNumber, store0.getFeatureCount()); |
|
121 |
featureSet.dispose(); |
|
122 |
store0.dispose(); |
|
123 |
store1.dispose(); |
|
124 |
} |
|
125 |
|
|
126 |
|
|
127 |
protected abstract DataServerExplorerParameters getParameters() throws DataException; |
|
128 |
|
|
129 |
protected abstract String getCacheProviderName(); |
|
130 |
|
|
131 |
} |
|
132 |
|
|
0 | 133 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/test/java/org/gvsig/fmap/dal/cache/shp/FeatureCacheShapeProviderFromWFSTest.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.cache.shp; |
|
2 |
|
|
3 |
import org.gvsig.fmap.crs.CRSFactory; |
|
4 |
import org.gvsig.fmap.dal.exception.DataException; |
|
5 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
6 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
7 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
8 |
import org.gvsig.fmap.dal.store.wfs.WFSStoreParameters; |
|
9 |
import org.gvsig.fmap.dal.store.wfs.WFSStoreProvider; |
|
10 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
11 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
12 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
13 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
14 |
import org.gvsig.fmap.mapcontext.layers.vectorial.IntersectsEnvelopeEvaluator; |
|
15 |
import org.gvsig.tools.evaluator.Evaluator; |
|
16 |
import org.gvsig.tools.locator.LocatorException; |
|
17 |
|
|
18 |
public class FeatureCacheShapeProviderFromWFSTest extends FeatureCacheShapeProviderTest{ |
|
19 |
private String url = "http://fuenlabrada.iver.es/geoserver-test/wfs"; |
|
20 |
|
|
21 |
private String version = "1.1.0"; |
|
22 |
private String featureType = "fuenlabrada:pois"; |
|
23 |
private String namespace = "http://fuenlabrada.iver.es"; |
|
24 |
private String namespacePrefix = "fuenlabrada"; |
|
25 |
|
|
26 |
|
|
27 |
@Override |
|
28 |
protected FeatureStore createStore1() throws Exception { |
|
29 |
WFSStoreParameters parameters = null; |
|
30 |
|
|
31 |
parameters = (WFSStoreParameters) dataManager |
|
32 |
.createStoreParameters(WFSStoreProvider.NAME); |
|
33 |
|
|
34 |
parameters.setUrl(url); |
|
35 |
parameters.setFeatureType(namespacePrefix, |
|
36 |
namespace, |
|
37 |
featureType); |
|
38 |
parameters.setVersion(version); |
|
39 |
return (FeatureStore)dataManager.createStore(parameters); |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
protected FeatureStore createStore2() throws Exception { |
|
44 |
WFSStoreParameters parameters = null; |
|
45 |
|
|
46 |
parameters = (WFSStoreParameters) dataManager |
|
47 |
.createStoreParameters(WFSStoreProvider.NAME); |
|
48 |
|
|
49 |
parameters.setUrl(url); |
|
50 |
parameters.setFeatureType(namespacePrefix, |
|
51 |
namespace, |
|
52 |
featureType); |
|
53 |
parameters.setVersion(version); |
|
54 |
return (FeatureStore)dataManager.createStore(parameters); |
|
55 |
} |
|
56 |
|
|
57 |
public void testFilterByArea() throws Exception{ |
|
58 |
store0 = createStore1(); |
|
59 |
store0.createCache(getCacheProviderName(), |
|
60 |
getParameters()); |
|
61 |
|
|
62 |
Envelope envelope = GeometryLocator.getGeometryManager().createEnvelope( |
|
63 |
420000, 4450000, 445000, 4470000, SUBTYPES.GEOM2D); |
|
64 |
|
|
65 |
Evaluator evaluator = new IntersectsEnvelopeEvaluator(envelope, |
|
66 |
CRSFactory.getCRS("EPSG:23030"), store0.getDefaultFeatureType(), "the_geom"); |
|
67 |
|
|
68 |
FeatureQuery featureQuery = store0.createFeatureQuery(); |
|
69 |
featureQuery.setFilter(evaluator); |
|
70 |
|
|
71 |
FeatureSet featureSet = store0.getFeatureSet(featureQuery); |
|
72 |
assertEquals(18, store0.getFeatureCount()); |
|
73 |
store0.dispose(); |
|
74 |
} |
|
75 |
|
|
76 |
} |
|
77 |
|
|
78 |
|
|
0 | 79 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/test/java/org/gvsig/fmap/dal/cache/shp/FeatureCacheShapeProviderFromShapeTest.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 2 |
|
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, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.cache.shp; |
|
29 |
|
|
30 |
import org.gvsig.fmap.crs.CRSFactory; |
|
31 |
import org.gvsig.fmap.dal.cache.AbstractFeatureCacheProviderTest; |
|
32 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
33 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
34 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters; |
|
37 |
|
|
38 |
/** |
|
39 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
40 |
*/ |
|
41 |
public class FeatureCacheShapeProviderFromShapeTest extends FeatureCacheShapeProviderTest{ |
|
42 |
|
|
43 |
|
|
44 |
@Override |
|
45 |
protected FeatureStore createStore1() throws Exception { |
|
46 |
return createStore(AbstractFeatureCacheProviderTest.class.getResource("data/points0.shp").getFile()); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
protected FeatureStore createStore2() throws Exception{ |
|
51 |
return createStore(AbstractFeatureCacheProviderTest.class.getResource("data/points1.shp").getFile()); |
|
52 |
} |
|
53 |
|
|
54 |
private FeatureStore createStore(String fileName) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException{ |
|
55 |
SHPStoreParameters parameters = (SHPStoreParameters)dataManager.createStoreParameters("Shape"); |
|
56 |
parameters.setSHPFileName(fileName); |
|
57 |
parameters.setDynValue("srs", CRSFactory.getCRS("EPSG:23030")); |
|
58 |
return (FeatureStore)dataManager.createStore(parameters); |
|
59 |
} |
|
60 |
|
|
61 |
} |
|
62 |
|
|
0 | 63 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/test/java/org/gvsig/fmap/dal/cache/shp/FeatureCacheShapeProviderTest.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 2 |
|
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, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.cache.shp; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
31 |
import org.gvsig.fmap.dal.cache.AbstractFeatureCacheProviderTest; |
|
32 |
import org.gvsig.fmap.dal.exception.DataException; |
|
33 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
|
34 |
|
|
35 |
/** |
|
36 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
37 |
*/ |
|
38 |
public abstract class FeatureCacheShapeProviderTest extends AbstractFeatureCacheProviderTest{ |
|
39 |
|
|
40 |
@Override |
|
41 |
protected String getCacheProviderName() { |
|
42 |
return FeatureCacheShapeProvider.NAME; |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
protected DataServerExplorerParameters getParameters() throws DataException { |
|
47 |
FilesystemServerExplorerParameters eparams = (FilesystemServerExplorerParameters)dataManager.createServerExplorerParameters("FilesystemExplorer"); |
|
48 |
eparams.setRoot(AbstractFeatureCacheProviderTest.class.getResource("data").getFile()); |
|
49 |
return eparams; |
|
50 |
} |
|
51 |
|
|
52 |
} |
|
53 |
|
|
0 | 54 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/test/java/README.txt | ||
---|---|---|
1 |
#set( $symbol_pound = '#' ) |
|
2 |
#set( $symbol_dollar = '$' ) |
|
3 |
#set( $symbol_escape = '\' ) |
|
4 |
For each class you are going to test, create one Test class with the same |
|
5 |
name as the class to test, ending with Test. |
|
6 |
|
|
7 |
For example, the unit tests of the "ExampleLibrary" class are performed |
|
8 |
by the "ExampleLibraryTest" class. |
|
0 | 9 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/test/resources/README.txt | ||
---|---|---|
1 |
#set( $symbol_pound = '#' ) |
|
2 |
#set( $symbol_dollar = '$' ) |
|
3 |
#set( $symbol_escape = '\' ) |
|
4 |
Put into this folder the resources needed by your test classes. |
|
5 |
|
|
6 |
This folder is added to the Tests classpath, so you can load any resources |
|
7 |
through the ClassLoader. |
|
8 |
|
|
9 |
By default, in this folder you can find an example of log4j configuration, |
|
10 |
prepared to log messages through the console, so logging works when you |
|
11 |
run your tests classes. |
|
0 | 12 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<!-- |
|
5 |
Log4J configuration file for unit tests execution. |
|
6 |
--> |
|
7 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
8 |
|
|
9 |
<!-- Appender configuration to show logging messages through the console --> |
|
10 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
11 |
<layout class="org.apache.log4j.PatternLayout"> |
|
12 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
13 |
</layout> |
|
14 |
</appender> |
|
15 |
|
|
16 |
<!-- |
|
17 |
Activate logging messages of DEBUG level of higher only for the |
|
18 |
DefaultExampleManager class. |
|
19 |
You can put full classes names or packages instead, to configure |
|
20 |
logging for all the classes and subpackages of the package. |
|
21 |
--> |
|
22 |
<category name="org.gvsig.fmap.dal.cache.impl.DefaultExampleManager"> |
|
23 |
<priority value="DEBUG" /> |
|
24 |
</category> |
|
25 |
|
|
26 |
<!-- |
|
27 |
By default, show only logging messages of INFO level or higher, |
|
28 |
through the previously configured CONSOLE appender. |
|
29 |
--> |
|
30 |
<root> |
|
31 |
<priority value="INFO" /> |
|
32 |
<appender-ref ref="CONSOLE" /> |
|
33 |
</root> |
|
34 |
</log4j:configuration> |
|
0 | 35 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/main/java/org/gvsig/fmap/dal/cache/CacheFeatureSet.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 2 |
|
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, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.cache; |
|
29 |
|
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import org.gvsig.fmap.dal.DataStore; |
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
|
34 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
|
35 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
36 |
import org.gvsig.fmap.dal.feature.Feature; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
39 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
40 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
|
41 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
42 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
|
43 |
import org.gvsig.tools.exception.BaseException; |
|
44 |
import org.gvsig.tools.visitor.Visitor; |
|
45 |
|
|
46 |
/** |
|
47 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
48 |
*/ |
|
49 |
public class CacheFeatureSet implements FeatureSet{ |
|
50 |
private FeatureSetProvider featureSetProvider = null; |
|
51 |
private FeatureStore store = null; |
|
52 |
|
|
53 |
public CacheFeatureSet(FeatureStore store, FeatureSetProvider featureSetProvider) { |
|
54 |
this.featureSetProvider = featureSetProvider; |
|
55 |
this.store = store; |
|
56 |
} |
|
57 |
|
|
58 |
public void delete(Feature feature) throws DataException { |
|
59 |
// TODO Auto-generated method stub |
|
60 |
|
|
61 |
} |
|
62 |
|
|
63 |
public DisposableIterator fastIterator() throws DataException { |
|
64 |
return new CacheFeatureSetIterator(featureSetProvider.fastIterator()); |
|
65 |
} |
|
66 |
|
|
67 |
public DisposableIterator fastIterator(long index) throws DataException { |
|
68 |
return new CacheFeatureSetIterator(featureSetProvider.fastIterator(index)); |
|
69 |
} |
|
70 |
|
|
71 |
public FeatureType getDefaultFeatureType() { |
|
72 |
// TODO Auto-generated method stub |
|
73 |
return null; |
|
74 |
} |
|
75 |
|
|
76 |
public List getFeatureTypes() { |
|
77 |
// TODO Auto-generated method stub |
|
78 |
return null; |
|
79 |
} |
|
80 |
|
|
81 |
public long getSize() throws DataException { |
|
82 |
// TODO Auto-generated method stub |
|
83 |
return 0; |
|
84 |
} |
|
85 |
|
|
86 |
public void insert(EditableFeature feature) throws DataException { |
|
87 |
// TODO Auto-generated method stub |
|
88 |
|
|
89 |
} |
|
90 |
|
|
91 |
public boolean isEmpty() throws DataException { |
|
92 |
// TODO Auto-generated method stub |
|
93 |
return false; |
|
94 |
} |
|
95 |
|
|
96 |
public DisposableIterator iterator(long index) throws DataException { |
|
97 |
return new CacheFeatureSetIterator(featureSetProvider.fastIterator(index)); |
|
98 |
} |
|
99 |
|
|
100 |
public DisposableIterator iterator() throws DataException { |
|
101 |
return new CacheFeatureSetIterator(featureSetProvider.fastIterator()); |
|
102 |
} |
|
103 |
|
|
104 |
public void update(EditableFeature feature) throws DataException { |
|
105 |
// TODO Auto-generated method stub |
|
106 |
|
|
107 |
} |
|
108 |
|
|
109 |
public void dispose() { |
|
110 |
// TODO Auto-generated method stub |
|
111 |
|
|
112 |
} |
|
113 |
|
|
114 |
public boolean isFromStore(DataStore store) { |
|
115 |
// TODO Auto-generated method stub |
|
116 |
return false; |
|
117 |
} |
|
118 |
|
|
119 |
public void accept(Visitor visitor) throws BaseException { |
|
120 |
// TODO Auto-generated method stub |
|
121 |
|
|
122 |
} |
|
123 |
|
|
124 |
public void accept(Visitor visitor, long firstValueIndex) |
|
125 |
throws BaseException { |
|
126 |
// TODO Auto-generated method stub |
|
127 |
|
|
128 |
} |
|
129 |
|
|
130 |
protected class CacheFeatureSetIterator implements DisposableIterator { |
|
131 |
protected DisposableIterator iterator; |
|
132 |
|
|
133 |
public CacheFeatureSetIterator(DisposableIterator iterator) throws DataException { |
|
134 |
this.iterator = iterator; |
|
135 |
} |
|
136 |
|
|
137 |
public void dispose() { |
|
138 |
// TODO Auto-generated method stub |
|
139 |
|
|
140 |
} |
|
141 |
|
|
142 |
public boolean hasNext() { |
|
143 |
return iterator.hasNext(); |
|
144 |
} |
|
145 |
|
|
146 |
public Object next() { |
|
147 |
return new DefaultFeature(store, (FeatureProvider)iterator.next()); |
|
148 |
} |
|
149 |
|
|
150 |
public void remove() { |
|
151 |
// TODO Auto-generated method stub |
|
152 |
} |
|
153 |
|
|
154 |
} |
|
155 |
|
|
156 |
} |
|
157 |
|
|
0 | 158 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/main/java/org/gvsig/fmap/dal/cache/envelope/EnvelopeManager.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 2 |
|
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, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.cache.envelope; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.feature.exception.CreateGeometryException; |
|
31 |
import org.gvsig.fmap.geom.Geometry; |
|
32 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
33 |
|
|
34 |
/** |
|
35 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
36 |
*/ |
|
37 |
public interface EnvelopeManager { |
|
38 |
|
|
39 |
public void addEnvelope(Envelope envelope); |
|
40 |
|
|
41 |
public void delete(); |
|
42 |
|
|
43 |
public boolean contains(Envelope envelope); |
|
44 |
|
|
45 |
public Geometry intersection(Envelope envelope) throws CreateGeometryException; |
|
46 |
|
|
47 |
public Geometry difference(Envelope envelope) throws CreateGeometryException; |
|
48 |
|
|
49 |
public Geometry getCachedArea() throws CreateGeometryException; |
|
50 |
} |
|
51 |
|
|
52 |
|
|
0 | 53 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/main/java/org/gvsig/fmap/dal/cache/envelope/DefaultEnvelopeManager.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 2 |
|
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, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.cache.envelope; |
|
29 |
|
|
30 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
31 |
import org.gvsig.fmap.geom.GeometryManager; |
|
32 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
33 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
34 |
import org.gvsig.fmap.geom.util.Converter; |
|
35 |
|
|
36 |
import com.vividsolutions.jts.geom.Coordinate; |
|
37 |
import com.vividsolutions.jts.geom.Geometry; |
|
38 |
import com.vividsolutions.jts.geom.LinearRing; |
|
39 |
import com.vividsolutions.jts.geom.MultiPolygon; |
|
40 |
import com.vividsolutions.jts.geom.Polygon; |
|
41 |
import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence; |
|
42 |
/** |
|
43 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
44 |
*/ |
|
45 |
public class DefaultEnvelopeManager implements EnvelopeManager{ |
|
46 |
private GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
47 |
private final static com.vividsolutions.jts.geom.GeometryFactory geomFactory = |
|
48 |
new com.vividsolutions.jts.geom.GeometryFactory(); |
|
49 |
com.vividsolutions.jts.geom.MultiPolygon currentArea = null; |
|
50 |
|
|
51 |
public DefaultEnvelopeManager() { |
|
52 |
super(); |
|
53 |
} |
|
54 |
|
|
55 |
/* (non-Javadoc) |
|
56 |
* @see org.gvsig.cache.vectorial.envelope.EnvelopeManager#addEnvelope(org.gvsig.fmap.geom.primitive.Envelope) |
|
57 |
*/ |
|
58 |
public void addEnvelope(Envelope envelope) { |
|
59 |
if (currentArea == null){ |
|
60 |
currentArea = toJTS(envelope); |
|
61 |
}else{ |
|
62 |
Geometry geom = currentArea.union(toJTS(envelope)); |
|
63 |
if(geom instanceof Polygon) |
|
64 |
currentArea = new MultiPolygon(new Polygon[] {(Polygon)geom},geomFactory); |
|
65 |
else { |
|
66 |
currentArea = (MultiPolygon)geom; |
|
67 |
} |
|
68 |
// currentArea = (com.vividsolutions.jts.geom.MultiPolygon)currentArea.union(toJTS(envelope)); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
private void initialize(){ |
|
73 |
Polygon polygon = new com.vividsolutions.jts.geom.Polygon(new LinearRing(new PackedCoordinateSequence.Double(new Coordinate[0]), |
|
74 |
geomFactory), |
|
75 |
new LinearRing[0], geomFactory); |
|
76 |
currentArea = new MultiPolygon(new Polygon[] {polygon},geomFactory); |
|
77 |
} |
|
78 |
|
|
79 |
private com.vividsolutions.jts.geom.MultiPolygon toJTS(Envelope envelope){ |
|
80 |
return toJTS(envelope.getMinimum(0), |
|
81 |
envelope.getMinimum(1), |
|
82 |
envelope.getMaximum(0), |
|
83 |
envelope.getMaximum(1)); |
|
84 |
} |
|
85 |
|
|
86 |
private com.vividsolutions.jts.geom.MultiPolygon toEnvelope(com.vividsolutions.jts.geom.Envelope envelope){ |
|
87 |
return toJTS(envelope.getMinX(), |
|
88 |
envelope.getMinY(), |
|
89 |
envelope.getMaxX(), |
|
90 |
envelope.getMaxY()); |
|
91 |
} |
|
92 |
|
|
93 |
private com.vividsolutions.jts.geom.MultiPolygon toJTS(double minX, double minY, double maxX, double maxY){ |
|
94 |
Coordinate[] coordinates = new Coordinate[5]; |
|
95 |
coordinates[0] = new Coordinate(minX, minY); |
|
96 |
coordinates[1] = new Coordinate(minX, maxY); |
|
97 |
coordinates[2] = new Coordinate(maxX, maxY); |
|
98 |
coordinates[3] = new Coordinate(maxX, minY); |
|
99 |
coordinates[4] = new Coordinate(minX, minY); |
|
100 |
Polygon polygon = new com.vividsolutions.jts.geom.Polygon(new LinearRing(new PackedCoordinateSequence.Double(coordinates), |
|
101 |
geomFactory), |
|
102 |
new LinearRing[0], geomFactory); |
|
103 |
return new MultiPolygon(new Polygon[] {polygon},geomFactory); |
|
104 |
} |
|
105 |
|
|
106 |
/* (non-Javadoc) |
|
107 |
* @see org.gvsig.fmap.dal.feature.EnvelopeManager#contains(org.gvsig.fmap.geom.primitive.Envelope) |
|
108 |
*/ |
|
109 |
public boolean contains(Envelope envelope) { |
|
110 |
if (currentArea == null){ |
|
111 |
initialize(); |
|
112 |
} |
|
113 |
return currentArea.contains(toJTS(envelope)); |
|
114 |
} |
|
115 |
|
|
116 |
/* (non-Javadoc) |
|
117 |
* @see org.gvsig.fmap.dal.feature.EnvelopeManager#delete() |
|
118 |
*/ |
|
119 |
public void delete() { |
|
120 |
initialize(); |
|
121 |
} |
|
122 |
|
|
123 |
/* (non-Javadoc) |
|
124 |
* @see org.gvsig.fmap.dal.feature.EnvelopeManager#getCachedArea() |
|
125 |
*/ |
|
126 |
public org.gvsig.fmap.geom.Geometry getCachedArea() throws org.gvsig.fmap.dal.feature.exception.CreateGeometryException { |
|
127 |
if (currentArea == null){ |
|
128 |
initialize(); |
|
129 |
} |
|
130 |
try { |
|
131 |
return Converter.jtsToGeometry(currentArea); |
|
132 |
} catch (CreateGeometryException e) { |
|
133 |
throw new org.gvsig.fmap.dal.feature.exception.CreateGeometryException(e); |
|
134 |
} |
|
135 |
|
|
136 |
} |
|
137 |
|
|
138 |
/* |
|
139 |
* (non-Javadoc) |
|
140 |
* @see org.gvsig.fmap.dal.feature.EnvelopeManager#intersection(org.gvsig.fmap.geom.primitive.Envelope) |
|
141 |
*/ |
|
142 |
public org.gvsig.fmap.geom.Geometry intersection(Envelope envelope) throws org.gvsig.fmap.dal.feature.exception.CreateGeometryException { |
|
143 |
if (currentArea == null){ |
|
144 |
initialize(); |
|
145 |
} |
|
146 |
Geometry intersection = currentArea.intersection(toJTS(envelope)); |
|
147 |
try { |
|
148 |
return Converter.jtsToGeometry(intersection); |
|
149 |
} catch (CreateGeometryException e) { |
|
150 |
throw new org.gvsig.fmap.dal.feature.exception.CreateGeometryException(e); |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
/* |
|
155 |
* (non-Javadoc) |
|
156 |
* @see org.gvsig.fmap.dal.feature.EnvelopeManager#difference(org.gvsig.fmap.geom.primitive.Envelope) |
|
157 |
*/ |
|
158 |
public org.gvsig.fmap.geom.Geometry difference(Envelope envelope) throws org.gvsig.fmap.dal.feature.exception.CreateGeometryException { |
|
159 |
if (currentArea == null){ |
|
160 |
initialize(); |
|
161 |
} |
|
162 |
Geometry difference = toJTS(envelope).difference(currentArea); |
|
163 |
try{ |
|
164 |
return Converter.jtsToGeometry(difference); |
|
165 |
} catch (CreateGeometryException e) { |
|
166 |
throw new org.gvsig.fmap.dal.feature.exception.CreateGeometryException(e); |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
170 |
} |
|
171 |
|
|
172 |
|
|
173 |
|
|
0 | 174 |
branches/v2_0_0_prep/libraries/org.gvsig.fmap.dal.cache/src/main/java/org/gvsig/fmap/dal/cache/AbstractFeatureCacheProvider.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 2 |
|
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, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.cache; |
|
29 |
|
|
30 |
import java.util.HashMap; |
|
31 |
import java.util.Iterator; |
|
32 |
|
|
33 |
import org.cresques.cts.IProjection; |
|
34 |
import org.gvsig.fmap.dal.DALLocator; |
|
35 |
import org.gvsig.fmap.dal.DataManager; |
|
36 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
37 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
38 |
import org.gvsig.fmap.dal.cache.envelope.DefaultEnvelopeManager; |
|
39 |
import org.gvsig.fmap.dal.cache.envelope.EnvelopeManager; |
|
40 |
import org.gvsig.fmap.dal.exception.CloseException; |
|
41 |
import org.gvsig.fmap.dal.exception.CreateException; |
|
42 |
import org.gvsig.fmap.dal.exception.DataException; |
|
43 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
44 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
45 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
46 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
47 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
|
48 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
49 |
import org.gvsig.fmap.dal.feature.Feature; |
|
50 |
import org.gvsig.fmap.dal.feature.FeatureLocks; |
|
51 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
52 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
53 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
54 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
55 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
56 |
import org.gvsig.fmap.dal.feature.exception.CreateGeometryException; |
|
57 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
58 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
|
59 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
|
60 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
|
61 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
|
62 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider; |
|
63 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
64 |
import org.gvsig.fmap.geom.Geometry; |
|
65 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
66 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
67 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
68 |
import org.gvsig.fmap.mapcontext.layers.vectorial.IntersectsEnvelopeEvaluator; |
|
69 |
import org.gvsig.fmap.mapcontext.layers.vectorial.IntersectsGeometryEvaluator; |
|
70 |
import org.gvsig.tools.dynobject.DynClass; |
|
71 |
import org.gvsig.tools.dynobject.DynObject; |
|
72 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
|
73 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
|
74 |
import org.gvsig.tools.evaluator.Evaluator; |
|
75 |
import org.gvsig.tools.evaluator.EvaluatorFieldValue; |
|
76 |
import org.gvsig.tools.evaluator.EvaluatorFieldValueMatch; |
|
77 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
|
78 |
import org.gvsig.tools.locator.LocatorException; |
|
79 |
|
|
80 |
/** |
|
81 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
82 |
*/ |
|
83 |
public abstract class AbstractFeatureCacheProvider implements FeatureCacheProvider{ |
|
84 |
protected DataServerExplorer dataServerExplorer = null; |
|
85 |
protected static final DataManager dataManager = DALLocator.getDataManager(); |
|
86 |
protected FeatureStoreProviderServices featureStoreProviderServices = null; |
|
87 |
protected FeatureStoreProvider featureStoreProvider = null; |
|
88 |
private Envelope fullenvelope = null; |
|
89 |
|
|
90 |
protected IProjection sourceProjection = null; |
|
91 |
protected FeatureType sourceFeatureType = null; |
|
92 |
|
|
93 |
//A list of FeatureStores indexed by scale |
|
94 |
protected HashMap featureStores = null; |
|
95 |
|
|
96 |
//A list of EnvelopeManager indexed by scale |
|
97 |
protected HashMap envelopeManagers = null; |
|
98 |
|
|
99 |
public AbstractFeatureCacheProvider() { |
|
100 |
super(); |
|
101 |
this.featureStores = new HashMap(); |
|
102 |
this.envelopeManagers = new HashMap(); |
|
103 |
} |
|
104 |
|
|
105 |
public void apply( |
|
106 |
FeatureStoreProviderServices featureStoreProviderServices, |
|
107 |
FeatureStoreProvider featureStoreProvider) throws DataException { |
|
108 |
this.featureStoreProvider = featureStoreProvider; |
|
109 |
this.featureStoreProviderServices = featureStoreProviderServices; |
|
110 |
|
|
111 |
this.sourceFeatureType = featureStoreProviderServices.getDefaultFeatureType(); |
|
112 |
this.sourceProjection = sourceFeatureType.getDefaultGeometryAttribute().getSRS(); |
|
113 |
|
|
114 |
try { |
|
115 |
fullenvelope = GeometryLocator.getGeometryManager().createEnvelope(-10000000, -10000000, |
|
116 |
10000000, 10000000, SUBTYPES.GEOM2D); |
|
117 |
} catch (Exception e) { |
|
118 |
throw new CreateGeometryException(e); |
|
119 |
} |
|
120 |
|
|
121 |
// FeatureStore featureStore = featureStoreProviderServices.getFeatureStore(); |
|
122 |
// addAllFeatures(featureStore.getFeatureSet(), featureStore.getEnvelope(), 0); |
|
123 |
} |
|
124 |
|
|
125 |
public void initialize(DataServerExplorerParameters parameters) throws DataException { |
|
126 |
try{ |
|
127 |
dataServerExplorer = dataManager.createServerExplorer(parameters); |
|
128 |
if (!dataServerExplorer.canAdd()){ |
|
129 |
throw new CreateException("The server explorer doesn't allow to add data stores", null); |
|
130 |
} |
|
131 |
} catch (Exception e) { |
|
132 |
throw new CreateException("Error creating the server explorer", e); |
|
133 |
} |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Gets an envelope manager by scale. |
|
138 |
* @param scale |
|
139 |
* @return |
|
140 |
*/ |
|
141 |
private EnvelopeManager getEnvelopeManager(double scale){ |
|
142 |
Double iScale = new Double(scale); |
|
143 |
if (envelopeManagers.containsKey(iScale)){ |
|
144 |
return (EnvelopeManager)envelopeManagers.get(iScale); |
|
145 |
} |
|
146 |
EnvelopeManager envelopeManager = new DefaultEnvelopeManager(); |
|
147 |
envelopeManagers.put(iScale, envelopeManager); |
|
148 |
return envelopeManager; |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* Gets a feature store by scale. If it not exists, it creates |
|
153 |
* one using the {@link FeatureStoreProvider}. |
|
154 |
* @param scale |
|
155 |
* @return |
|
156 |
* @throws ValidateDataParametersException |
|
157 |
* @throws LocatorException |
|
158 |
* @throws DataException |
|
159 |
*/ |
|
160 |
private FeatureStore getFeatureStore(double scale) throws DataException{ |
|
161 |
Double iScale = new Double(scale); |
|
162 |
if (featureStores.containsKey(iScale)){ |
|
163 |
return (FeatureStore)featureStores.get(iScale); |
|
164 |
} |
|
165 |
FeatureStore featureStore = createDataStore(scale); |
|
166 |
featureStores.put(iScale, featureStore); |
|
167 |
return featureStore; |
|
168 |
} |
|
169 |
|
|
170 |
public boolean allowAutomaticValues() { |
|
171 |
return false; |
|
172 |
} |
|
173 |
|
|
174 |
public boolean allowWrite() { |
|
175 |
return false; |
|
176 |
} |
|
177 |
|
|
178 |
public void append(FeatureProvider featureProvider) throws DataException { |
|
179 |
// TODO Auto-generated method stub |
|
180 |
|
|
181 |
} |
|
182 |
|
|
183 |
public void beginAppend() throws DataException { |
|
184 |
// TODO Auto-generated method stub |
|
185 |
|
|
186 |
} |
|
187 |
|
|
188 |
public boolean canWriteGeometry(int geometryType, int geometrySubType) |
|
189 |
throws DataException { |
|
190 |
return false; |
|
191 |
} |
|
192 |
|
|
193 |
public FeatureLocks createFeatureLocks() throws DataException { |
|
194 |
return null; |
|
195 |
} |
|
196 |
|
|
197 |
public FeatureProvider createFeatureProvider(FeatureType type) |
|
198 |
throws DataException { |
|
199 |
// TODO Auto-generated method stub |
|
200 |
return null; |
|
201 |
} |
|
202 |
|
|
203 |
public FeatureSelection createFeatureSelection() throws DataException { |
|
204 |
// TODO Auto-generated method stub |
|
205 |
return null; |
|
206 |
} |
|
207 |
|
|
208 |
public Object createNewOID() { |
|
209 |
// TODO Auto-generated method stub |
|
210 |
return null; |
|
211 |
} |
|
212 |
|
|
213 |
public FeatureSetProvider createSet(FeatureQuery query, |
|
214 |
FeatureType featureType) throws DataException { |
|
215 |
double scale = query.getScale(); |
|
216 |
FeatureStore featureStore = getFeatureStore(scale); |
|
217 |
EnvelopeManager envelopeManager = getEnvelopeManager(scale); |
|
218 |
|
|
219 |
//If there is not a filter returns the original set of data |
|
220 |
if ((query == null) || (query.getFilter() == null)){ |
|
221 |
return featureStoreProvider.createSet(query, featureType); |
|
222 |
} |
|
223 |
|
|
224 |
Envelope envelope = null; |
|
225 |
|
|
226 |
EvaluatorFieldsInfo fieldsInfo = query.getFilter().getFieldsInfo(); |
|
227 |
String[] fields = fieldsInfo.getFieldNames(); |
|
228 |
for (int i=0 ; i<fields.length ; i++){ |
|
229 |
EvaluatorFieldValue[] evaluatorFieldValues = fieldsInfo.getFieldValues(fields[i]); |
|
230 |
for (int j=0 ; j<evaluatorFieldValues.length ; j++){ |
|
231 |
if (EvaluatorFieldValue.MATCH == evaluatorFieldValues[j].getType()){ |
|
232 |
EvaluatorFieldValueMatch evaluatorFieldValueMatch = (EvaluatorFieldValueMatch)evaluatorFieldValues[j]; |
|
233 |
Object area = evaluatorFieldValueMatch.getValue(); |
|
234 |
if (area instanceof Envelope){ |
|
235 |
envelope = (Envelope)area; |
|
236 |
}else if (area instanceof Geometry){ |
|
237 |
envelope = ((Geometry)area).getEnvelope(); |
|
238 |
} |
|
239 |
} |
|
240 |
} |
|
241 |
} |
|
242 |
|
|
243 |
//If there is not an envelope returns the original set of data |
|
244 |
if (envelope == null){ |
|
245 |
return featureStoreProvider.createSet(query, featureType); |
|
246 |
} |
|
247 |
|
|
248 |
if (!envelopeManager.contains(envelope)){ |
|
249 |
//Create a query by geometry |
|
250 |
Geometry geometry = envelopeManager.difference(envelope); |
|
251 |
Evaluator evaluator = new IntersectsGeometryEvaluator(geometry, |
|
252 |
sourceProjection, sourceFeatureType, |
|
253 |
sourceFeatureType.getDefaultGeometryAttributeName()); |
|
254 |
FeatureQuery newFeatureQuery = featureStoreProviderServices.getFeatureStore().createFeatureQuery(); |
|
255 |
newFeatureQuery.setFilter(evaluator); |
|
256 |
|
|
257 |
//Retrieve the features from the source |
|
258 |
FeatureSetProvider featureSetProvider = featureStoreProvider.createSet(newFeatureQuery, featureType); |
|
259 |
|
|
260 |
//Update the cache |
|
261 |
addAllFeatures(new CacheFeatureSet(featureStore, featureSetProvider), envelope, scale); |
|
262 |
|
|
263 |
//Update the envelope manager |
|
264 |
envelopeManager.addEnvelope(envelope); |
|
265 |
} |
|
266 |
return new CacheSetProvider(getFeatureSet(envelope, scale)); |
|
267 |
} |
|
268 |
|
|
269 |
/* (non-Javadoc) |
|
270 |
* @see org.gvsig.fmap.dal.feature.FeatureCache#getFeatures(org.gvsig.fmap.geom.primitive.Envelope, double) |
|
271 |
*/ |
|
272 |
public FeatureSet getFeatureSet(Envelope envelope, double scale) throws DataException { |
|
273 |
FeatureStore store = getFeatureStore(scale); |
|
274 |
Evaluator evaluator = new IntersectsEnvelopeEvaluator(envelope, |
|
275 |
sourceProjection, sourceFeatureType, |
|
276 |
sourceFeatureType.getDefaultGeometryAttributeName()); |
|
277 |
|
|
278 |
FeatureQuery featureQuery = store.createFeatureQuery(); |
|
279 |
featureQuery.setFilter(evaluator); |
|
280 |
return store.getFeatureSet(featureQuery); |
|
281 |
} |
|
282 |
|
|
283 |
public void endAppend() throws DataException { |
|
284 |
// TODO Auto-generated method stub |
|
285 |
|
|
286 |
} |
|
287 |
|
|
288 |
public Envelope getEnvelope() throws DataException { |
|
289 |
return fullenvelope; |
|
290 |
} |
|
291 |
|
|
292 |
public long getFeatureCount() throws DataException { |
|
293 |
if (featureStores.size() == 0){ |
|
294 |
return 0; |
|
295 |
} |
|
296 |
//TODO feature count by scale |
|
297 |
Iterator it = featureStores.keySet().iterator(); |
|
298 |
long featureNumber = 0; |
|
299 |
while (it.hasNext()){ |
|
300 |
FeatureStore store = (FeatureStore)featureStores.get(it.next()); |
|
301 |
featureNumber = featureNumber + store.getFeatureCount(); |
|
302 |
} |
|
303 |
return featureNumber; |
|
304 |
} |
|
305 |
|
|
306 |
public FeatureProvider getFeatureProviderByReference( |
|
307 |
FeatureReferenceProviderServices reference) throws DataException { |
|
308 |
// TODO Auto-generated method stub |
|
309 |
return null; |
|
310 |
} |
|
311 |
|
|
312 |
public FeatureProvider getFeatureProviderByReference( |
|
313 |
FeatureReferenceProviderServices reference, FeatureType featureType) |
|
314 |
throws DataException { |
|
315 |
// TODO Auto-generated method stub |
|
316 |
return null; |
|
317 |
} |
|
318 |
|
|
319 |
public String getName() { |
|
320 |
return null; |
|
321 |
} |
|
322 |
|
|
323 |
public int getOIDType() { |
|
324 |
// TODO Auto-generated method stub |
|
325 |
return 0; |
|
326 |
} |
|
327 |
|
|
328 |
public FeatureStoreProviderServices getStoreServices() { |
|
329 |
// TODO Auto-generated method stub |
|
330 |
return null; |
|
331 |
} |
|
332 |
|
|
333 |
public boolean isLocksSupported() { |
|
334 |
// TODO Auto-generated method stub |
|
335 |
return false; |
|
336 |
} |
|
337 |
|
|
338 |
public void performChanges(Iterator deleteds, Iterator inserteds, |
|
339 |
Iterator updateds, Iterator featureTypesChanged) |
|
340 |
throws DataException { |
|
341 |
// TODO Auto-generated method stub |
|
342 |
|
|
343 |
} |
|
344 |
|
|
345 |
public boolean supportsAppendMode() { |
|
346 |
// TODO Auto-generated method stub |
|
347 |
return false; |
|
348 |
} |
|
349 |
|
|
350 |
public void close() throws CloseException { |
|
351 |
// TODO Auto-generated method stub |
|
352 |
|
|
353 |
} |
|
354 |
|
|
355 |
public void dispose() { |
|
356 |
// TODO Auto-generated method stub |
|
357 |
|
|
358 |
} |
|
359 |
|
|
360 |
public Iterator getChilds() { |
|
361 |
// TODO Auto-generated method stub |
|
362 |
return null; |
|
363 |
} |
|
364 |
|
|
365 |
public DataServerExplorer getExplorer() throws ReadException, |
|
366 |
ValidateDataParametersException { |
|
367 |
// TODO Auto-generated method stub |
|
368 |
return null; |
|
369 |
} |
|
370 |
|
|
371 |
public Object getSourceId() { |
|
372 |
// TODO Auto-generated method stub |
Also available in: Unified diff