Changeset 3136


Ignore:
Timestamp:
Feb 19, 2007, 11:11:51 AM (15 years ago)
Author:
Martin Svensson
Message:

Fixes #466 Remaining Quantity not displayed in extracts.

Location:
branches/2.2.2/src/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.2/src/core/common-queries.xml

    r3086 r3136  
    25232523  </query>
    25242524
    2525   <query id="GET_SUM_USED_QUANTITY_EVENTS" type="HQL">
    2526     <sql>
    2527       SELECT evt.bioMaterial, SUM(evt.usedQuantity)
     2525  <query id="GET_USED_QUANTITY_EVENTS" type="HQL">
     2526    <sql>
     2527      SELECT evt.bioMaterial, evt.usedQuantity
    25282528      FROM BioMaterialEventData evt
    2529       GROUP BY evt.bioMaterial
    2530     </sql>
    2531     <description>
    2532       A HQL query that loads the sum of the used quantity
    2533       grouped by the biomaterial for all BioMaterialEvent:s.
    2534     </description>
    2535   </query>
    2536  
    2537   <query id="GET_SUM_USED_QUANTITY_SOURCES" type="HQL">
    2538     <sql>
    2539       SELECT index(src), SUM(src.usedQuantity)
     2529    </sql>
     2530    <description>
     2531      A HQL query that loads the biomaterial and the used quantity
     2532      for all BioMaterialEvent:s.
     2533    </description>
     2534  </query>
     2535 
     2536  <query id="GET_USED_QUANTITY_SOURCES" type="HQL">
     2537    <sql>
     2538      SELECT index(src), src.usedQuantity
    25402539      FROM BioMaterialEventData evt
    25412540      JOIN evt.sources src
    2542       GROUP BY index(src)
    2543     </sql>
    2544     <description>
    2545       A HQL query that loads the sum of the used quantity
    2546       grouped by the biomaterial for all sources to
    2547       BioMaterialEvent:s.
     2541    </sql>
     2542    <description>
     2543      A HQL query that loads the used quantity
     2544      for all sources to BioMaterialEvent:s.
    25482545    </description>
    25492546  </query>
  • branches/2.2.2/src/core/net/sf/basedb/core/Install.java

    r3086 r3136  
    102102    method.
    103103  */
    104   public static final int NEW_SCHEMA_VERSION = 29;
    105 
     104  public static final int NEW_SCHEMA_VERSION = 30;
     105 
    106106  public static synchronized void createTables(boolean update, final ProgressReporter progress)
    107107    throws BaseException
  • branches/2.2.2/src/core/net/sf/basedb/core/Update.java

    r3121 r3136  
    346346  <tr>
    347347    <td>29</td>
     348    <td>
     349      No changes at all except increasing the schema version number.
     350      The veryfication of remaining quantity is moved to next update of schema version.
     351    </td>
     352  </tr>
     353 
     354  <tr>
     355    <td>30</td>
    348356    <td>
    349357      No schema change as such, but we need to verify and possibly update the
     
    505513      }
    506514     
     515     
     516      if (schemaVersion < 30)
     517      {
     518        if (progress != null) progress.display((int)(29*progress_factor), "--Updating schema version: " + schemaVersion + " -> 30...");     
     519        schemaVersion = updateToSchemaVersion30(session);
     520      }
     521     
    507522      /*
    508       if (schemaVersion < 30)
    509       {
    510         if (progress != null) progress.display((int)(29*progress_factor), "--Updating schema version: " + schemaVersion + " -> 30...");
    511         schemaVersion = setSchemaVersionInTransaction(session, 30);
     523      if (schemaVersion < 31)
     524      {
     525        if (progress != null) progress.display((int)(30*progress_factor), "--Updating schema version: " + schemaVersion + " -> 30...");
     526        schemaVersion = setSchemaVersionInTransaction(session, 31);
    512527        - or -
    513         schemaVersion = updateToSchemaVersion30(session);
     528        schemaVersion = updateToSchemaVersion31(session);
    514529      }
    515530      ... etc...
     
    10711086  /**
    10721087    Vefify and update the remaining quantity of all biomaterials.
    1073     @return The new schema version (=29)
     1088    @return The new schema version (=30)
    10741089  */
    1075   private static int updateToSchemaVersion29(org.hibernate.Session session)
     1090  private static int updateToSchemaVersion30(org.hibernate.Session session)
    10761091    throws BaseException
    10771092  {
    1078     final int schemaVersion = 29;
     1093    final int schemaVersion = 30;
    10791094   
    10801095    org.hibernate.Transaction tx = null;
     
    10861101      Map<MeasuredBioMaterialData, Float> remaining = new HashMap<MeasuredBioMaterialData, Float>();
    10871102     
    1088       // Load sum of used quantity for all events
     1103      // Load used quantity for all events
    10891104      org.hibernate.Query eventQuery = HibernateUtil.getPredefinedQuery(session,
    1090         "GET_SUM_USED_QUANTITY_EVENTS");
    1091       /*
    1092         SELECT evt.bioMaterial, SUM(evt.usedQuantity)
    1093         FROM BioMaterialEventData evt
    1094         GROUP BY evt.bioMaterial
    1095       */
    1096       // Load sum of used quantity for sources to all events
     1105        "GET_USED_QUANTITY_EVENTS");
     1106        /*       
     1107          SELECT evt.bioMaterial, evt.usedQuantity
     1108          FROM BioMaterialEventData evt
     1109        */
     1110     
     1111      // Load used quantity for sources to all events
    10971112      org.hibernate.Query sourcesQuery = HibernateUtil.getPredefinedQuery(session,
    1098         "GET_SUM_USED_QUANTITY_SOURCES");
     1113        "GET_USED_QUANTITY_SOURCES");
    10991114        /*
    1100           SELECT index(src), SUM(src.usedQuantity)
     1115          SELECT index(src), src.usedQuantity
    11011116          FROM BioMaterialEventData evt
    1102           JOIN evt.sources src
    1103           GROUP BY index(src)
     1117          JOIN evt.sources src         
    11041118         */
    11051119      List<Object[]> events = HibernateUtil.loadList(Object[].class, eventQuery);
     
    11071121     
    11081122      // Calculate the remaining quantity for each biomaterial
    1109       // o[0] = biomaterial, o[1] = sum of used quantity
     1123      // o[0] = biomaterial, o[1] = used quantity     
    11101124      for (Object[] o : events)
    11111125      {
    1112         MeasuredBioMaterialData bioMaterial = (MeasuredBioMaterialData)o[0];
    1113         Double sumUsedQuantity = (Double)o[1];
    1114         if (sumUsedQuantity != null)
     1126        MeasuredBioMaterialData bioMaterial = (MeasuredBioMaterialData)o[0];       
     1127        Float usedQuantity = (Float)o[1];       
     1128        if (usedQuantity != null)
    11151129        {
    11161130          Float currentRemaining = remaining.get(bioMaterial);
    11171131          if (currentRemaining == null) currentRemaining = 0.0f;
    1118           currentRemaining = currentRemaining - sumUsedQuantity.floatValue();
     1132          currentRemaining = currentRemaining - usedQuantity;
    11191133          remaining.put(bioMaterial, currentRemaining);
    11201134        }
     
    11431157      // Commit the changes
    11441158      HibernateUtil.commit(tx);
    1145       log.info("updateToSchemaVersion29: OK");
     1159      log.info("updateToSchemaVersion30: OK");
    11461160    }
    11471161    catch (BaseException ex)
    11481162    {
    11491163      if (tx != null) HibernateUtil.rollback(tx);
    1150       log.error("updateToSchemaVersion29: FAILED", ex);
     1164      log.error("updateToSchemaVersion30: FAILED", ex);
    11511165      throw ex;
    11521166    }
Note: See TracChangeset for help on using the changeset viewer.