Changeset 7122
- Timestamp:
- Apr 19, 2016, 1:00:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/AnnotationBatcher.java
r7121 r7122 39 39 import net.sf.basedb.core.snapshot.SnapshotManager; 40 40 import net.sf.basedb.util.EqualsHelper; 41 import net.sf.basedb.util.units.UnitConverter; 41 42 42 43 /** … … 334 335 335 336 CurrentAnnotationInfo info = new CurrentAnnotationInfo(at); 336 // info.id = at.getId();337 // info.valueType = at.getValueType();338 337 currentInfo.put(at.getId(), info); 339 338 } … … 511 510 else 512 511 { 512 // Check that values are allowed by annotation type 513 // and convert to the default unit if it is needed 514 UnitConverter converter = null; 515 if (unit != null && info.defaultUnit != null && !unit.equals(info.defaultUnit)) 516 { 517 // Two different unit, convert the values to the default unit 518 converter = info.defaultUnit.getUnitConverter(unit); 519 } 520 521 List<Object> convertedValues = new ArrayList<Object>(values.size()); 522 for (Object value : values) 523 { 524 if (value instanceof Number) 525 { 526 Number numericValue = (Number)value; 527 if (converter != null) 528 { 529 numericValue = converter.convertToSpecificUnit(numericValue.doubleValue()); 530 } 531 value = info.valueType.convertNumber(numericValue); 532 } 533 annotationType.validateAnnotationValue(value); 534 convertedValues.add(value); 535 } 536 513 537 if (infoIsForCurrentItem) 514 538 { 515 539 // Update the current annotation if the value(s) have changed 516 if (!EqualsHelper.invariantEquals( values, info.values))540 if (!EqualsHelper.invariantEquals(convertedValues, info.values)) 517 541 { 518 542 // Update … … 523 547 524 548 // Insert into **Values 525 for (Object v : values)549 for (Object v : convertedValues) 526 550 { 527 551 insertValues[info.valueType.ordinal()].addToBatch(info.valueId, v); … … 529 553 530 554 // Update last_update, unit, version in Annotations 531 updateAnnotations.addToBatch(info.version+1, info.unitId, batchDate, info.annotationId, info.version);555 updateAnnotations.addToBatch(info.version+1, unit != null ? unit.getId() : info.unitId, batchDate, info.annotationId, info.version); 532 556 } 533 557 } … … 541 565 542 566 // Insert into **Values 543 for (Object v : values)567 for (Object v : convertedValues) 544 568 { 545 569 insertValues[info.valueType.ordinal()].addToBatch(valueId, v); … … 579 603 } 580 604 605 /** 606 A flag indicating what type of change that was made to an 607 annotation as a result of calling 608 {@link AnnotationBatcher#setValues(AnnotationType, List, Unit)} 609 */ 581 610 public static enum Change 582 611 { 612 /** 613 The annotation was not changed. 614 */ 583 615 NO_CHANGE, 616 617 /** 618 A new annotation was created. 619 */ 584 620 ADDED, 621 622 /** 623 An existing annotation was updated. 624 */ 585 625 UPDATED, 626 627 /** 628 An existing annotation was deleted. 629 */ 586 630 DELETED; 587 631 } 588 589 /**590 Holds information about an annotation type.591 */592 /*593 static class AnnotationTypeInfo594 {595 int id;596 Type valueType;597 }598 */599 632 600 633 /** … … 614 647 final int annotationTypeId; 615 648 final Type valueType; 649 final Unit defaultUnit; 616 650 617 651 // Updated in setCurrentItem … … 625 659 final List<Object> values; 626 660 627 publicCurrentAnnotationInfo(AnnotationType at)661 CurrentAnnotationInfo(AnnotationType at) 628 662 { 629 663 this.annotationTypeId = at.getId(); 630 664 this.valueType = at.getValueType(); 665 this.defaultUnit = at.getDefaultUnit(); 631 666 this.values = new ArrayList<Object>(); 632 667 }
Note: See TracChangeset
for help on using the changeset viewer.