svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.dbf / src / test / java / org / gvsig / fmap / dal / store / dbf / TestDBF.java @ 40435
History | View | Annotate | Download (4.9 KB)
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 |
* 2008 IVER T.I. S.A. {{Task}}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.dal.store.dbf; |
29 |
|
30 |
import java.io.File; |
31 |
import java.util.ArrayList; |
32 |
import java.util.Iterator; |
33 |
|
34 |
import org.gvsig.fmap.dal.DataStoreParameters; |
35 |
import org.gvsig.fmap.dal.exception.DataException; |
36 |
import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore; |
37 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
38 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
40 |
import org.gvsig.fmap.dal.feature.FeatureType; |
41 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
42 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
43 |
|
44 |
public class TestDBF extends BaseTestEditableFeatureStore { |
45 |
|
46 |
public static final File dbf_prueba = new File(TestDBF.class.getResource( |
47 |
"data/prueba.dbf").getFile());
|
48 |
public static final File dbf_prueba_destino= new File(TestDBF.class.getResource( |
49 |
"data").getFile()+"/pruebaTemp.dbf"); |
50 |
public static final File dbf_pruebaNull = new File(TestDBF.class |
51 |
.getResource("data/pruebaNull.dbf").getFile());
|
52 |
|
53 |
private FilesystemServerExplorer myExplorer = null; |
54 |
|
55 |
public DataStoreParameters getDefaultDataStoreParameters() throws DataException { |
56 |
DBFStoreParameters dbfParameters = null;
|
57 |
dbfParameters = (DBFStoreParameters) dataManager |
58 |
.createStoreParameters(DBFStoreProvider.NAME); |
59 |
|
60 |
dbfParameters.setFile(dbf_prueba); |
61 |
|
62 |
return dbfParameters;
|
63 |
} |
64 |
|
65 |
public void testExplorerList() throws Exception { |
66 |
this.testExplorerList(2); |
67 |
} |
68 |
|
69 |
public void testJoin() throws Exception { |
70 |
DBFStoreParameters dbfParameters = null;
|
71 |
FeatureStore store1, store2; |
72 |
|
73 |
dbfParameters = (DBFStoreParameters) dataManager |
74 |
.createStoreParameters(DBFStoreProvider.NAME); |
75 |
|
76 |
dbfParameters.setFile(dbf_prueba); |
77 |
|
78 |
store1 = (FeatureStore) dataManager.createStore(dbfParameters); |
79 |
store2 = (FeatureStore) dataManager.createStore(dbfParameters); |
80 |
|
81 |
JoinTransform join = new JoinTransform();
|
82 |
|
83 |
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 |
|
89 |
join.initialize(store1, store2, "NOMBRE", "NOMBRE", null, null, |
90 |
(String[]) names.toArray(new String[0])); |
91 |
store1.getTransforms().add(join); |
92 |
|
93 |
this.testSimpleIteration(store1);
|
94 |
|
95 |
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 |
|
103 |
this.testSimpleIteration(store1, query);
|
104 |
|
105 |
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 |
|
111 |
query.setAttributeNames(queryNames); |
112 |
this.testSimpleIteration(store1, query);
|
113 |
|
114 |
store1.dispose(); |
115 |
store2.dispose(); |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
} |
121 |
|
122 |
/*
|
123 |
* (non-Javadoc)
|
124 |
*
|
125 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer()
|
126 |
*/
|
127 |
public boolean hasExplorer() { |
128 |
return true; |
129 |
} |
130 |
|
131 |
/*
|
132 |
* (non-Javadoc)
|
133 |
*
|
134 |
* @seeorg.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore#
|
135 |
* getDefaultNewDataStoreParameters()
|
136 |
*/
|
137 |
public NewFeatureStoreParameters getDefaultNewDataStoreParameters()
|
138 |
throws Exception { |
139 |
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 |
public boolean usesResources() { |
153 |
return true; |
154 |
} |
155 |
|
156 |
@Override
|
157 |
public boolean resourcesNotifyChanges() { |
158 |
return true; |
159 |
} |
160 |
|
161 |
} |