Revision 39207
branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/shp/SHPStoreProvider.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
package org.gvsig.fmap.dal.store.shp; |
29 | 29 |
|
30 |
import java.io.File; |
|
30 | 31 |
import java.io.IOException; |
31 | 32 |
import java.util.Iterator; |
32 | 33 |
|
34 |
import org.apache.commons.io.FileUtils; |
|
33 | 35 |
import org.cresques.cts.IProjection; |
34 | 36 |
import org.slf4j.Logger; |
35 | 37 |
import org.slf4j.LoggerFactory; |
36 | 38 |
|
37 |
import org.gvsig.fmap.crs.CRSFactory; |
|
38 | 39 |
import org.gvsig.fmap.dal.DataStore; |
39 | 40 |
import org.gvsig.fmap.dal.DataTypes; |
40 | 41 |
import org.gvsig.fmap.dal.FileHelper; |
... | ... | |
473 | 474 |
SHPStoreParameters shpParams = getShpParameters(); |
474 | 475 |
SHPStoreParameters tmpParams = |
475 | 476 |
(SHPStoreParameters) shpParams.getCopy(); |
476 |
tmpParams.setDBFFile(tmpParams.getDBFFileName() |
|
477 |
+ ".tmp"); |
|
478 |
tmpParams.setSHPFile(tmpParams.getSHPFileName() |
|
479 |
+ ".tmp"); |
|
480 |
tmpParams.setSHXFile(tmpParams.getSHXFileName() |
|
481 |
+ ".tmp"); |
|
477 |
|
|
478 |
File tmp_base = File.createTempFile( |
|
479 |
"tmp_" + System.currentTimeMillis(), null); |
|
480 |
String str_base = tmp_base.getCanonicalPath(); |
|
481 |
|
|
482 |
tmpParams.setDBFFile(str_base + ".dbf"); |
|
483 |
tmpParams.setSHPFile(str_base + ".shp"); |
|
484 |
tmpParams.setSHXFile(str_base + ".shx"); |
|
482 | 485 |
|
483 | 486 |
writer.begin(tmpParams, fType, dbfFtype, set.getSize()); |
484 | 487 |
|
... | ... | |
505 | 508 |
throw new PerformEditingException(getProviderName(), |
506 | 509 |
new IOException(shpParams.getSHXFileName())); |
507 | 510 |
} |
511 |
|
|
508 | 512 |
if (!tmpParams.getDBFFile().renameTo( |
509 | 513 |
shpParams.getDBFFile())) { |
510 |
throw new PerformEditingException(getProviderName(), |
|
511 |
new IOException(shpParams.getSHPFileName())); |
|
514 |
logger.info("Warning: copying tmp file instead of renaming: " |
|
515 |
+ shpParams.getDBFFile()); |
|
516 |
FileUtils.copyFile( |
|
517 |
tmpParams.getDBFFile(), |
|
518 |
shpParams.getDBFFile()); |
|
512 | 519 |
} |
513 | 520 |
if (!tmpParams.getSHPFile().renameTo( |
514 | 521 |
shpParams.getSHPFile())) { |
515 |
throw new PerformEditingException(getProviderName(), |
|
516 |
new IOException(shpParams.getSHPFileName())); |
|
522 |
logger.info("Warning: copying tmp file instead of renaming: " |
|
523 |
+ shpParams.getSHPFile()); |
|
524 |
FileUtils.copyFile( |
|
525 |
tmpParams.getSHPFile(), |
|
526 |
shpParams.getSHPFile()); |
|
517 | 527 |
} |
518 | 528 |
if (!tmpParams.getSHXFile().renameTo( |
519 | 529 |
shpParams.getSHXFile())) { |
520 |
throw new PerformEditingException(getProviderName(), |
|
521 |
new IOException(shpParams.getSHXFileName())); |
|
530 |
logger.info("Warning: copying tmp file instead of renaming: " |
|
531 |
+ shpParams.getSHXFile()); |
|
532 |
FileUtils.copyFile( |
|
533 |
tmpParams.getSHXFile(), |
|
534 |
shpParams.getSHXFile()); |
|
522 | 535 |
} |
523 | 536 |
|
524 | 537 |
resourcesNotifyChanges(); |
branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/dbf/DBFStoreProvider.java | ||
---|---|---|
11 | 11 |
import java.util.List; |
12 | 12 |
import java.util.Locale; |
13 | 13 |
|
14 |
import org.apache.commons.io.FileUtils; |
|
14 | 15 |
import org.slf4j.Logger; |
15 | 16 |
import org.slf4j.LoggerFactory; |
16 | 17 |
|
... | ... | |
207 | 208 |
DBFStoreParameters tmpParams = |
208 | 209 |
(DBFStoreParameters) getDBFParameters().getCopy(); |
209 | 210 |
|
210 |
tmpParams.setDBFFile(tmpParams.getDBFFileName() |
|
211 |
+ ".tmp"); |
|
211 |
File tmp_file = File.createTempFile( |
|
212 |
"tmp_" + System.currentTimeMillis(), ".dbf"); |
|
213 |
tmp_file.deleteOnExit(); |
|
214 |
|
|
215 |
tmpParams.setDBFFile(tmp_file); |
|
212 | 216 |
|
213 | 217 |
writer.begin(tmpParams, store.getDefaultFeatureType(), |
214 | 218 |
set.getSize()); |
... | ... | |
227 | 231 |
throw new PerformEditingException(getProviderName(), e1); |
228 | 232 |
} |
229 | 233 |
getDBFParameters().getDBFFile().delete(); |
230 |
tmpParams.getDBFFile().renameTo( |
|
231 |
getDBFParameters().getDBFFile()); |
|
234 |
|
|
235 |
File target_file = getDBFParameters().getDBFFile(); |
|
236 |
if (target_file.exists()) { |
|
237 |
target_file.delete(); |
|
238 |
} |
|
239 |
tmp_file.renameTo(target_file); |
|
240 |
|
|
241 |
if (tmp_file.exists() && !target_file.exists()) { |
|
242 |
// Renaming failed, let's simply copy. |
|
243 |
// We assume we cannot delete it, but we |
|
244 |
// used deleteOnExit and it's |
|
245 |
// temporary, so no problem |
|
246 |
LOG.info("Warning: copying tmp file instead of renaming: " |
|
247 |
+ target_file.getName()); |
|
248 |
FileUtils.copyFile(tmp_file, target_file); |
|
249 |
} |
|
232 | 250 |
|
233 | 251 |
resourcesNotifyChanges(); |
234 | 252 |
initFeatureType(); |
... | ... | |
357 | 375 |
+ fieldType, getProviderName())); |
358 | 376 |
} |
359 | 377 |
} |
378 |
|
|
379 |
// FeatureRules rules = fType.getRules(); |
|
380 |
// rules.add(new DBFRowValidator()); |
|
360 | 381 |
return fType; |
361 | 382 |
} |
362 | 383 |
}); |
branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/dbf/utils/DbaseFileWriter.java | ||
---|---|---|
163 | 163 |
featureType.iterator(); |
164 | 164 |
while (iterator.hasNext()) { |
165 | 165 |
FeatureAttributeDescriptor fad = iterator.next(); |
166 |
|
|
167 |
if (fad.getName().length() > DbaseFile.MAX_FIELD_NAME_LENGTH) { |
|
168 |
throw new FieldNameTooLongException( |
|
169 |
"DBF file", fad.getName()); |
|
170 |
} |
|
171 |
|
|
166 | 172 |
int type = fad.getType(); |
167 | 173 |
if (type == DataTypes.GEOMETRY) { |
168 | 174 |
continue; |
branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/dbf/utils/DbaseFile.java | ||
---|---|---|
33 | 33 |
* (5/15/2001 5:15:13 PM) |
34 | 34 |
*/ |
35 | 35 |
public class DbaseFile { |
36 |
|
|
37 |
public static final int MAX_FIELD_NAME_LENGTH = 11; |
|
38 |
|
|
36 | 39 |
// Header information for the DBase File |
37 | 40 |
private DbaseFileHeader myHeader; |
38 | 41 |
|
branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/dbf/utils/FieldNameTooLongException.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2012 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.fmap.dal.store.dbf.utils; |
|
24 |
|
|
25 |
import org.gvsig.fmap.dal.exception.WriteException; |
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
* Indicates that field name is too long for DBF file |
|
31 |
* |
|
32 |
* @author jldominguez |
|
33 |
* |
|
34 |
*/ |
|
35 |
public class FieldNameTooLongException extends WriteException { |
|
36 |
|
|
37 |
/** |
|
38 |
* @param resource |
|
39 |
* @param cause |
|
40 |
*/ |
|
41 |
public FieldNameTooLongException(String resource, String field) { |
|
42 |
super(resource, new Exception("Field name is too long (max 11 char): '" + field + "'")); |
|
43 |
} |
|
44 |
|
|
45 |
} |
branches/v2_0_0_prep/libraries/libFMap_dalfile/pom.xml | ||
---|---|---|
191 | 191 |
<artifactId>org.gvsig.tools.swing.impl</artifactId> |
192 | 192 |
<scope>test</scope> |
193 | 193 |
</dependency> |
194 |
|
|
195 |
<dependency> |
|
196 |
<groupId>commons-io</groupId> |
|
197 |
<artifactId>commons-io</artifactId> |
|
198 |
<scope>compile</scope> |
|
199 |
</dependency> |
|
194 | 200 |
</dependencies> |
195 | 201 |
<build> |
196 | 202 |
<sourceDirectory>src</sourceDirectory> |
Also available in: Unified diff