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 @ 43020
History | View | Annotate | Download (4.97 KB)
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
|
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, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.fmap.dal.store.dbf; |
26 |
|
27 |
import java.io.File; |
28 |
import java.util.ArrayList; |
29 |
import java.util.Iterator; |
30 |
|
31 |
import org.gvsig.fmap.dal.DataStoreParameters; |
32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 |
import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore; |
34 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
35 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
36 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
37 |
import org.gvsig.fmap.dal.feature.FeatureType; |
38 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
39 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
40 |
|
41 |
public class TestDBF extends BaseTestEditableFeatureStore { |
42 |
|
43 |
public static final File dbf_prueba = new File(TestDBF.class.getResource( |
44 |
"data/prueba.dbf").getFile());
|
45 |
public static final File dbf_prueba_destino= new File(TestDBF.class.getResource( |
46 |
"data").getFile()+"/pruebaTemp.dbf"); |
47 |
public static final File dbf_pruebaNull = new File(TestDBF.class |
48 |
.getResource("data/pruebaNull.dbf").getFile());
|
49 |
|
50 |
private FilesystemServerExplorer myExplorer = null; |
51 |
|
52 |
public DataStoreParameters getDefaultDataStoreParameters() throws DataException { |
53 |
DBFStoreParameters dbfParameters = null;
|
54 |
dbfParameters = (DBFStoreParameters) dataManager |
55 |
.createStoreParameters(DBFStoreProvider.NAME); |
56 |
|
57 |
dbfParameters.setFile(dbf_prueba); |
58 |
|
59 |
return dbfParameters;
|
60 |
} |
61 |
|
62 |
public void testExplorerList() throws Exception { |
63 |
this.testExplorerList(2); |
64 |
} |
65 |
|
66 |
public void testJoin() throws Exception { |
67 |
DBFStoreParameters dbfParameters = null;
|
68 |
FeatureStore store1, store2; |
69 |
|
70 |
dbfParameters = (DBFStoreParameters) dataManager |
71 |
.createStoreParameters(DBFStoreProvider.NAME); |
72 |
|
73 |
dbfParameters.setFile(dbf_prueba); |
74 |
|
75 |
store1 = (FeatureStore) dataManager.openStore(dbfParameters.getDataStoreName(),dbfParameters); |
76 |
store2 = (FeatureStore) dataManager.openStore(dbfParameters.getDataStoreName(),dbfParameters); |
77 |
|
78 |
JoinTransform join = new JoinTransform();
|
79 |
|
80 |
ArrayList names = new ArrayList();// <String> |
81 |
Iterator iter = store2.getDefaultFeatureType().iterator();// <FeatureAttributeDescriptor> |
82 |
while (iter.hasNext()) {
|
83 |
names.add(((FeatureAttributeDescriptor) iter.next()).getName()); |
84 |
} |
85 |
|
86 |
join.initialize(store1, store2, "NOMBRE", "NOMBRE", null, null, |
87 |
(String[]) names.toArray(new String[0])); |
88 |
store1.getTransforms().add(join); |
89 |
|
90 |
this.testSimpleIteration(store1);
|
91 |
|
92 |
FeatureQuery query = store1.createFeatureQuery(); |
93 |
FeatureType ftFinal = store1.getDefaultFeatureType(); |
94 |
String[] queryNames = new String[] { |
95 |
ftFinal.getAttributeDescriptor(0).getName(),
|
96 |
ftFinal.getAttributeDescriptor(1).getName(),
|
97 |
ftFinal.getAttributeDescriptor(ftFinal.size() - 1).getName() };
|
98 |
query.setAttributeNames(queryNames); |
99 |
|
100 |
this.testSimpleIteration(store1, query);
|
101 |
|
102 |
queryNames = new String[] { |
103 |
ftFinal.getAttributeDescriptor(ftFinal.size() - 1).getName(),
|
104 |
ftFinal.getAttributeDescriptor(1).getName(),
|
105 |
ftFinal.getAttributeDescriptor(0).getName(),
|
106 |
ftFinal.getAttributeDescriptor(ftFinal.size() - 2).getName() };
|
107 |
|
108 |
query.setAttributeNames(queryNames); |
109 |
this.testSimpleIteration(store1, query);
|
110 |
|
111 |
store1.dispose(); |
112 |
store2.dispose(); |
113 |
|
114 |
|
115 |
|
116 |
|
117 |
} |
118 |
|
119 |
/*
|
120 |
* (non-Javadoc)
|
121 |
*
|
122 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer()
|
123 |
*/
|
124 |
public boolean hasExplorer() { |
125 |
return true; |
126 |
} |
127 |
|
128 |
/*
|
129 |
* (non-Javadoc)
|
130 |
*
|
131 |
* @seeorg.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore#
|
132 |
* getDefaultNewDataStoreParameters()
|
133 |
*/
|
134 |
public NewFeatureStoreParameters getDefaultNewDataStoreParameters()
|
135 |
throws Exception { |
136 |
if (this.myExplorer == null) { |
137 |
DBFStoreParameters dbfParameters = (DBFStoreParameters) this
|
138 |
.getDefaultDataStoreParameters(); |
139 |
FeatureStore store = (FeatureStore) dataManager |
140 |
.openStore(dbfParameters.getDataStoreName(),dbfParameters); |
141 |
myExplorer = (FilesystemServerExplorer) store.getExplorer(); |
142 |
store.dispose(); |
143 |
} |
144 |
|
145 |
return (NewFeatureStoreParameters) myExplorer
|
146 |
.getAddParameters(dbf_prueba_destino); |
147 |
} |
148 |
|
149 |
public boolean usesResources() { |
150 |
return true; |
151 |
} |
152 |
|
153 |
@Override
|
154 |
public boolean resourcesNotifyChanges() { |
155 |
return true; |
156 |
} |
157 |
|
158 |
} |