Changeset 7121
- Timestamp:
- Apr 19, 2016, 8:56:43 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/config/dist/mysql-queries.xml
r6981 r7121 38 38 </query> 39 39 40 <query id="AB_INSERT_INTO_ANNOTATIONS" type="SQL"> 41 <sql> 42 INSERT INTO [Annotations] ([version], [annotationset_id], [annotationtype_id], [unit_id], [value_id], [last_update], [source]) 43 VALUES (0, ?, ?, ?, ?, ?, 0) 44 </sql> 45 <description> 46 SQL query for inserting rows into the Annotations table. 47 The primary key (id) must be auto-generated. 48 Parameters: annotationset_id, annotationtype_id, unit_id, value_id, last_updated 49 </description> 50 </query> 51 52 <query id="AB_INSERT_INTO_ANNOTATIONSETS" type="SQL"> 53 <sql> 54 INSERT INTO [AnnotationSets] ([version], [item_type], [item_id]) 55 VALUES (0, {1}, ?) 56 </sql> 57 <description> 58 SQL query for inserting rows into the AnnotationSets table. 59 The primary key (id) must be auto-generated. 60 Parameters: item_id 61 </description> 62 </query> 63 64 65 40 66 </predefined-queries> -
trunk/src/core/common-queries.xml
r7082 r7121 3582 3582 </query> 3583 3583 3584 <query id="AB_LOAD_ANNOTATION_INFO" type="SQL"> 3585 <sql> 3586 SELECT [annotationtype_id], [id], [version], [unit_id], [value_id], [last_update] 3587 FROM [Annotations] 3588 WHERE [annotationset_id] = :annotationSet AND [source] = 0 3589 </sql> 3590 <description> 3591 SQL query for loading current (primary) annotations for 3592 a given item. 3593 Used by the AnnotationBatcher as a SQL query via Hibernate. 3594 </description> 3595 </query> 3596 3597 <query id="AB_LOAD_ANNOTATION_VALUES" type="SQL"> 3598 <sql> 3599 SELECT [id], [value] 3600 FROM [{1}] 3601 WHERE [id] IN (:listOfIds) 3602 </sql> 3603 <description> 3604 SQL query for loading current annotation values 3605 for a given list of annotation value IDs. 3606 Used by the AnnotationBatcher as a SQL query via Hibernate. 3607 </description> 3608 </query> 3609 3610 <query id="AB_INSERT_INTO_PARAMETERVALUES" type="SQL"> 3611 <sql> 3612 INSERT INTO [ParameterValues] ([id], [discriminator], [version]) 3613 VALUES (nextval('hibernate_sequence'), ?, 0) 3614 </sql> 3615 <description> 3616 SQL query for inserting rows into the ParameterValues table. 3617 The primary key (id) must be auto-generated. 3618 Parameters: discriminator 3619 </description> 3620 </query> 3621 3622 <query id="AB_INSERT_INTO_ANNOTATIONS" type="SQL"> 3623 <sql> 3624 INSERT INTO [Annotations] ([id], [version], [annotationset_id], [annotationtype_id], [unit_id], [value_id], [last_update], [source]) 3625 VALUES (nextval('hibernate_sequence'), 0, ?, ?, ?, ?, ?, 0) 3626 </sql> 3627 <description> 3628 SQL query for inserting rows into the Annotations table. 3629 The primary key (id) must be auto-generated. 3630 Parameters: annotationset_id, annotationtype_id, unit_id, value_id, last_updated 3631 </description> 3632 </query> 3633 3634 <query id="AB_UPDATE_ANNOTATIONS" type="SQL"> 3635 <sql> 3636 UPDATE [Annotations] 3637 SET [version] = ?, [unit_id] = ?, [last_update] = ? 3638 WHERE [id] = ? AND [version] = ? 3639 </sql> 3640 <description> 3641 SQL query for updating rows into the Annotations table. 3642 Parameters: version (new), unit_id, last_updated, id, version (old) 3643 </description> 3644 </query> 3645 3646 <query id="AB_INSERT_INTO_ANNOTATIONSETS" type="SQL"> 3647 <sql> 3648 INSERT INTO [AnnotationSets] ([id], [version], [item_type], [item_id]) 3649 VALUES (nextval('hibernate_sequence'), 0, {1}, ?) 3650 </sql> 3651 <description> 3652 SQL query for inserting rows into the AnnotationSets table. 3653 The primary key (id) must be auto-generated. 3654 Parameters: item_id 3655 </description> 3656 </query> 3657 3658 <query id="AB_UPDATE_ITEMTABLE" type="SQL"> 3659 <sql> 3660 UPDATE [{1}] 3661 SET [annotationset_id] = ? 3662 WHERE [id] = ? 3663 </sql> 3664 <description> 3665 SQL query for updating the annotationset_id column in any 3666 table it exists in. 3667 Parameters: annotationset_id, item_id 3668 </description> 3669 </query> 3670 3671 <query id="AB_NULLIFY_CLONED_ANNOTATIONS" type="SQL"> 3672 <sql> 3673 UPDATE [Annotations] 3674 SET [inherited_id] = null 3675 WHERE [inherited_id] = ? and [source] = 2 3676 </sql> 3677 <description> 3678 SQL query for setting the 'inherited_id' column to null 3679 for cloned annotations that reference the annotation that 3680 is about to be deleted. 3681 Parameters: inherited_id 3682 </description> 3683 </query> 3684 3685 <query id="AB_DELETE_INHERITED_ANNOTATIONS" type="SQL"> 3686 <sql> 3687 DELETE FROM [Annotations] 3688 WHERE [inherited_id] = ? and [source] = 1 3689 </sql> 3690 <description> 3691 SQL query for deleting inherited annotations that reference 3692 the annotation that is about to be deleted. 3693 Parameters: inherited_id 3694 </description> 3695 </query> 3696 3697 <query id="AB_DELETE_FROM_ANNOTATIONS" type="SQL"> 3698 <sql> 3699 DELETE FROM [Annotations] 3700 WHERE [id] = ? 3701 </sql> 3702 <description> 3703 SQL query for deleting an annotation with a given id. 3704 Used by the AnnotationBatcher as a PreparedStatement. 3705 Parameters: id 3706 </description> 3707 </query> 3708 3709 <query id="AB_DELETE_FROM_PARAMETERVALUES" type="SQL"> 3710 <sql> 3711 DELETE FROM [ParameterValues] WHERE [id] = ? 3712 </sql> 3713 <description> 3714 SQL query for deleting a parameter value with a given id. 3715 Used by the AnnotationBatcher as a PreparedStatement. 3716 </description> 3717 </query> 3718 3719 <query id="AB_DELETE_FROM_VALUES" type="SQL"> 3720 <sql> 3721 DELETE FROM [{1}] WHERE [id] = ? 3722 </sql> 3723 <description> 3724 SQL query for deleting all actual annotation values with a given id. 3725 The {1} parameter is the table the value are stored in, eg. StringValues, 3726 IntegerValues, FloatValues, etc. 3727 Used by the AnnotationBatcher as a PreparedStatement. 3728 </description> 3729 </query> 3730 3731 <query id="AB_INSERT_INTO_VALUES" type="SQL"> 3732 <sql> 3733 INSERT INTO [{1}] ([id], [value]) VALUES (?, ?) 3734 </sql> 3735 <description> 3736 SQL query for inserting annotation values in their respective 3737 table (eg. StringValues, IntegerValues, FloatValues, etc.). 3738 Used by the AnnotationBatcher as a PreparedStatement. 3739 </description> 3740 </query> 3584 3741 3585 3742 </predefined-queries> -
trunk/src/core/net/sf/basedb/core/BasicItem.java
r7082 r7121 281 281 { 282 282 return 0; 283 } 284 285 private boolean hasBeenCalledFromGetAnnotationSet = false; 286 private boolean hasBeenCalledFromAnnotationBatcher = false; 287 288 /** 289 Annotatable items that are used with the {@link AnnotationBatcher} 290 must not call {@link Annotatable#getAnnotationSet()} in the same 291 transaction. This method is a helper method for keeping track of 292 which method that has been called. 293 @param annotationSet TRUE when called from the getAnnotationSet method 294 @param batcher TRUE when called from the batcher 295 @since 3.8 296 */ 297 void checkBatchAnnotatableUsage(boolean annotationSet, boolean batcher) 298 { 299 if (annotationSet) 300 { 301 if (hasBeenCalledFromAnnotationBatcher) 302 { 303 throw new IllegalStateException("Can't call getAnnotationSet() after the item has been used with an AnnotationBatcher: " + this); 304 } 305 hasBeenCalledFromGetAnnotationSet = true; 306 } 307 if (batcher) 308 { 309 if (hasBeenCalledFromGetAnnotationSet) 310 { 311 throw new IllegalStateException("Can't use with AnnotationBatcher after getAnnotationSet() has been called: " + this); 312 } 313 if (hasBeenCalledFromAnnotationBatcher) 314 { 315 throw new IllegalStateException("Can't use an item more than once with an AnnotationBatcher: " + this); 316 } 317 hasBeenCalledFromAnnotationBatcher = true; 318 } 283 319 } 284 320 -
trunk/src/plugins/core/net/sf/basedb/plugins/AnnotationFlatFileImporter.java
r7120 r7121 42 42 import net.sf.basedb.core.Annotatable; 43 43 import net.sf.basedb.core.Annotation; 44 import net.sf.basedb.core.AnnotationBatcher; 45 import net.sf.basedb.core.AnnotationBatcher.Change; 44 46 import net.sf.basedb.core.AnnotationSet; 45 47 import net.sf.basedb.core.AnnotationType; … … 594 596 private List<String> columnHeaders; 595 597 private DbControl dc; 598 private AnnotationBatcher batcher; 599 596 600 private UnitCache unitCache; 597 601 private FlatFileParser ffp; … … 746 750 ++i; 747 751 } 752 batcher = new AnnotationBatcher(dc, itemType); 753 batcher.addAnnotationTypes(mappers.values()); 748 754 749 755 // Include options … … 946 952 for (NewAnnotations na : n) 947 953 { 948 na.setNewAnnotations( addToUnlimited, replaceExisting, failIfTooManyValues, removeExisting);954 na.setNewAnnotations(batcher, addToUnlimited, replaceExisting, failIfTooManyValues, removeExisting); 949 955 if (na.getNumSet() == 0) numItems--; 950 956 numAnnotations += na.getNumSet(); … … 961 967 962 968 } 969 batcher.close(); 963 970 System.out.println(new Date()+": commit start"); 964 971 dc.commit(); 965 972 System.out.println(new Date()+": commit end"); 966 973 if (progress != null) progress.display(100, "Done"); 974 //if (true) throw new RuntimeException("success!!"); 967 975 } 968 976 } … … 1376 1384 the multiplicity settings allows, TRUE to throw an exception 1377 1385 */ 1378 void setNewAnnotations( boolean addToUnlimited, boolean replaceExisting,1386 void setNewAnnotations(AnnotationBatcher batcher, boolean addToUnlimited, boolean replaceExisting, 1379 1387 boolean failIfTooManyValues, boolean removeAnnotations) 1380 1388 { 1381 1389 if (values.size() == 0) return; 1382 1390 int numAnnotations = 0; 1383 AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null; 1391 // AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null; 1392 1393 batcher.setCurrentItem(item); 1394 1384 1395 for (Map.Entry<AnnotationType, List<AnnotationValue>> entry : values.entrySet()) 1385 1396 { 1386 1397 AnnotationType at = entry.getKey(); 1387 1398 List<AnnotationValue> newValues = entry.getValue(); 1399 1400 List<Object> theValues = new ArrayList<Object>(newValues.size()); 1401 for (AnnotationValue value : newValues) 1402 { 1403 Object theValue = value.value; 1404 theValues.add(theValue); 1405 } 1406 Change change = batcher.setValues(at, theValues, null); 1407 if (change == Change.DELETED) 1408 { 1409 numRemoved++; 1410 } 1411 else if (change == Change.ADDED ) 1412 { 1413 numSet += theValues.size(); 1414 } 1415 else if (change == Change.UPDATED) 1416 { 1417 numSet += theValues.size(); 1418 numReplaced += theValues.size(); 1419 } 1420 1421 /* 1388 1422 int size = newValues.size(); 1389 1423 int multiplicity = at.getMultiplicity(); … … 1436 1470 } 1437 1471 } 1472 */ 1438 1473 } 1439 1474 }
Note: See TracChangeset
for help on using the changeset viewer.