Revision 43648 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.jdbc/src/main/java/org/gvsig/exportto/swing/prov/jdbc/ExporrtoJDBCService.java
ExporrtoJDBCService.java | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
package org.gvsig.exportto.swing.prov.jdbc; |
24 | 24 |
|
25 |
import java.util.Map;
|
|
25 |
import java.text.MessageFormat;
|
|
26 | 26 |
import org.apache.commons.lang3.StringUtils; |
27 | 27 |
import org.cresques.cts.ICoordTrans; |
28 | 28 |
import org.cresques.cts.IProjection; |
... | ... | |
68 | 68 |
public static final int ACTION_ABORT = 2; |
69 | 69 |
|
70 | 70 |
private ExporttoServiceFinishAction exporttoServiceFinishAction = null; |
71 |
private ExporttoJDBCOptions options; |
|
71 |
private final ExporttoJDBCOptions options; |
|
72 |
private FeatureType targetFeatureType = null; |
|
72 | 73 |
// private Map<String,String> translationIds; |
73 | 74 |
|
74 | 75 |
public ExporrtoJDBCService(ExporttoJDBCOptions options) { |
... | ... | |
91 | 92 |
|
92 | 93 |
protected void createTable(JDBCServerExplorer explorer) throws Exception { |
93 | 94 |
|
94 |
FeatureType targetFeatureType; |
|
95 |
FeatureType targetTempFeatureType;
|
|
95 | 96 |
EditableFeatureType targetEditableFeatureType; |
96 | 97 |
|
97 |
targetFeatureType = options.getSource().getDefaultFeatureType().getCopy(); |
|
98 |
targetEditableFeatureType = targetFeatureType.getEditable(); |
|
98 |
targetTempFeatureType = options.getSource().getDefaultFeatureType().getCopy();
|
|
99 |
targetEditableFeatureType = targetTempFeatureType.getEditable();
|
|
99 | 100 |
|
101 |
// Remove inherited primary keys from the data source |
|
102 |
for (int i = 0; i < targetEditableFeatureType.size(); i++) { |
|
103 |
EditableFeatureAttributeDescriptor x = (EditableFeatureAttributeDescriptor) targetEditableFeatureType.get(i); |
|
104 |
x.setIsPrimaryKey(false); |
|
105 |
} |
|
106 |
|
|
100 | 107 |
if (this.options.getTranslateIdentifiersToLowerCase() |
101 | 108 |
|| this.options.getRemoveSpacesInIdentifiers() |
102 | 109 |
|| this.options.getTranslateHyphens()) { |
... | ... | |
134 | 141 |
} |
135 | 142 |
|
136 | 143 |
// ====================================== |
144 |
// Remove index to improve performance |
|
145 |
this.targetFeatureType = targetEditableFeatureType.getNotEditableCopy(); |
|
146 |
for (int i = 0; i < targetEditableFeatureType.size(); i++) { |
|
147 |
EditableFeatureAttributeDescriptor x = (EditableFeatureAttributeDescriptor) targetEditableFeatureType.get(i); |
|
148 |
//x.setIsPrimaryKey(false); |
|
149 |
x.setIsIndexed(false); |
|
150 |
} |
|
151 |
|
|
152 |
// ====================================== |
|
153 |
|
|
154 |
|
|
137 | 155 |
JDBCNewStoreParameters createTableParams = (JDBCNewStoreParameters) explorer.getAddParameters(); |
138 | 156 |
|
139 | 157 |
createTableParams.setSelectRole(this.options.getSelectRole()); |
... | ... | |
155 | 173 |
|
156 | 174 |
private static class InvalidGeometryException extends ExporttoServiceException { |
157 | 175 |
|
176 |
private static final long serialVersionUID = 3082742759529054747L; |
|
177 |
|
|
158 | 178 |
public InvalidGeometryException(Feature feature, String checkMessage) { |
159 | 179 |
super(checkMessage, null, checkMessage, 0); |
160 | 180 |
this.feature = feature; |
161 | 181 |
} |
162 | 182 |
} |
163 | 183 |
|
184 |
@Override |
|
164 | 185 |
public void export(FeatureSet featureSet) throws ExporttoServiceException { |
165 | 186 |
Geometry.ValidationStatus geometryCheck; |
166 | 187 |
|
... | ... | |
173 | 194 |
// ====================================== |
174 | 195 |
// Reprojection |
175 | 196 |
FeatureAttributeDescriptor geo_att = this.options.getSource().getDefaultFeatureType().getDefaultGeometryAttribute(); |
176 |
IProjection sourceProjection = null;
|
|
197 |
IProjection sourceProjection; |
|
177 | 198 |
ICoordTrans coord_trans = null; |
178 |
Geometry reproj_geom = null;
|
|
199 |
Geometry reproj_geom; |
|
179 | 200 |
IProjection targetProjection = this.options.getTargetProjection(); |
180 | 201 |
if (geo_att != null) { |
181 | 202 |
sourceProjection = geo_att.getSRS(); |
... | ... | |
215 | 236 |
|
216 | 237 |
target.edit(FeatureStore.MODE_APPEND); |
217 | 238 |
|
218 |
int featureCount = 1;
|
|
239 |
long featureCount = 1;
|
|
219 | 240 |
taskStatus.setRangeOfValues(0, featureSet.getSize()); |
220 | 241 |
|
221 |
int targetGeometryIndex = -1;
|
|
222 |
int sourceGeometryIndex = -1;
|
|
242 |
int targetGeometryIndex; |
|
243 |
int sourceGeometryIndex; |
|
223 | 244 |
if( getGeometryColumnCount(sourceFeatureType)==1 |
224 | 245 |
&& getGeometryColumnCount(targetFeatureType)==1 ) { |
225 | 246 |
// Si solo hay una columna de geometria asignaremos las geometrias |
... | ... | |
324 | 345 |
} |
325 | 346 |
featureCount++; |
326 | 347 |
} |
348 |
String msgRowCount = MessageFormat.format(" ({0,number, #,###} rows)",featureCount); |
|
327 | 349 |
targetFeature = null; |
350 |
taskStatus.setIndeterminate(); |
|
351 |
logger.debug("Finish editing"+msgRowCount); |
|
352 |
if( featureCount > 50000 ) { |
|
353 |
taskStatus.message("Finishing insertion of records, may take a while" + msgRowCount); |
|
354 |
} else { |
|
355 |
taskStatus.message("Finishing insertion of records"+msgRowCount); |
|
356 |
} |
|
328 | 357 |
target.finishEditing(); |
329 |
|
|
358 |
|
|
359 |
if (this.options.canCreatetable()) { |
|
360 |
taskStatus.message("Preparing the update of the indices"+msgRowCount); |
|
361 |
target.edit(); |
|
362 |
EditableFeatureType ft = target.getDefaultFeatureType().getEditable(); |
|
363 |
for( FeatureAttributeDescriptor attr : this.targetFeatureType) { |
|
364 |
EditableFeatureAttributeDescriptor attr2 = (EditableFeatureAttributeDescriptor) ft.getAttributeDescriptor(attr.getName()); |
|
365 |
if( attr2!=null ) { |
|
366 |
//attr2.setIsPrimaryKey(attr.isPrimaryKey()); |
|
367 |
attr2.setIsIndexed(attr.isIndexed()); |
|
368 |
attr2.setIsAutomatic(attr.isAutomatic()); |
|
369 |
} |
|
370 |
} |
|
371 |
target.update(ft); |
|
372 |
taskStatus.message("Updating the indices"+msgRowCount); |
|
373 |
target.finishEditing(); |
|
374 |
} |
|
330 | 375 |
if (this.options.getUpdateTableStatistics()) { |
331 | 376 |
logger.debug("Updating statistics"); |
332 |
taskStatus.message("Updating statistics"); |
|
377 |
taskStatus.message("Updating statistics"+msgRowCount);
|
|
333 | 378 |
explorer.updateTableStatistics( |
334 | 379 |
openParams.getDBName(), |
335 | 380 |
openParams.getSchema(), |
... | ... | |
337 | 382 |
); |
338 | 383 |
} |
339 | 384 |
logger.debug("finish"); |
385 |
taskStatus.message("Exportation finished"); |
|
386 |
this.taskStatus.terminate(); |
|
340 | 387 |
|
341 | 388 |
if (exporttoServiceFinishAction != null) { |
342 | 389 |
exporttoServiceFinishAction.finished( |
343 | 390 |
this.options.getTableName() + " (" + explorer.getStoreName() + ")", |
344 | 391 |
openParams); |
345 | 392 |
} |
346 |
taskStatus.message("Exportation finished"); |
|
347 | 393 |
|
348 | 394 |
} catch (Exception e) { |
349 | 395 |
logger.warn("Can't export data.", e); |
... | ... | |
360 | 406 |
try { |
361 | 407 |
target.cancelEditing(); |
362 | 408 |
} catch(Exception ex) { |
363 |
// Do nothing
|
|
409 |
logger.warn("Can't cancel editing.",ex);
|
|
364 | 410 |
} |
365 | 411 |
} |
366 | 412 |
target.dispose(); |
... | ... | |
380 | 426 |
return count; |
381 | 427 |
} |
382 | 428 |
|
429 |
@Override |
|
383 | 430 |
public void setFinishAction( |
384 | 431 |
ExporttoServiceFinishAction exporttoServiceFinishAction) { |
385 | 432 |
this.exporttoServiceFinishAction = exporttoServiceFinishAction; |
Also available in: Unified diff