Changeset 6757


Ignore:
Timestamp:
Feb 23, 2015, 9:25:00 AM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #1325: Lists of items (similar funcion as biomaterial lists)

Added update script for moving existing biomaterial lists to item lists. ID values are re-used. The old database tables are removed and property filters on biomaterial lists are updated to filter on item lists instead.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Install.java

    r6756 r6757  
    118118    method.
    119119  */
    120   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(119).intValue();
     120  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(120).intValue();
    121121 
    122122  public static synchronized int createTables(SchemaGenerator.Mode mode, ProgressReporter progress,
  • trunk/src/core/net/sf/basedb/core/Update.java

    r6728 r6757  
    217217    </td>
    218218  </tr>
     219  <tr>
     220    <td>120</td>
     221    <td>
     222      Added {@link ItemListData} and removed <code>BioMaterialListData</code>.
     223      The update will convert all existing biomaterial lists to item lists
     224      and make other changes as are requried to keep things working.
     225    </td>
     226  </tr>
    219227  </table>
    220228
     
    343351        // Schemaversion 118-119 only updates the version number
    344352        schemaVersion = setSchemaVersionInTransaction(session, 119);
     353        progress_current += 2 * progress_step;
     354      }
     355
     356      if (schemaVersion < 120)
     357      {
     358        if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 120...");
     359        schemaVersion = updateToSchemaVersion120(session);
    345360        progress_current += progress_step;
    346361      }
    347 
     362     
    348363      sc.logout();
    349364      if (progress != null) progress.display(100, "Database updated successfully.");
     
    9971012 
    9981013  /**
     1014    Transfer existing biomaterial lists to item lists.
     1015    @return The new schema version (=120)
     1016  */
     1017  private static int updateToSchemaVersion120(org.hibernate.Session session)
     1018    throws BaseException
     1019  {
     1020    final int schemaVersion = 120;
     1021    org.hibernate.Transaction tx = null;
     1022   
     1023    try
     1024    {
     1025      tx = HibernateUtil.newTransaction(session);
     1026     
     1027      String[] itemListFields = {
     1028        "[id]", "[version]", "[external_id]", "[member_type]", "[size]",
     1029        "[annotationset_id]", "[name]", "[description]", "[removed]",
     1030        "[itemkey_id]", "[projectkey_id]", "[owner]"
     1031      };
     1032     
     1033      String combinedListFields = Values.getString(Arrays.asList(itemListFields), ", ", true);
     1034     
     1035      String transferSql = "insert into [ItemLists] (" + combinedListFields + ") " +
     1036          " select " + combinedListFields + " from [BioMaterialLists]";
     1037     
     1038      org.hibernate.Query query = HibernateUtil.createSqlQuery(session, transferSql);
     1039      int numLists = query.executeUpdate();
     1040   
     1041      transferSql = "insert into [ItemListMembers] ([list_id], [item_id]) " +
     1042          "select [list_id], [biomaterial_id] from [BioMaterialListMembers]";
     1043      query = HibernateUtil.createSqlQuery(session, transferSql);
     1044      int numMembers = query.executeUpdate();
     1045     
     1046      dropTable(session, "BioMaterialListMembers");
     1047      dropTable(session, "BioMaterialLists");
     1048     
     1049      // Fix property filters so they use the new property name (§itemLists)
     1050      String propertyFilterSql = "update [PropertyFilters] set [property] = :newValue where [property] = :oldValue";
     1051      query = HibernateUtil.createSqlQuery(session, propertyFilterSql);
     1052      // @bioMaterialLists --> §itemLists
     1053      query.setString("oldValue", "@bioMaterialLists");
     1054      query.setString("newValue", "§itemLists");
     1055      int numFilters = query.executeUpdate();
     1056
     1057      // @bioMaterial.bioMaterialLists --> $mbm.§itemLists
     1058      query.setString("oldValue", "@bioMaterial.bioMaterialLists");
     1059      query.setString("newValue", "$mbm.§itemLists");
     1060      numFilters += query.executeUpdate();
     1061
     1062      // Update the schema version number
     1063      setSchemaVersion(session, schemaVersion);
     1064
     1065      // Commit the changes
     1066      HibernateUtil.commit(tx);
     1067      log.info("updateToSchemaVersion120: OK");
     1068    }
     1069    catch (RuntimeException ex)
     1070    {
     1071      if (tx != null) HibernateUtil.rollback(tx);
     1072      log.error("updateToSchemaVersion120: FAILED", ex);
     1073      throw ex;
     1074    }
     1075    return schemaVersion;
     1076  }
     1077
     1078 
     1079  /**
    9991080    Vefify and update the remaining quantity of all biomaterials.
    10001081    @return The number of biomaterial fixed
     
    11841265
    11851266 
    1186   private static void dropTable(org.hibernate.Session session, String tableName, ProgressReporter progress)
     1267  private static void dropTable(org.hibernate.Session session, String tableName)
    11871268  {
    11881269    org.hibernate.Transaction tx = null;
     
    11911272    {
    11921273      log.debug("Dropping table: " + tableName);
    1193       progress.display(90, "  --drop table " + tableName);
    1194       tx = HibernateUtil.newTransaction(session);
     1274      tx = session.getTransaction().isActive() ? null : HibernateUtil.newTransaction(session);
    11951275      query = HibernateUtil.getPredefinedSQLQuery(session, "DROP_TABLE", tableName);
    11961276      query.executeUpdate();
    1197       HibernateUtil.commit(tx);
     1277      // Only commit if we started a new transaction
     1278      if (tx != null) HibernateUtil.commit(tx);
    11981279    }
    11991280    catch (BaseException ex)
  • trunk/src/plugins/core/net/sf/basedb/plugins/AnnotationFlatFileImporter.java

    r6127 r6757  
    365365        for (Item item : Metadata.getAnnotatableItems())
    366366        {
    367           if (item.getDefinedPermissions() != null)
     367          if (item.getDefinedPermissions() != null && item != Item.BIOMATERIALLIST)
    368368          {
    369369            tmp.add(new GuiContext(item, GuiContext.Type.LIST));
Note: See TracChangeset for help on using the changeset viewer.