Revision 10627 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/EditableAdapter.java
EditableAdapter.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
import com.hardcode.driverManager.Driver; |
11 | 11 |
import com.hardcode.driverManager.DriverLoadException; |
12 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
13 |
import com.hardcode.gdbms.driver.exceptions.ReloadDriverException; |
|
14 |
import com.hardcode.gdbms.driver.exceptions.WriteDriverException; |
|
12 | 15 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
13 | 16 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
14 | 17 |
import com.hardcode.gdbms.engine.data.driver.AlphanumericDBDriver; |
... | ... | |
16 | 19 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
17 | 20 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
18 | 21 |
import com.hardcode.gdbms.engine.values.Value; |
22 |
import com.iver.cit.gvsig.exceptions.commands.EditionCommandException; |
|
23 |
import com.iver.cit.gvsig.exceptions.expansionfile.CloseExpansionFileException; |
|
24 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
|
25 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileWriteException; |
|
26 |
import com.iver.cit.gvsig.exceptions.layers.CancelEditingLayerException; |
|
27 |
import com.iver.cit.gvsig.exceptions.layers.StartEditionLayerException; |
|
28 |
import com.iver.cit.gvsig.exceptions.layers.StopEditionLayerException; |
|
29 |
import com.iver.cit.gvsig.exceptions.validate.ValidateRowException; |
|
30 |
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException; |
|
31 |
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException; |
|
32 |
import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
|
19 | 33 |
import com.iver.cit.gvsig.fmap.core.DefaultRow; |
20 | 34 |
import com.iver.cit.gvsig.fmap.core.IRow; |
21 | 35 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
... | ... | |
83 | 97 |
|
84 | 98 |
protected class MyFieldManager extends AbstractFieldManager { |
85 | 99 |
|
86 |
public boolean alterTable() throws EditionException {
|
|
100 |
public boolean alterTable() throws WriteDriverException {
|
|
87 | 101 |
return getFieldManager().alterTable(); |
88 | 102 |
} |
89 | 103 |
|
... | ... | |
156 | 170 |
* DOCUMENT ME! |
157 | 171 |
* @throws DriverException |
158 | 172 |
*/ |
159 |
public void setOriginalDataSource(SelectableDataSource ds) throws DriverException { |
|
173 |
public void setOriginalDataSource(SelectableDataSource ds) throws ReadDriverException {
|
|
160 | 174 |
this.ods = ds; |
161 | 175 |
initalizeFields(ds); |
162 | 176 |
Driver drv = ods.getDriver(); |
... | ... | |
169 | 183 |
|
170 | 184 |
/** |
171 | 185 |
* @param ds |
186 |
* @throws ReadDriverException |
|
172 | 187 |
* @throws DriverException |
173 | 188 |
*/ |
174 |
private void initalizeFields(SelectableDataSource ds) throws DriverException { |
|
189 |
private void initalizeFields(SelectableDataSource ds) throws ReadDriverException {
|
|
175 | 190 |
FieldDescription[] fields = ds.getFieldsDescription(); |
176 | 191 |
listInternalFields.clear(); |
177 | 192 |
actualIndexFields = 0; |
... | ... | |
186 | 201 |
// fastAccessFields.add(fields[i]); |
187 | 202 |
System.out.println("INITIALIZEFIELDS: FIELD " + field.getFieldDesc().getFieldAlias()); |
188 | 203 |
} |
189 |
try { |
|
190 | 204 |
fieldsChanged(); |
191 | 205 |
bFieldsHasBeenChanged = false; |
192 |
} catch (EditionException e) { |
|
193 |
e.printStackTrace(); |
|
194 |
throw new DriverException(e); |
|
195 |
} |
|
196 | 206 |
} |
197 | 207 |
|
198 | 208 |
private TreeMap deepCloneInternalFields(TreeMap col) |
... | ... | |
206 | 216 |
|
207 | 217 |
return clonedFields; |
208 | 218 |
} |
209 |
private void fieldsChanged() throws EditionException {
|
|
219 |
private void fieldsChanged() throws ReadDriverException {
|
|
210 | 220 |
fastAccessFields= new ArrayList(); |
211 | 221 |
int index = 0; |
212 | 222 |
for (Iterator iter = actualFields.values().iterator(); iter.hasNext();) { |
... | ... | |
222 | 232 |
getRecordset().mapExternalFields(); |
223 | 233 |
bFieldsHasBeenChanged = true; |
224 | 234 |
} catch (DriverLoadException e) { |
225 |
e.printStackTrace(); |
|
226 |
throw new EditionException(e); |
|
227 |
} catch (DriverException e) { |
|
228 |
e.printStackTrace(); |
|
229 |
throw new EditionException(e); |
|
235 |
throw new ReadDriverException(getRecordset().getDriver().getName(),e); |
|
230 | 236 |
} |
231 | 237 |
} |
232 | 238 |
|
233 | 239 |
/** |
234 | 240 |
* DOCUMENT ME! |
241 |
* @throws StartEditionLayerException |
|
242 |
* @throws StartWriterVisitorException |
|
235 | 243 |
* |
236 | 244 |
* @throws EditionException |
237 | 245 |
* DOCUMENT ME! |
238 | 246 |
*/ |
239 |
public void startEdition(int sourceType) throws EditionException {
|
|
247 |
public void startEdition(int sourceType) throws StartWriterVisitorException {
|
|
240 | 248 |
isEditing = true; |
241 | 249 |
|
242 | 250 |
fireStartEditionEvent(sourceType); |
... | ... | |
257 | 265 |
* |
258 | 266 |
*/ |
259 | 267 |
public void stopEdition(IWriter writer, int sourceType) |
260 |
throws EditionException {
|
|
268 |
throws StopWriterVisitorException {
|
|
261 | 269 |
saveEdits(writer, sourceType); |
262 | 270 |
isEditing = false; |
263 | 271 |
cr.clearAll(); |
... | ... | |
265 | 273 |
} |
266 | 274 |
|
267 | 275 |
public void saveEdits(IWriter writer, int sourceType) |
268 |
throws EditionException {
|
|
276 |
throws StopWriterVisitorException {
|
|
269 | 277 |
|
270 | 278 |
// TODO: ARREGLAR ESTO PARA QUE CUANDO HA HABIDO CAMBIOS |
271 | 279 |
// EN LOS CAMPOS, PODAMOS CAMBIAR LO QUE TOQUE (A SER POSIBLE |
... | ... | |
312 | 320 |
} |
313 | 321 |
// getFieldManager().alterTable(); // Se llama dentro del preprocess() |
314 | 322 |
} |
315 |
|
|
316 |
writer.preProcess(); |
|
317 |
|
|
318 | 323 |
try { |
319 |
|
|
324 |
writer.preProcess(); |
|
320 | 325 |
// Procesamos primero los borrados. |
321 | 326 |
// Cuando se genere un tema nuevo, no se les debe hacer caso |
322 | 327 |
// a estos registros |
... | ... | |
331 | 336 |
if (!relations.containsKey(integer)) { |
332 | 337 |
edRow = new DefaultRowEdited(new DefaultRow(ods |
333 | 338 |
.getRow(calculatedIndex)), |
334 |
DefaultRowEdited.STATUS_DELETED, calculatedIndex);
|
|
339 |
IRowEdited.STATUS_DELETED, calculatedIndex);
|
|
335 | 340 |
writer.process(edRow); |
336 | 341 |
} else { |
337 | 342 |
int num = ((Integer) relations.get(integer)).intValue(); |
... | ... | |
341 | 346 |
// ?Habr?a que hacer aqu? setID(index + "")? |
342 | 347 |
edRow = new DefaultRowEdited(rowFromExpansion |
343 | 348 |
.getLinkedRow().cloneRow(), |
344 |
DefaultRowEdited.STATUS_DELETED, calculatedIndex);
|
|
349 |
IRowEdited.STATUS_DELETED, calculatedIndex);
|
|
345 | 350 |
writer.process(edRow); |
346 | 351 |
} |
347 | 352 |
|
... | ... | |
393 | 398 |
ds = null; |
394 | 399 |
clean(); |
395 | 400 |
|
396 |
} catch (DriverIOException e) { |
|
397 |
e.printStackTrace(); |
|
398 |
throw new EditionException(e); |
|
399 |
} catch (IOException e) { |
|
400 |
e.printStackTrace(); |
|
401 |
throw new EditionException(e); |
|
402 |
} catch (DriverException e) { |
|
403 |
e.printStackTrace(); |
|
404 |
throw new EditionException(e); |
|
401 |
} catch (ReadDriverException e) { |
|
402 |
throw new StopWriterVisitorException(writer.getName(),e); |
|
403 |
} catch (ExpansionFileReadException e) { |
|
404 |
throw new StopWriterVisitorException(writer.getName(),e); |
|
405 |
} catch (StartWriterVisitorException e) { |
|
406 |
throw new StopWriterVisitorException(writer.getName(),e); |
|
407 |
} catch (VisitorException e) { |
|
408 |
throw new StopWriterVisitorException(writer.getName(),e); |
|
405 | 409 |
} |
406 | 410 |
|
407 | 411 |
} |
... | ... | |
412 | 416 |
* @throws IOException |
413 | 417 |
* DOCUMENT ME! |
414 | 418 |
*/ |
415 |
public void cancelEdition(int sourceType) throws IOException {
|
|
419 |
public void cancelEdition(int sourceType) throws CancelEditingLayerException {
|
|
416 | 420 |
isEditing = false; |
417 | 421 |
try { |
418 | 422 |
ds= null; |
419 | 423 |
clean(); |
420 | 424 |
cr.clearAll(); |
421 |
} catch (DriverException e) { |
|
422 |
e.printStackTrace(); |
|
423 |
throw new IOException("Error: " + e.getMessage()); |
|
425 |
} catch (ReadDriverException e) { |
|
426 |
throw new CancelEditingLayerException(writer.getName(),e); |
|
424 | 427 |
} |
425 | 428 |
fireCancelEditionEvent(sourceType); |
426 | 429 |
} |
... | ... | |
430 | 433 |
* |
431 | 434 |
* @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int) |
432 | 435 |
*/ |
433 |
public IRowEdited getRow(int index) throws DriverIOException, IOException {
|
|
436 |
public IRowEdited getRow(int index) throws ReadDriverException, ExpansionFileReadException {
|
|
434 | 437 |
int calculatedIndex = getCalculatedIndex(index); |
435 | 438 |
Integer integer = new Integer(calculatedIndex); |
436 | 439 |
DefaultRowEdited edRow = null; |
437 | 440 |
// Si no est? en el fichero de expansi?n |
438 | 441 |
if (!relations.containsKey(integer)) { |
439 |
try { |
|
440 | 442 |
/* |
441 | 443 |
* edRow = new DefaultRowEdited(new |
442 | 444 |
* DefaultRow(ods.getRow(calculatedIndex), "" + index), |
... | ... | |
444 | 446 |
*/ |
445 | 447 |
DefaultRow auxR = new DefaultRow(ods.getRow(calculatedIndex)); |
446 | 448 |
edRow = new DefaultRowEdited(auxR, |
447 |
DefaultRowEdited.STATUS_ORIGINAL, index);
|
|
449 |
IRowEdited.STATUS_ORIGINAL, index);
|
|
448 | 450 |
return createExternalRow(edRow, 0); |
449 | 451 |
// edRow = new DefaultRowEdited(new DefaultRow(ods |
450 | 452 |
// .getRow(calculatedIndex)), |
451 | 453 |
// DefaultRowEdited.STATUS_ORIGINAL, index); |
452 |
} catch (DriverException e) { |
|
453 |
throw new DriverIOException(e); |
|
454 |
} |
|
455 |
} else { |
|
456 |
int num = ((Integer) relations.get(integer)).intValue(); |
|
457 |
|
|
458 |
// return expansionFile.getRow(num); |
|
459 |
// ExpansionFile ya entrega el registro formateado como debe |
|
460 |
IRowEdited rowFromExpansion = expansionFile.getRow(num); |
|
461 |
// ?Habr?a que hacer aqu? setID(index + "")? |
|
462 |
edRow = new DefaultRowEdited(rowFromExpansion.getLinkedRow() |
|
463 |
.cloneRow(), rowFromExpansion.getStatus(), index); |
|
464 |
return edRow; |
|
465 | 454 |
} |
455 |
int num = ((Integer) relations.get(integer)).intValue(); |
|
466 | 456 |
|
457 |
// return expansionFile.getRow(num); |
|
458 |
// ExpansionFile ya entrega el registro formateado como debe |
|
459 |
IRowEdited rowFromExpansion; |
|
460 |
rowFromExpansion = expansionFile.getRow(num); |
|
461 |
// ?Habr?a que hacer aqu? setID(index + "")? |
|
462 |
edRow = new DefaultRowEdited(rowFromExpansion.getLinkedRow() |
|
463 |
.cloneRow(), rowFromExpansion.getStatus(), index); |
|
464 |
return edRow; |
|
467 | 465 |
|
468 | 466 |
|
467 |
|
|
469 | 468 |
} |
470 | 469 |
|
471 | 470 |
/** |
472 | 471 |
* DOCUMENT ME! |
473 | 472 |
* |
474 | 473 |
* @return DOCUMENT ME! |
474 |
* @throws ReadDriverException |
|
475 | 475 |
* |
476 | 476 |
* @throws DriverIOException |
477 | 477 |
* DOCUMENT ME! |
478 | 478 |
* @throws IOException |
479 | 479 |
* DOCUMENT ME! |
480 | 480 |
*/ |
481 |
public int getRowCount() throws DriverIOException, IOException { |
|
482 |
try { |
|
481 |
public int getRowCount() throws ReadDriverException { |
|
483 | 482 |
return (int) (ods.getRowCount() + numAdd) - delRows.cardinality();// - |
484 | 483 |
// expansionFile.getInvalidRows().cardinality(); |
485 |
} catch (DriverException e) { |
|
486 |
throw new DriverIOException(e); |
|
487 |
} |
|
488 |
|
|
489 | 484 |
} |
490 | 485 |
|
491 | 486 |
/* |
... | ... | |
494 | 489 |
* @see com.iver.cit.gvsig.fmap.edition.IEditableSource#addRow(com.iver.cit.gvsig.fmap.core.IRow, |
495 | 490 |
* java.lang.String) |
496 | 491 |
*/ |
497 |
public int addRow(IRow row, String descrip, int sourceType) |
|
498 |
throws DriverIOException, IOException {
|
|
492 |
public int addRow(IRow row, String descrip, int sourceType) throws ValidateRowException, ReadDriverException, ExpansionFileWriteException{
|
|
493 |
validateRow(row,sourceType);
|
|
499 | 494 |
|
500 |
try { |
|
501 |
validateRow(row,sourceType); |
|
502 |
} catch (EditionException e) { |
|
503 |
e.printStackTrace(); |
|
504 |
throw new IOException(e.getMessage()); |
|
505 |
} |
|
506 |
|
|
507 | 495 |
int calculatedIndex = doAddRow(row, sourceType); |
508 | 496 |
Command command = new AddRowCommand(this, row, calculatedIndex, |
509 | 497 |
sourceType); |
... | ... | |
519 | 507 |
|
520 | 508 |
/** |
521 | 509 |
* DOCUMENT ME! |
510 |
* @throws EditionCommandException |
|
522 | 511 |
* |
523 | 512 |
* @throws DriverIOException |
524 | 513 |
* DOCUMENT ME! |
525 | 514 |
* @throws IOException |
526 | 515 |
* DOCUMENT ME! |
527 | 516 |
*/ |
528 |
public void undo() throws DriverIOException, IOException {
|
|
517 |
public void undo() throws EditionCommandException{
|
|
529 | 518 |
// seleccion.clear(); |
530 | 519 |
if (cr.moreUndoCommands()) { |
531 | 520 |
cr.undoCommand(); |
... | ... | |
534 | 523 |
|
535 | 524 |
/** |
536 | 525 |
* DOCUMENT ME! |
526 |
* @throws EditionCommandException |
|
537 | 527 |
* |
538 | 528 |
* @throws DriverIOException |
539 | 529 |
* DOCUMENT ME! |
540 | 530 |
* @throws IOException |
541 | 531 |
* DOCUMENT ME! |
542 | 532 |
*/ |
543 |
public void redo() throws DriverIOException, IOException {
|
|
533 |
public void redo() throws EditionCommandException {
|
|
544 | 534 |
// seleccion.clear(); |
545 | 535 |
if (cr.moreRedoCommands()) { |
546 | 536 |
cr.redoCommand(); |
... | ... | |
552 | 542 |
* |
553 | 543 |
* @see com.iver.cit.gvsig.fmap.edition.IEditableSource#removeRow(int) |
554 | 544 |
*/ |
555 |
public void removeRow(int index, String descrip, int sourceType) |
|
556 |
throws IOException, DriverIOException { |
|
545 |
public void removeRow(int index, String descrip, int sourceType) throws ReadDriverException, ExpansionFileReadException { |
|
557 | 546 |
|
558 | 547 |
int calculatedIndex = getCalculatedIndex(index); |
559 | 548 |
Command command = new RemoveRowCommand(this, calculatedIndex, |
... | ... | |
574 | 563 |
* @see com.iver.cit.gvsig.fmap.edition.IEditableSource#modifyRow(int, |
575 | 564 |
* com.iver.cit.gvsig.fmap.core.IRow) |
576 | 565 |
*/ |
577 |
public int modifyRow(int index, IRow row, String descrip, int sourceType) |
|
578 |
throws IOException, DriverIOException { |
|
579 |
|
|
580 |
try { |
|
581 |
validateRow(row,sourceType); |
|
582 |
} catch (EditionException e) { |
|
583 |
e.printStackTrace(); |
|
584 |
throw new IOException(e.getMessage()); |
|
585 |
} |
|
586 |
|
|
566 |
public int modifyRow(int index, IRow row, String descrip, int sourceType) throws ValidateRowException, ExpansionFileWriteException, ReadDriverException, ExpansionFileReadException { |
|
567 |
validateRow(row,sourceType); |
|
587 | 568 |
int calculatedIndex = getCalculatedIndex(index); |
588 | 569 |
int pos = doModifyRow(calculatedIndex, row, sourceType); |
589 | 570 |
Command command = new ModifyRowCommand(this, calculatedIndex, pos, row, |
... | ... | |
621 | 602 |
* @throws DriverIOException |
622 | 603 |
* DOCUMENT ME! |
623 | 604 |
*/ |
624 |
public void endComplexRow(String description) throws IOException, |
|
625 |
DriverIOException { |
|
605 |
public void endComplexRow(String description) { |
|
626 | 606 |
commands.setDescription(description); |
627 | 607 |
cr.pushCommand(commands); |
628 | 608 |
complex = false; |
... | ... | |
656 | 636 |
* vale -1 quiere decir que es una modificaci?n de una geometr?a |
657 | 637 |
* original y por tanto no hay que actualizar el mapa de indices |
658 | 638 |
* sino eliminar su entrada. |
659 |
* |
|
660 | 639 |
* @throws IOException |
661 | 640 |
* @throws DriverIOException |
662 | 641 |
*/ |
663 | 642 |
public void undoModifyRow(int geometryIndex, |
664 |
int previousExpansionFileIndex, int sourceType) throws IOException, |
|
665 |
DriverIOException { |
|
643 |
int previousExpansionFileIndex, int sourceType) throws EditionCommandException { |
|
666 | 644 |
|
667 | 645 |
if (previousExpansionFileIndex == -1) { |
668 | 646 |
DefaultRowEdited edRow = null; |
669 | 647 |
try { |
670 | 648 |
edRow = new DefaultRowEdited(new DefaultRow(ods |
671 |
.getRow(geometryIndex)), |
|
672 |
DefaultRowEdited.STATUS_ORIGINAL, geometryIndex);
|
|
673 |
} catch (DriverException e) { |
|
674 |
e.printStackTrace();
|
|
649 |
.getRow(geometryIndex)),
|
|
650 |
IRowEdited.STATUS_ORIGINAL, geometryIndex);
|
|
651 |
} catch (ReadDriverException e) {
|
|
652 |
throw new EditionCommandException(writer.getName(),e);
|
|
675 | 653 |
} |
676 | 654 |
boolean cancel = fireBeforeModifyRow(edRow, geometryIndex, |
677 | 655 |
sourceType); |
... | ... | |
681 | 659 |
relations.remove(new Integer(geometryIndex)); |
682 | 660 |
expansionFile.deleteLastRow(); |
683 | 661 |
} else { |
684 |
boolean cancel = fireBeforeModifyRow(expansionFile |
|
685 |
.getRow(previousExpansionFileIndex), geometryIndex, |
|
686 |
sourceType); |
|
662 |
boolean cancel; |
|
663 |
try { |
|
664 |
cancel = fireBeforeModifyRow(expansionFile |
|
665 |
.getRow(previousExpansionFileIndex), geometryIndex, |
|
666 |
sourceType); |
|
667 |
} catch (ExpansionFileReadException e) { |
|
668 |
throw new EditionCommandException(writer.getName(),e); |
|
669 |
} |
|
687 | 670 |
if (cancel) |
688 | 671 |
return; |
689 | 672 |
// Se actualiza la relaci?n de ?ndices |
... | ... | |
701 | 684 |
* |
702 | 685 |
* @param index |
703 | 686 |
* ?ndice de la geometr?a. |
687 |
* @throws ReadDriverException |
|
688 |
* @throws ExpansionFileReadException |
|
704 | 689 |
* |
705 | 690 |
* @throws DriverIOException |
706 | 691 |
* @throws IOException |
707 | 692 |
*/ |
708 |
public IRow doRemoveRow(int index, int sourceType) |
|
709 |
throws DriverIOException, IOException { |
|
693 |
public IRow doRemoveRow(int index, int sourceType) throws ReadDriverException, ExpansionFileReadException{ |
|
710 | 694 |
boolean cancel = fireBeforeRemoveRow(index, sourceType); |
711 | 695 |
if (cancel) |
712 | 696 |
return null; |
... | ... | |
735 | 719 |
* DOCUMENT ME! |
736 | 720 |
* |
737 | 721 |
* @return DOCUMENT ME! |
722 |
* @throws ExpansionFileWriteException |
|
723 |
* @throws ReadDriverException |
|
724 |
* @throws ExpansionFileReadException |
|
738 | 725 |
* |
739 |
* @throws IOException |
|
740 |
* @throws DriverIOException |
|
741 | 726 |
*/ |
742 |
public int doModifyRow(int index, IRow feat, int sourceType) |
|
743 |
throws IOException, DriverIOException { |
|
727 |
public int doModifyRow(int index, IRow feat, int sourceType) throws ExpansionFileWriteException, ReadDriverException, ExpansionFileReadException { |
|
744 | 728 |
boolean cancel = fireBeforeModifyRow(feat, index, sourceType); |
745 | 729 |
if (cancel) |
746 | 730 |
return -1; |
... | ... | |
784 | 768 |
* geometr?a a guardar. |
785 | 769 |
* |
786 | 770 |
* @return calculatedIndex |
787 |
* |
|
771 |
* @throws ExpansionFileWriteException
|
|
788 | 772 |
* @throws DriverIOException |
789 | 773 |
* @throws IOException |
790 | 774 |
*/ |
791 |
public int doAddRow(IRow feat, int sourceType) throws DriverIOException, |
|
792 |
IOException { |
|
775 |
public int doAddRow(IRow feat, int sourceType) throws ReadDriverException, ExpansionFileWriteException { |
|
793 | 776 |
boolean cancel = fireBeforeRowAdded(sourceType); |
794 | 777 |
if (cancel) |
795 | 778 |
return -1; |
... | ... | |
797 | 780 |
// int virtualIndex = 0; |
798 | 781 |
int calculatedIndex = -1; |
799 | 782 |
|
800 |
try { |
|
801 |
calculatedIndex = (int) ods.getRowCount() + numAdd; |
|
802 |
// int externalIndex = getRowCount(); |
|
803 |
// calculatedIndex = getCalculatedIndex(externalIndex); |
|
804 |
} catch (DriverException e) { |
|
805 |
throw new DriverIOException(e); |
|
806 |
} |
|
783 |
calculatedIndex = (int) ods.getRowCount() + numAdd; |
|
807 | 784 |
|
808 | 785 |
int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, actualIndexFields); |
809 | 786 |
relations.put(new Integer(calculatedIndex), new Integer(pos)); |
... | ... | |
820 | 797 |
* |
821 | 798 |
* @param index |
822 | 799 |
* DOCUMENT ME! |
823 |
* |
|
824 |
* @throws IOException |
|
825 |
* @throws DriverIOException |
|
826 | 800 |
*/ |
827 |
public void undoRemoveRow(int index, int sourceType) throws IOException, |
|
828 |
DriverIOException { |
|
829 |
boolean cancel = fireBeforeRowAdded(sourceType); |
|
801 |
public void undoRemoveRow(int index, int sourceType) throws EditionCommandException { |
|
802 |
boolean cancel; |
|
803 |
try { |
|
804 |
cancel = fireBeforeRowAdded(sourceType); |
|
805 |
} catch (ReadDriverException e) { |
|
806 |
throw new EditionCommandException(writer.getName(),e); |
|
807 |
} |
|
830 | 808 |
if (cancel) |
831 | 809 |
return; |
832 | 810 |
delRows.set(index, false); |
... | ... | |
840 | 818 |
* |
841 | 819 |
* @param index |
842 | 820 |
* ?ndice de la geometr?a que se a?adi? |
843 |
* |
|
844 | 821 |
* @throws DriverIOException |
845 | 822 |
* @throws IOException |
846 | 823 |
*/ |
847 | 824 |
public void undoAddRow(int calculatedIndex, int sourceType) |
848 |
throws DriverIOException, IOException {
|
|
825 |
throws EditionCommandException {
|
|
849 | 826 |
boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType); |
850 | 827 |
if (cancel) |
851 | 828 |
return; |
... | ... | |
860 | 837 |
* |
861 | 838 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialAdapter#getRecordset() |
862 | 839 |
*/ |
863 |
public SelectableDataSource getRecordset() throws DriverLoadException {
|
|
840 |
public SelectableDataSource getRecordset() throws ReadDriverException {
|
|
864 | 841 |
if (isEditing) { |
865 | 842 |
if (ds == null) { |
866 | 843 |
String name = LayerFactory.getDataSourceFactory() |
867 |
.addDataSource((ObjectDriver) editingDriver);
|
|
844 |
.addDataSource(editingDriver); |
|
868 | 845 |
|
869 | 846 |
try { |
870 | 847 |
|
... | ... | |
876 | 853 |
|
877 | 854 |
} catch (NoSuchTableException e) { |
878 | 855 |
throw new RuntimeException(e); |
879 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
|
880 |
throw new RuntimeException(e); |
|
881 | 856 |
} |
882 | 857 |
} |
883 | 858 |
|
884 | 859 |
return ds; |
885 |
} else { |
|
886 |
return ods; |
|
887 | 860 |
} |
861 |
return ods; |
|
888 | 862 |
} |
889 | 863 |
|
890 | 864 |
/** |
... | ... | |
901 | 875 |
* DOCUMENT ME! |
902 | 876 |
* |
903 | 877 |
* @return |
878 |
* @throws ReadDriverException |
|
904 | 879 |
*/ |
905 |
public FBitSet getSelection() { |
|
880 |
public FBitSet getSelection() throws ReadDriverException {
|
|
906 | 881 |
/* |
907 | 882 |
* try { return getRecordset().getSelection(); } catch |
908 | 883 |
* (DriverLoadException e) { // TODO Auto-generated catch block |
... | ... | |
911 | 886 |
return getRecordset().getSelection(); |
912 | 887 |
} |
913 | 888 |
|
914 |
public void setSelection(FBitSet selection) { |
|
889 |
public void setSelection(FBitSet selection) throws ReadDriverException {
|
|
915 | 890 |
/* |
916 | 891 |
* try { getRecordset().setSelection(selection); } catch |
917 | 892 |
* (DriverLoadException e) { // TODO Auto-generated catch block |
... | ... | |
996 | 971 |
* |
997 | 972 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys() |
998 | 973 |
*/ |
999 |
public int[] getPrimaryKeys() throws DriverException { |
|
974 |
public int[] getPrimaryKeys() throws ReadDriverException {
|
|
1000 | 975 |
return ods.getPrimaryKeys(); |
1001 | 976 |
// int[] pk=new int[1]; |
1002 | 977 |
/* |
... | ... | |
1011 | 986 |
* |
1012 | 987 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare) |
1013 | 988 |
*/ |
1014 |
public void write(DataWare dataWare) throws DriverException { |
|
989 |
public void write(DataWare dataWare) throws ReadDriverException, WriteDriverException {
|
|
1015 | 990 |
DataWare dataWareOrig = ods |
1016 | 991 |
.getDataWare(DataSourceFactory.DATA_WARE_DIRECT_MODE); |
1017 | 992 |
dataWareOrig.commitTrans(); |
... | ... | |
1041 | 1016 |
* @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldValue(long, |
1042 | 1017 |
* int) |
1043 | 1018 |
*/ |
1044 |
public Value getFieldValue(long rowIndex, int fieldId) |
|
1045 |
throws DriverException { |
|
1019 |
public Value getFieldValue(long rowIndex, int fieldId) throws ReadDriverException { |
|
1046 | 1020 |
// Si no est? en el fichero de expansi?n |
1047 | 1021 |
// Integer integer = new Integer(getCalculatedIndex(rowIndex)); |
1048 | 1022 |
|
... | ... | |
1066 | 1040 |
// } catch (DriverException e) { |
1067 | 1041 |
// e.printStackTrace(); |
1068 | 1042 |
// throw new DriverException(e); |
1069 |
} catch (IOException e) { |
|
1070 |
e.printStackTrace(); |
|
1071 |
throw new DriverException(e); |
|
1072 |
} catch (DriverIOException e) { |
|
1073 |
e.printStackTrace(); |
|
1074 |
throw new DriverException(e); |
|
1043 |
} catch (ExpansionFileReadException e) { |
|
1044 |
throw new ReadDriverException(getRecordset().getDriver().getName(),e); |
|
1075 | 1045 |
} |
1076 | 1046 |
|
1077 | 1047 |
/** |
... | ... | |
1093 | 1063 |
* |
1094 | 1064 |
* @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldCount() |
1095 | 1065 |
*/ |
1096 |
public int getFieldCount() throws DriverException { |
|
1066 |
public int getFieldCount() throws ReadDriverException {
|
|
1097 | 1067 |
return fastAccessFields.size(); |
1098 | 1068 |
} |
1099 | 1069 |
|
... | ... | |
1102 | 1072 |
* |
1103 | 1073 |
* @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldName(int) |
1104 | 1074 |
*/ |
1105 |
public String getFieldName(int fieldId) throws DriverException { |
|
1075 |
public String getFieldName(int fieldId) throws ReadDriverException {
|
|
1106 | 1076 |
// int i=0; |
1107 | 1077 |
// for (Iterator iter = actualFields.values().iterator(); iter.hasNext();) { |
1108 | 1078 |
// InternalField fld = (InternalField) iter.next(); |
... | ... | |
1123 | 1093 |
* |
1124 | 1094 |
* @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getRowCount() |
1125 | 1095 |
*/ |
1126 |
public long getRowCount() { |
|
1127 |
try { |
|
1128 |
return (int) (ods.getRowCount() + numAdd) |
|
1129 |
- delRows.cardinality();// - |
|
1130 |
// expansionFile.getInvalidRows().cardinality(); |
|
1131 |
} catch (DriverException e) { |
|
1132 |
// TODO Auto-generated catch block |
|
1133 |
e.printStackTrace(); |
|
1134 |
} |
|
1135 |
|
|
1136 |
return 0; |
|
1096 |
public long getRowCount() throws ReadDriverException { |
|
1097 |
return (int) (ods.getRowCount() + numAdd) |
|
1098 |
- delRows.cardinality();// - |
|
1099 |
// expansionFile.getInvalidRows().cardinality(); |
|
1137 | 1100 |
} |
1138 | 1101 |
|
1139 | 1102 |
/* |
... | ... | |
1141 | 1104 |
* |
1142 | 1105 |
* @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldType(int) |
1143 | 1106 |
*/ |
1144 |
public int getFieldType(int fieldId) throws DriverException { |
|
1107 |
public int getFieldType(int fieldId) throws ReadDriverException {
|
|
1145 | 1108 |
// int i=0; |
1146 | 1109 |
// for (Iterator iter = actualFields.values().iterator(); iter.hasNext();) { |
1147 | 1110 |
// InternalField fld = (InternalField) iter.next(); |
... | ... | |
1156 | 1119 |
// return ods.getFieldType(i); |
1157 | 1120 |
} |
1158 | 1121 |
|
1159 |
public int getFieldWidth(int fieldId) throws DriverException { |
|
1122 |
public int getFieldWidth(int fieldId) throws ReadDriverException {
|
|
1160 | 1123 |
// int i=0; |
1161 | 1124 |
// for (Iterator iter = actualFields.values().iterator(); iter.hasNext();) { |
1162 | 1125 |
// InternalField fld = (InternalField) iter.next(); |
... | ... | |
1174 | 1137 |
|
1175 | 1138 |
} |
1176 | 1139 |
|
1177 |
public void reload() throws IOException, DriverException {
|
|
1140 |
public void reload() throws ReloadDriverException {
|
|
1178 | 1141 |
ods.reload(); |
1179 | 1142 |
|
1180 | 1143 |
} |
... | ... | |
1271 | 1234 |
} |
1272 | 1235 |
|
1273 | 1236 |
|
1274 |
protected boolean fireBeforeRowAdded(int sourceType) |
|
1275 |
throws DriverIOException, IOException { |
|
1237 |
protected boolean fireBeforeRowAdded(int sourceType) throws ReadDriverException{ |
|
1276 | 1238 |
Cancel cancel = new Cancel(); |
1277 | 1239 |
BeforeRowEditEvent event = new BeforeRowEditEvent(this, getRowCount(), |
1278 | 1240 |
EditionEvent.CHANGE_TYPE_ADD, cancel, sourceType); |
... | ... | |
1286 | 1248 |
return false; |
1287 | 1249 |
} |
1288 | 1250 |
|
1289 |
protected boolean fireBeforeFieldAdded(FieldDescription field) |
|
1290 |
throws EditionException { |
|
1251 |
protected boolean fireBeforeFieldAdded(FieldDescription field) { |
|
1291 | 1252 |
Cancel cancel = new Cancel(); |
1292 | 1253 |
BeforeFieldEditEvent event = new BeforeFieldEditEvent(this, field, |
1293 | 1254 |
EditionEvent.CHANGE_TYPE_ADD, cancel); |
... | ... | |
1301 | 1262 |
return false; |
1302 | 1263 |
} |
1303 | 1264 |
|
1304 |
protected boolean fireBeforeRemoveField(FieldDescription field) |
|
1305 |
throws EditionException { |
|
1265 |
protected boolean fireBeforeRemoveField(FieldDescription field){ |
|
1306 | 1266 |
Cancel cancel = new Cancel(); |
1307 | 1267 |
BeforeFieldEditEvent event = new BeforeFieldEditEvent(this, field, |
1308 | 1268 |
EditionEvent.CHANGE_TYPE_DELETE, cancel); |
... | ... | |
1404 | 1364 |
* TODO REVISAR LA ARQUITECTURA DE ESTO |
1405 | 1365 |
* |
1406 | 1366 |
* */ |
1407 |
public ITableDefinition getTableDefinition() throws DriverLoadException, |
|
1408 |
DriverException { |
|
1367 |
public ITableDefinition getTableDefinition() throws ReadDriverException { |
|
1409 | 1368 |
Driver originalDriver = getOriginalDriver(); |
1410 | 1369 |
if(! (originalDriver instanceof AlphanumericDBDriver)){ |
1411 | 1370 |
TableDefinition tableDef = new TableDefinition(); |
1412 | 1371 |
tableDef.setFieldsDesc(getRecordset().getFieldsDescription()); |
1413 | 1372 |
tableDef.setName(getRecordset().getSourceInfo().name); |
1414 | 1373 |
return tableDef; |
1415 |
}else{ |
|
1416 |
AlphanumericDBDriver dbDriver = (AlphanumericDBDriver)originalDriver; |
|
1417 |
return dbDriver.getTableDefinition(); |
|
1418 |
|
|
1419 | 1374 |
} |
1375 |
AlphanumericDBDriver dbDriver = (AlphanumericDBDriver)originalDriver; |
|
1376 |
return dbDriver.getTableDefinition(); |
|
1420 | 1377 |
|
1421 | 1378 |
|
1422 | 1379 |
} |
1423 | 1380 |
|
1424 |
public void validateRow(IRow row,int sourceType) throws EditionException {
|
|
1381 |
public void validateRow(IRow row,int sourceType) throws ValidateRowException {
|
|
1425 | 1382 |
for (int i = 0; i < rules.size(); i++) { |
1426 | 1383 |
IRule rule = (IRule) rules.get(i); |
1427 | 1384 |
boolean bAux = rule.validate(row,sourceType); |
1428 | 1385 |
if (bAux == false) { |
1429 |
EditionException ex = new EditionException( |
|
1430 |
"NOT follow the rule: " + rule.getDescription()); |
|
1386 |
ValidateRowException ex = new ValidateRowException(writer.getName(),null); |
|
1431 | 1387 |
// TODO: Lanzar una RuleException con datos como el registro |
1432 | 1388 |
// que no cumple, la regla que no lo ha cumplido, etc. |
1433 | 1389 |
throw ex; |
... | ... | |
1443 | 1399 |
this.rules = rules; |
1444 | 1400 |
} |
1445 | 1401 |
|
1446 |
private void clean() throws IOException, DriverException { |
|
1447 |
expansionFile.close(); |
|
1402 |
private void clean() throws ReadDriverException { |
|
1403 |
try { |
|
1404 |
expansionFile.close(); |
|
1405 |
} catch (CloseExpansionFileException e) { |
|
1406 |
throw new ReadDriverException(getRecordset().getDriver().getName(),e); |
|
1407 |
} |
|
1448 | 1408 |
relations.clear(); |
1449 | 1409 |
numAdd = 0; |
1450 | 1410 |
delRows.clear(); |
... | ... | |
1527 | 1487 |
return newRow; |
1528 | 1488 |
} |
1529 | 1489 |
|
1530 |
public void removeField(String fieldName) throws EditionException {
|
|
1490 |
public void removeField(String fieldName) throws WriteDriverException, ReadDriverException {
|
|
1531 | 1491 |
|
1532 | 1492 |
InternalField fld = findFieldByName(fieldName); |
1533 | 1493 |
if (fld == null) |
1534 |
throw new EditionException("Field " + fieldName + " not found when removing field"); |
|
1494 |
throw new WriteDriverException(getRecordset().getDriver().getName(),null); |
|
1495 |
//throw new WriteDriverException("Field " + fieldName + " not found when removing field"); |
|
1535 | 1496 |
Command command = new RemoveFieldCommand(this, fld); |
1536 | 1497 |
if (complex) { |
1537 | 1498 |
commands.add(command); |
... | ... | |
1554 | 1515 |
return null; |
1555 | 1516 |
} |
1556 | 1517 |
|
1557 |
public void undoRemoveField(InternalField field) throws EditionException { |
|
1518 |
public void undoRemoveField(InternalField field) throws EditionCommandException {
|
|
1558 | 1519 |
// field.setDeleted(false); |
1559 | 1520 |
// field.setFieldIndex(actualFields.size()); |
1560 | 1521 |
actualFields.put(field.getFieldId(), field); |
1561 |
fieldsChanged(); |
|
1522 |
try { |
|
1523 |
fieldsChanged(); |
|
1524 |
} catch (ReadDriverException e) { |
|
1525 |
throw new EditionCommandException(writer.getName(),e); |
|
1526 |
} |
|
1562 | 1527 |
fireAfterFieldAdded(field.getFieldDesc()); |
1563 | 1528 |
} |
1564 | 1529 |
|
1565 |
public void doRemoveField(InternalField field) throws EditionException {
|
|
1530 |
public void doRemoveField(InternalField field) throws ReadDriverException {
|
|
1566 | 1531 |
boolean cancel = fireBeforeRemoveField(field.getFieldDesc()); |
1567 | 1532 |
if (cancel) return; |
1568 | 1533 |
actualFields.remove(field.getFieldId()); |
... | ... | |
1570 | 1535 |
fireAfterFieldRemoved(field.getFieldDesc()); |
1571 | 1536 |
} |
1572 | 1537 |
|
1573 |
public void renameField(String antName, String newName) throws EditionException {
|
|
1538 |
public void renameField(String antName, String newName) throws ReadDriverException{
|
|
1574 | 1539 |
|
1575 | 1540 |
InternalField fld = findFieldByName(antName); |
1576 | 1541 |
Command command = new RenameFieldCommand(this, fld, newName); |
... | ... | |
1583 | 1548 |
|
1584 | 1549 |
} |
1585 | 1550 |
|
1586 |
public void undoRenameField(InternalField field, String antName) throws EditionException {
|
|
1551 |
public void undoRenameField(InternalField field, String antName) throws EditionCommandException{
|
|
1587 | 1552 |
field.getFieldDesc().setFieldAlias(antName); |
1588 |
fieldsChanged(); |
|
1553 |
try { |
|
1554 |
fieldsChanged(); |
|
1555 |
} catch (ReadDriverException e) { |
|
1556 |
throw new EditionCommandException(writer.getName(),e); |
|
1557 |
} |
|
1589 | 1558 |
fireAfterFieldModified(field.getFieldDesc()); |
1590 | 1559 |
|
1591 | 1560 |
} |
1592 | 1561 |
|
1593 |
public void doRenameField(InternalField field, String newName) throws EditionException {
|
|
1562 |
public void doRenameField(InternalField field, String newName) throws ReadDriverException{
|
|
1594 | 1563 |
field.getFieldDesc().setFieldAlias(newName); |
1595 | 1564 |
fieldsChanged(); |
1596 | 1565 |
fireAfterFieldModified(field.getFieldDesc()); |
... | ... | |
1598 | 1567 |
} |
1599 | 1568 |
|
1600 | 1569 |
|
1601 |
public void addField(FieldDescription field) throws EditionException {
|
|
1570 |
public void addField(FieldDescription field) throws ReadDriverException {
|
|
1602 | 1571 |
|
1603 | 1572 |
InternalField fld = new InternalField(field, InternalField.ADDED, new Integer(listFields.size())); |
1604 | 1573 |
Command command = new AddFieldCommand(this, fld); |
... | ... | |
1612 | 1581 |
|
1613 | 1582 |
} |
1614 | 1583 |
|
1615 |
public void undoAddField(InternalField field) throws EditionException {
|
|
1584 |
public void undoAddField(InternalField field) throws EditionCommandException {
|
|
1616 | 1585 |
boolean cancel = fireBeforeRemoveField(field.getFieldDesc()); |
1617 | 1586 |
if (cancel) |
1618 | 1587 |
return; |
1619 | 1588 |
|
1620 | 1589 |
// field.setDeleted(true); |
1621 | 1590 |
actualFields.remove(field.getFieldId()); |
1622 |
fieldsChanged(); |
|
1591 |
try { |
|
1592 |
fieldsChanged(); |
|
1593 |
} catch (ReadDriverException e) { |
|
1594 |
throw new EditionCommandException(writer.getName(),e); |
|
1595 |
} |
|
1623 | 1596 |
fireAfterFieldRemoved(field.getFieldDesc()); |
1624 | 1597 |
|
1625 | 1598 |
} |
1626 | 1599 |
|
1627 |
public int doAddField(InternalField field) throws EditionException {
|
|
1600 |
public int doAddField(InternalField field) throws ReadDriverException {
|
|
1628 | 1601 |
boolean cancel; |
1629 | 1602 |
cancel = fireBeforeFieldAdded(field.getFieldDesc()); |
1630 | 1603 |
if (cancel) |
Also available in: Unified diff