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