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