Revision 39207 branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/dbf/DBFStoreProvider.java
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 |
}); |
Also available in: Unified diff