Changeset 7125
- Timestamp:
- Apr 20, 2016, 8:28:12 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/AnnotationBatcher.java
r7124 r7125 29 29 import java.util.ArrayList; 30 30 import java.util.Collection; 31 import java.util.Collections; 31 32 import java.util.Date; 32 33 import java.util.HashMap; … … 147 148 private final List<Integer> snapshotsToDelete; 148 149 150 // Cache with unit converters so that we don't need to create 151 // new ones all the time 152 private final Map<String, UnitConverter> unitConvertes; 153 149 154 /** 150 155 Create a new batcher instance. … … 183 188 // Maps AnnotationType.id -> Annotation information 184 189 this.currentInfo = new HashMap<Integer, CurrentAnnotationInfo>(); 190 this.unitConvertes = new HashMap<String, UnitConverter>(); 185 191 186 192 this.allUpdateBatchers = new ArrayList<UpdateBatcher>(); … … 331 337 b.close(); 332 338 } 339 allUpdateBatchers.clear(); 333 340 for (InsertBatcher b : allInsertBatchers) 334 341 { 335 342 b.close(); 336 343 } 344 allInsertBatchers.clear(); 337 345 for (Integer id : snapshotsToDelete) 338 346 { 339 347 SnapshotManager.removeSnapshot(currentAnnotationSetId); 340 348 } 349 snapshotsToDelete.clear(); 350 unitConvertes.clear(); 351 currentInfo.clear(); 352 currentItem = null; 341 353 } 342 354 // --------------------------- … … 360 372 } 361 373 374 /** 375 Get/create a unit converter for converting between two units. 376 */ 377 private UnitConverter getUnitConverter(Unit from, Unit to) 378 { 379 String key = from.getId() + ":" + to.getId(); 380 UnitConverter converter = unitConvertes.get(key); 381 if (converter == null) 382 { 383 converter = to.getUnitConverter(from); 384 unitConvertes.put(key, converter); 385 } 386 return converter; 387 } 362 388 363 389 /** … … 519 545 520 546 /** 547 Add, update or delete a single-valued annotation. 548 See {@link #setValues(AnnotationType, List, Unit)} for 549 more information. 550 */ 551 public Change setValue(AnnotationType annotationType, Object value, Unit unit) 552 { 553 return setValues(annotationType, value == null ? null : Collections.singletonList(value), unit); 554 } 555 556 /** 521 557 Add, update or delete annotation values for the current item. 522 558 If the current item doesn't have any values for the annotation type … … 610 646 if (unit != null && info.defaultUnit != null && !unit.equals(info.defaultUnit)) 611 647 { 612 // Two different unit , convert the values to the default unit613 converter = info.defaultUnit.getUnitConverter(unit);648 // Two different units, convert the values to the default unit 649 converter = getUnitConverter(unit, info.defaultUnit); 614 650 } 615 651
Note: See TracChangeset
for help on using the changeset viewer.