root / branches / v2_0_0_prep / libraries / libFMap_dalfile / src-test / org / gvsig / fmap / dal / store / dbf / TestDBF.java @ 33053
History | View | Annotate | Download (4.9 KB)
1 | 23996 | jmvivo | /* 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 | * 2008 IVER T.I. S.A. {{Task}}
|
||
26 | */
|
||
27 | |||
28 | 24498 | jmvivo | package org.gvsig.fmap.dal.store.dbf; |
29 | 23996 | jmvivo | |
30 | import java.io.File; |
||
31 | 25980 | jmvivo | import java.util.ArrayList; |
32 | 23996 | jmvivo | import java.util.Iterator; |
33 | |||
34 | 26040 | jmvivo | import org.gvsig.fmap.dal.DataStoreParameters; |
35 | 24502 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
36 | 26047 | jmvivo | import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore; |
37 | 24498 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
38 | 25246 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureQuery; |
39 | 24498 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureStore; |
40 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
41 | 25752 | vcaballero | import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
42 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
||
43 | 23996 | jmvivo | |
44 | 26047 | jmvivo | public class TestDBF extends BaseTestEditableFeatureStore { |
45 | 23996 | jmvivo | |
46 | 24642 | jmvivo | public static final File dbf_prueba = new File(TestDBF.class.getResource( |
47 | 23996 | jmvivo | "data/prueba.dbf").getFile());
|
48 | 25752 | vcaballero | public static final File dbf_prueba_destino= new File(TestDBF.class.getResource( |
49 | "data").getFile()+"/pruebaTemp.dbf"); |
||
50 | 24642 | jmvivo | public static final File dbf_pruebaNull = new File(TestDBF.class |
51 | .getResource("data/pruebaNull.dbf").getFile());
|
||
52 | 23996 | jmvivo | |
53 | 26047 | jmvivo | private FilesystemServerExplorer myExplorer = null; |
54 | 24642 | jmvivo | |
55 | 26040 | jmvivo | public DataStoreParameters getDefaultDataStoreParameters() throws DataException { |
56 | 24642 | jmvivo | DBFStoreParameters dbfParameters = null;
|
57 | 26040 | jmvivo | dbfParameters = (DBFStoreParameters) dataManager |
58 | .createStoreParameters(DBFStoreProvider.NAME); |
||
59 | 24642 | jmvivo | |
60 | 26040 | jmvivo | dbfParameters.setFile(dbf_prueba); |
61 | 24642 | jmvivo | |
62 | 26040 | jmvivo | return dbfParameters;
|
63 | 24642 | jmvivo | } |
64 | |||
65 | 27723 | jmvivo | public void testExplorerList() throws Exception { |
66 | 26040 | jmvivo | this.testExplorerList(2); |
67 | 24791 | jmvivo | } |
68 | |||
69 | 27723 | jmvivo | public void testJoin() throws Exception { |
70 | 25980 | jmvivo | DBFStoreParameters dbfParameters = null;
|
71 | FeatureStore store1, store2; |
||
72 | |||
73 | 27723 | jmvivo | dbfParameters = (DBFStoreParameters) dataManager |
74 | .createStoreParameters(DBFStoreProvider.NAME); |
||
75 | 25980 | jmvivo | |
76 | 27723 | jmvivo | dbfParameters.setFile(dbf_prueba); |
77 | 25980 | jmvivo | |
78 | 27723 | jmvivo | store1 = (FeatureStore) dataManager.createStore(dbfParameters); |
79 | store2 = (FeatureStore) dataManager.createStore(dbfParameters); |
||
80 | 25980 | jmvivo | |
81 | 27723 | jmvivo | JoinTransform join = new JoinTransform();
|
82 | 25980 | jmvivo | |
83 | 27723 | jmvivo | ArrayList names = new ArrayList();// <String> |
84 | Iterator iter = store2.getDefaultFeatureType().iterator();// <FeatureAttributeDescriptor> |
||
85 | while (iter.hasNext()) {
|
||
86 | names.add(((FeatureAttributeDescriptor) iter.next()).getName()); |
||
87 | } |
||
88 | 25980 | jmvivo | |
89 | 27723 | jmvivo | join.initialize(store1, store2, "NOMBRE", "NOMBRE", null, null, |
90 | (String[]) names.toArray(new String[0])); |
||
91 | store1.getTransforms().add(join); |
||
92 | 25980 | jmvivo | |
93 | 27723 | jmvivo | this.testSimpleIteration(store1);
|
94 | 25980 | jmvivo | |
95 | 27723 | jmvivo | FeatureQuery query = store1.createFeatureQuery(); |
96 | FeatureType ftFinal = store1.getDefaultFeatureType(); |
||
97 | String[] queryNames = new String[] { |
||
98 | ftFinal.getAttributeDescriptor(0).getName(),
|
||
99 | ftFinal.getAttributeDescriptor(1).getName(),
|
||
100 | ftFinal.getAttributeDescriptor(ftFinal.size() - 1).getName() };
|
||
101 | query.setAttributeNames(queryNames); |
||
102 | 25980 | jmvivo | |
103 | 27723 | jmvivo | this.testSimpleIteration(store1, query);
|
104 | 25980 | jmvivo | |
105 | 27723 | jmvivo | queryNames = new String[] { |
106 | ftFinal.getAttributeDescriptor(ftFinal.size() - 1).getName(),
|
||
107 | ftFinal.getAttributeDescriptor(1).getName(),
|
||
108 | ftFinal.getAttributeDescriptor(0).getName(),
|
||
109 | ftFinal.getAttributeDescriptor(ftFinal.size() - 2).getName() };
|
||
110 | 25980 | jmvivo | |
111 | 27723 | jmvivo | query.setAttributeNames(queryNames); |
112 | this.testSimpleIteration(store1, query);
|
||
113 | 25980 | jmvivo | |
114 | 27723 | jmvivo | store1.dispose(); |
115 | store2.dispose(); |
||
116 | 25980 | jmvivo | |
117 | |||
118 | |||
119 | |||
120 | } |
||
121 | |||
122 | 26040 | jmvivo | /*
|
123 | * (non-Javadoc)
|
||
124 | 26233 | vcaballero | *
|
125 | 26040 | jmvivo | * @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer()
|
126 | */
|
||
127 | public boolean hasExplorer() { |
||
128 | return true; |
||
129 | } |
||
130 | |||
131 | 26047 | jmvivo | /*
|
132 | * (non-Javadoc)
|
||
133 | 26233 | vcaballero | *
|
134 | 26047 | jmvivo | * @seeorg.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore#
|
135 | * getDefaultNewDataStoreParameters()
|
||
136 | */
|
||
137 | public NewFeatureStoreParameters getDefaultNewDataStoreParameters()
|
||
138 | 27723 | jmvivo | throws Exception { |
139 | 26047 | jmvivo | if (this.myExplorer == null) { |
140 | DBFStoreParameters dbfParameters = (DBFStoreParameters) this
|
||
141 | .getDefaultDataStoreParameters(); |
||
142 | FeatureStore store = (FeatureStore) dataManager |
||
143 | .createStore(dbfParameters); |
||
144 | myExplorer = (FilesystemServerExplorer) store.getExplorer(); |
||
145 | store.dispose(); |
||
146 | } |
||
147 | |||
148 | return (NewFeatureStoreParameters) myExplorer
|
||
149 | .getAddParameters(dbf_prueba_destino); |
||
150 | } |
||
151 | |||
152 | 26209 | jmvivo | public boolean usesResources() { |
153 | return true; |
||
154 | } |
||
155 | |||
156 | 28663 | jmvivo | @Override
|
157 | public boolean resourcesNotifyChanges() { |
||
158 | return true; |
||
159 | } |
||
160 | |||
161 | 23996 | jmvivo | } |