Changeset 6084
- Timestamp:
- Aug 16, 2012, 11:06:41 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/common-queries.xml
r6082 r6084 3390 3390 </description> 3391 3391 </query> 3392 3393 <query id="COPY_PARENT_PHYSICAL_BIOASSAYS" type="SQL"> 3394 <sql> 3395 INSERT INTO [ParentPhysicalBioAssays] ([physicalbioassay_id], [derivedbioassay_id]) 3396 SELECT [bioassay_id], [id] FROM [DerivedBioAssays] 3397 </sql> 3398 <description> 3399 An SQL query that copy the parent physical bioassays 3400 to the new (in BASE 3.2) ParentPhysicalBioAssays table 3401 </description> 3402 </query> 3403 3404 3405 <query id="COPY_PARENT_DERIVED_BIOASSAYS" type="SQL"> 3406 <sql> 3407 INSERT INTO [ParentDerivedBioAssays] ([parentbioassay_id], [derivedbioassay_id]) 3408 SELECT [parent_id], [id] FROM [DerivedBioAssays] WHERE NOT [parent_id] IS NULL 3409 </sql> 3410 <description> 3411 An SQL query that copy the parent derived bioassays 3412 to the new (in BASE 3.2) ParentDerivedBioAssays table 3413 </description> 3414 </query> 3415 3416 <query id="SET_ISROOT_ON_DERIVED_BIOASSAYS" type="SQL"> 3417 <sql> 3418 UPDATE [DerivedBioAssays] SET [is_root] = ([parent_id] IS NULL) 3419 </sql> 3420 <description> 3421 An SQL query that set the is_root property on DerivedBioAssays table. 3422 </description> 3423 </query> 3424 3392 3425 3393 3426 </predefined-queries> -
trunk/src/core/net/sf/basedb/core/Install.java
r6082 r6084 119 119 method. 120 120 */ 121 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(1 09).intValue();121 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(110).intValue(); 122 122 123 123 public static synchronized int createTables(SchemaGenerator.Mode mode, ProgressReporter progress, -
trunk/src/core/net/sf/basedb/core/Update.java
r6082 r6084 151 151 </tr> 152 152 <tr> 153 <td>109 </td>153 <td>109 and 110</td> 154 154 <td> 155 155 Added {@link DerivedBioAssayData#getPhysicalBioAssays()} and {@link DerivedBioAssayData#getParents()} 156 156 and removed <code>DerivedBioAssayData.getPhysicalBioAssay()</code> and 157 <code>DerivedBioAssayData.getParent()</code>. Existing derived bioassays are updated. 157 <code>DerivedBioAssayData.getParent()</code>. Existing derived bioassays are updated in a two-step 158 procedure. The first step is to copy existing information to the new tables and the second step is 159 to drop columns that are no longer needed. 158 160 </td> 159 161 </tr> … … 250 252 if (schemaVersion < 109) 251 253 { 252 if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 1 09...");253 schemaVersion = updateToSchemaVersion1 09(session);254 if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 110..."); 255 schemaVersion = updateToSchemaVersion110(session, schemaVersion); 254 256 progress_current += progress_step; 255 257 } … … 626 628 old columns in the DerivedBioAssays table. 627 629 628 @return The new schema version (=1 09)630 @return The new schema version (=110) 629 631 */ 630 private static int updateToSchemaVersion1 09(org.hibernate.Session session)632 private static int updateToSchemaVersion110(org.hibernate.Session session, int currentSchemaVersion) 631 633 throws BaseException 632 634 { 633 final int schemaVersion = 109; 634 try 635 { 636 637 // TODO - 1707 638 635 final int schemaVersion = 110; 636 try 637 { 638 if (currentSchemaVersion < 109) 639 { 640 // First step is to copy existing information to the new tables 641 org.hibernate.Transaction tx = null; 642 try 643 { 644 tx = HibernateUtil.newTransaction(session); 645 646 // Copy parent physical and derived bioassay information to the 647 // new tables: ParentPhysicalBioAssays and ParentDerivedBioAssays 648 org.hibernate.Query query = HibernateUtil.getPredefinedSQLQuery(session, "COPY_PARENT_PHYSICAL_BIOASSAYS"); 649 /* 650 INSERT INTO ParentPhysicalBioAssays (physicalbioassay_id, derivedbioassay_id) 651 SELECT bioassay_id, id FROM DerivedBioAssays 652 */ 653 query.executeUpdate(); 654 query = HibernateUtil.getPredefinedSQLQuery(session, "COPY_PARENT_DERIVED_BIOASSAYS"); 655 /* 656 INSERT INTO ParentDerivedBioAssays (parentbioassay_id, derivedbioassay_id) 657 SELECT parent_id, id FROM DerivedBioAssays WHERE NOT parent_id IS NULL 658 */ 659 query.executeUpdate(); 660 661 // Set is_root flag on derived bioassays 662 query = HibernateUtil.getPredefinedSQLQuery(session, "SET_ISROOT_ON_DERIVED_BIOASSAYS"); 663 /* 664 UPDATE DerivedBioAssays SET is_root = (parent_id IS NULL) 665 */ 666 query.executeUpdate(); 667 668 // Remove table filters, etc. that use the old properties 669 cleanContextFromProperty(session, Item.DERIVEDBIOASSAY, "physicalBioAssay", null, true); 670 cleanContextFromProperty(session, Item.DERIVEDBIOASSAY, "parent", null, true); 671 672 setSchemaVersion(session, 109); 673 674 // Commit the changes 675 HibernateUtil.commit(tx); 676 } 677 finally 678 { 679 if (tx != null && !tx.wasCommitted()) HibernateUtil.rollback(tx); 680 } 681 } 682 683 // Second step is to drop the old columns that are no longer used in BASE 3.2 684 dropColumn(session, "DerivedBioAssays", "parent_id", null); 685 dropColumn(session, "DerivedBioAssays", "bioassay_id", null); 686 639 687 // Update the schema version number 640 688 setSchemaVersionInTransaction(session, schemaVersion); 641 689 642 log.info("updateToSchemaVersion109: OK"); 643 } 644 catch (BaseException ex) 645 { 646 log.error("updateToSchemaVersion109: FAILED", ex); 690 log.info("updateToSchemaVersion110: OK"); 691 } 692 catch (SQLException ex) 693 { 694 log.error("updateToSchemaVersion110: FAILED", ex); 695 throw new BaseException(ex); 696 } 697 catch (RuntimeException ex) 698 { 699 log.error("updateToSchemaVersion110: FAILED", ex); 647 700 throw ex; 648 701 } … … 957 1010 } 958 1011 959 progress.display(90, " --alter table " + tableName + " drop column " + columnName); 1012 if (progress != null) 1013 { 1014 progress.display(90, " --alter table " + tableName + " drop column " + columnName); 1015 } 960 1016 query = HibernateUtil.getPredefinedSQLQuery(session, "DROP_COLUMN", tableName, columnName); 961 1017 query.executeUpdate(); … … 1118 1174 { 1119 1175 log.debug("Cleaning context for item: " + itemType + "; property=" + propertyName + "; replacement=" + replacementPropertyName); 1120 tx = HibernateUtil.newTransaction(session); 1176 tx = session.getTransaction().isActive() ? null : HibernateUtil.newTransaction(session); 1177 1121 1178 query = HibernateUtil.createQuery(session, "select ctx from ContextData ctx where ctx.itemType = " + itemType.getValue()); 1122 1179 List<ContextData> contexts = HibernateUtil.loadList(ContextData.class, query, null); … … 1148 1205 // Filter 1149 1206 Map<String, PropertyFilterData> filters = ctx.getPropertyFilters(); 1150 PropertyFilterData propertyFilter = filters.remove(propertyName); 1151 if (propertyFilter != null && replacementPropertyName != null && !forceRemoveFilter) 1152 { 1153 // Replace with new property 1154 filters.put(replacementPropertyName, propertyFilter); 1155 } 1156 1157 } 1158 1159 1160 HibernateUtil.commit(tx); 1161 } 1162 catch (BaseException ex) 1163 { 1207 List<String> filterProperties = new ArrayList<String>(filters.keySet()); 1208 for (String property : filterProperties) 1209 { 1210 if (property.startsWith(propertyName)) 1211 { 1212 PropertyFilterData old = filters.remove(property); 1213 if (replacementPropertyName != null) 1214 { 1215 filters.put(replacementPropertyName + property.substring(propertyName.length()), old); 1216 } 1217 } 1218 } 1219 } 1220 1221 // Only commit if we started a new transaction 1222 if (tx != null) HibernateUtil.commit(tx); 1223 } 1224 catch (RuntimeException ex) 1225 { 1226 // Only rollback if we started the transaction 1164 1227 if (tx != null) HibernateUtil.rollback(tx); 1165 1228 throw ex; -
trunk/www/views/derivedbioassays/index.jsp
r6082 r6084 83 83 { 84 84 // Register formatters 85 cc.setObject("export.formatter.&physicalBioAssays(name)", new NameableFormatter()); 86 cc.setObject("export.formatter.&parents(name)", new NameableFormatter()); 85 87 cc.setObject("export.formatter.&children(name)", new NameableFormatter()); 86 88 cc.setObject("export.formatter.&rawBioAssays(name)", new NameableFormatter()); … … 88 90 // Register dataloaders 89 91 String bioassayParameter = "bioassay"; 92 // Physical bioassays 93 ItemQuery<PhysicalBioAssay> physicalQuery = PhysicalBioAssay.getQuery(); 94 physicalQuery.include(cc.getInclude()); 95 physicalQuery.join(Hql.innerJoin("derivedBioAssays", "dba")); 96 physicalQuery.restrict(Restrictions.eq(Hql.alias("dba"), Expressions.parameter(bioassayParameter))); 97 physicalQuery.order(Orders.asc(Hql.property("name"))); 98 cc.setObject("export.dataloader.&physicalBioAssays(name)", new ItemQueryLoader(physicalQuery, bioassayParameter)); 99 100 // Parent bioassays 101 ItemQuery<DerivedBioAssay> parentQuery = DerivedBioAssay.getQuery(); 102 parentQuery.include(cc.getInclude()); 103 parentQuery.join(Hql.innerJoin("children", "c")); 104 parentQuery.restrict(Restrictions.eq(Hql.alias("c"), Expressions.parameter(bioassayParameter))); 105 parentQuery.order(Orders.asc(Hql.property("name"))); 106 cc.setObject("export.dataloader.&parents(name)", new ItemQueryLoader(parentQuery, bioassayParameter)); 107 90 108 // Child bioassays 91 ItemQuery<DerivedBioAssay> dbasQuery = DerivedBioAssay.getQuery(); 92 dbasQuery.include(cc.getInclude()); 93 dbasQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter(bioassayParameter))); 94 dbasQuery.order(Orders.asc(Hql.property("name"))); 95 cc.setObject("export.dataloader.&children(name)", new ItemQueryLoader(dbasQuery, bioassayParameter)); 109 ItemQuery<DerivedBioAssay> childQuery = DerivedBioAssay.getQuery(); 110 childQuery.include(cc.getInclude()); 111 childQuery.join(Hql.innerJoin("parents", "p")); 112 childQuery.restrict(Restrictions.eq(Hql.alias("p"), Expressions.parameter(bioassayParameter))); 113 childQuery.order(Orders.asc(Hql.property("name"))); 114 cc.setObject("export.dataloader.&children(name)", new ItemQueryLoader(childQuery, bioassayParameter)); 96 115 97 116 // Child raw bioassays -
trunk/www/views/physicalbioassays/index.jsp
r6082 r6084 96 96 ItemQuery<DerivedBioAssay> dbasQuery = DerivedBioAssay.getQuery(); 97 97 dbasQuery.include(cc.getInclude()); 98 dbasQuery.restrict(Restrictions.eq(Hql.property("physicalBioAssay"), Expressions.parameter(bioassayParameter))); 99 dbasQuery.restrict(Restrictions.eq(Hql.property("parent"), null)); 98 dbasQuery.join(Hql.innerJoin("physicalBioAssays", "pba")); 99 dbasQuery.restrict(Restrictions.eq(Hql.alias("pba"), Expressions.parameter(bioassayParameter))); 100 dbasQuery.restrict(Restrictions.eq(Hql.property("root"), Expressions.bool(true))); 100 101 dbasQuery.order(Orders.asc(Hql.property("name"))); 101 102 cc.setObject("export.dataloader.&rootDerivedBioAssays(name)", new ItemQueryLoader(dbasQuery, bioassayParameter));
Note: See TracChangeset
for help on using the changeset viewer.