root / branches / v2_0_0_prep / libraries / libFMap_daldb / src-test / org / gvsig / fmap / dal / store / mysql / MySQLTestWrite.java @ 30580
History | View | Annotate | Download (7.34 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 |
* 2009 IVER T.I {{Task}}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.dal.store.mysql; |
29 |
|
30 |
import org.gvsig.fmap.dal.DataStoreParameters; |
31 |
import org.gvsig.fmap.dal.exception.DataException; |
32 |
import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore; |
33 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
35 |
import org.gvsig.fmap.dal.feature.FeatureType; |
36 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
37 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
38 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
39 |
|
40 |
|
41 |
public class MySQLTestWrite extends BaseTestEditableFeatureStore { |
42 |
private MySQLNewStoreParameters newParams;
|
43 |
private MySQLServerExplorer myExplorer;
|
44 |
|
45 |
|
46 |
protected void setUp() throws Exception { |
47 |
super.setUp();
|
48 |
// FIXME
|
49 |
// ToolsLocator.registerDefaultPersistenceManager(XMLEntityManager.class);
|
50 |
new DefaultLibrariesInitializer().fullInitialize();
|
51 |
|
52 |
// DefaultGeometryLibrary defGeomLib = new DefaultGeometryLibrary();
|
53 |
// defGeomLib.initialize();
|
54 |
//
|
55 |
// DefaultGeometryOperationLibrary defGeomOpLib = new DefaultGeometryOperationLibrary();
|
56 |
// defGeomOpLib.initialize();
|
57 |
//
|
58 |
// ProjectionLibrary projLib = new ProjectionLibrary();
|
59 |
// projLib.initialize();
|
60 |
//
|
61 |
// CresquesCtsLibrary cresquesLib = new CresquesCtsLibrary();
|
62 |
// cresquesLib.initialize();
|
63 |
//
|
64 |
// DALDbLibrary libDb = new DALDbLibrary();
|
65 |
// libDb.initialize();
|
66 |
//
|
67 |
// DBStoreLibrary libDbStore = new DBStoreLibrary();
|
68 |
// libDbStore.initialize();
|
69 |
//
|
70 |
// JDBCLibrary libJDBC = new JDBCLibrary();
|
71 |
// libJDBC.initialize();
|
72 |
//
|
73 |
// MySQLLibrary libMySQL = new MySQLLibrary();
|
74 |
// libMySQL.initialize();
|
75 |
//
|
76 |
// JTSIndexLibrary jtsIndex = new JTSIndexLibrary();
|
77 |
// jtsIndex.initialize();
|
78 |
//
|
79 |
// projLib.postInitialize();
|
80 |
// cresquesLib.postInitialize();
|
81 |
// defGeomLib.postInitialize();
|
82 |
// defGeomOpLib.postInitialize();
|
83 |
// libDb.postInitialize();
|
84 |
// libDbStore.postInitialize();
|
85 |
// libJDBC.postInitialize();
|
86 |
// libMySQL.postInitialize();
|
87 |
// jtsIndex.postInitialize();
|
88 |
} |
89 |
|
90 |
public DataStoreParameters getDefaultDataStoreParameters()
|
91 |
throws DataException {
|
92 |
MySQLStoreParameters parameters = null;
|
93 |
parameters = (MySQLStoreParameters) dataManager |
94 |
.createStoreParameters(MySQLStoreProvider.NAME); |
95 |
|
96 |
parameters.setHost("localhost");
|
97 |
parameters.setPort(3306);
|
98 |
parameters.setUser("test");
|
99 |
parameters.setPassword("test");
|
100 |
parameters.setDBName("gis");
|
101 |
// parameters.setTable("alfanum_autoid");
|
102 |
parameters.setTable("comunic_lin_300k");
|
103 |
|
104 |
return parameters;
|
105 |
} |
106 |
|
107 |
/*
|
108 |
* (non-Javadoc)
|
109 |
*
|
110 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer()
|
111 |
*/
|
112 |
@Override
|
113 |
public boolean hasExplorer() { |
114 |
// TODO Auto-generated method stub
|
115 |
return true; |
116 |
} |
117 |
|
118 |
/*
|
119 |
* (non-Javadoc)
|
120 |
*
|
121 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#usesResources()
|
122 |
*/
|
123 |
@Override
|
124 |
public boolean usesResources() { |
125 |
// TODO Auto-generated method stub
|
126 |
return true; |
127 |
} |
128 |
|
129 |
/*
|
130 |
public void testImportDB() throws Exception {
|
131 |
JDBCNewStoreParameters newParasm = (JDBCNewStoreParameters) getDefaultNewDataStoreParameters();
|
132 |
JDBCServerExplorerParameters seParams = (JDBCServerExplorerParameters) dataManager
|
133 |
.createServerExplorerParameters(JDBCServerExplorer.NAME);
|
134 |
|
135 |
assertTrue(myExplorer.add(newParasm, true));
|
136 |
|
137 |
FeatureStore store = (FeatureStore) dataManager
|
138 |
.createStore(getDefaultDataStoreParameters());
|
139 |
|
140 |
FeatureStore newstore = (FeatureStore) dataManager
|
141 |
.createStore(newParasm);
|
142 |
|
143 |
|
144 |
|
145 |
newstore.edit(FeatureStore.MODE_APPEND);
|
146 |
FeatureSet set = store.getFeatureSet();
|
147 |
DisposableIterator iter = set.iterator();
|
148 |
Feature org;
|
149 |
EditableFeature trg;
|
150 |
Iterator attrIter;
|
151 |
FeatureAttributeDescriptor attr;
|
152 |
while (iter.hasNext()) {
|
153 |
org = (Feature) iter.next();
|
154 |
trg = newstore.createNewFeature(false);
|
155 |
attrIter = trg.getType().iterator();
|
156 |
while (attrIter.hasNext()) {
|
157 |
attr = (FeatureAttributeDescriptor) attrIter.next();
|
158 |
trg.set(attr.getName(), org.get(attr.getName()));
|
159 |
}
|
160 |
newstore.insert(trg);
|
161 |
}
|
162 |
newstore.finishEditing();
|
163 |
|
164 |
iter.dispose();
|
165 |
set.dispose();
|
166 |
store.dispose();
|
167 |
newstore.dispose();
|
168 |
|
169 |
|
170 |
}
|
171 |
*/
|
172 |
|
173 |
@Override
|
174 |
public NewFeatureStoreParameters getDefaultNewDataStoreParameters()
|
175 |
throws Exception { |
176 |
|
177 |
|
178 |
JDBCStoreParameters params = (JDBCStoreParameters) getDefaultDataStoreParameters(); |
179 |
|
180 |
if (this.myExplorer == null) { |
181 |
|
182 |
MySQLServerExplorerParameters seParameters = null;
|
183 |
seParameters = (MySQLServerExplorerParameters) dataManager |
184 |
.createServerExplorerParameters(MySQLServerExplorer.NAME); |
185 |
|
186 |
seParameters.setHost("localhost");
|
187 |
seParameters.setPort(3306);
|
188 |
seParameters.setUser("test");
|
189 |
seParameters.setPassword("test");
|
190 |
seParameters.setDBName("gis");
|
191 |
|
192 |
|
193 |
myExplorer = (MySQLServerExplorer) dataManager |
194 |
.createServerExplorer(seParameters); |
195 |
} |
196 |
if (this.newParams == null) { |
197 |
FeatureStore store = (FeatureStore) dataManager.createStore(params); |
198 |
|
199 |
newParams = (MySQLNewStoreParameters) myExplorer |
200 |
.getAddParameters(); |
201 |
|
202 |
|
203 |
newParams.setTable(params.getTable() + "_test");
|
204 |
FeatureType ftOrg = store.getDefaultFeatureType(); |
205 |
EditableFeatureType ftTrg = ftOrg.getEditable(); |
206 |
|
207 |
// EditableFeatureType ftTrg = (EditableFeatureType) newParams
|
208 |
// .getDefaultFeatureType();
|
209 |
newParams.setDefaultFeatureType(ftTrg); |
210 |
|
211 |
// FeatureAttributeDescriptor org;
|
212 |
// EditableFeatureAttributeDescriptor trg;
|
213 |
// Iterator iter = ftOrg.iterator();
|
214 |
// while (iter.hasNext()) {
|
215 |
// org = (FeatureAttributeDescriptor) iter.next();
|
216 |
// trg = ftTrg.add(org.getName(), org.getDataType());
|
217 |
// trg.setAllowNull(org.allowNull());
|
218 |
// trg.setDefaultValue(org.getDefaultValue());
|
219 |
// trg.setGeometrySubType(org.getGeometrySubType());
|
220 |
// trg.setGeometryType(org.getGeometryType());
|
221 |
// trg.setIsAutomatic(org.isAutomatic());
|
222 |
// trg.setIsPrimaryKey(org.isPrimaryKey());
|
223 |
// trg.setIsReadOnly(org.isReadOnly());
|
224 |
// trg.setMaximumOccurrences(org.getMaximumOccurrences());
|
225 |
// trg.setMinimumOccurrences(org.getMinimumOccurrences());
|
226 |
// trg.setPrecision(org.getPrecision());
|
227 |
// trg.setSize(org.getSize());
|
228 |
// trg.setSRS(org.getSRS());
|
229 |
// trg.setAdditionalInfo("SQLType", org
|
230 |
// .getAdditionalInfo("SQLType"));
|
231 |
// trg.setAdditionalInfo("SQLTypeName", org
|
232 |
// .getAdditionalInfo("SQLTypeName"));
|
233 |
//
|
234 |
// }
|
235 |
// ftTrg.setDefaultGeometryAttributeName(ftOrg
|
236 |
// .getDefaultGeometryAttributeName());
|
237 |
// ftTrg.setHasOID(ftOrg.hasOID());
|
238 |
|
239 |
store.dispose(); |
240 |
} |
241 |
|
242 |
return this.newParams; |
243 |
} |
244 |
|
245 |
@Override
|
246 |
public boolean resourcesNotifyChanges() { |
247 |
// TODO Auto-generated method stub
|
248 |
return false; |
249 |
} |
250 |
|
251 |
} |