Changeset 5566


Ignore:
Timestamp:
Feb 9, 2011, 2:49:51 PM (11 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1573: Display number of free (used) wells on a plate (bioplate list view)

Location:
trunk
Files:
10 edited

Legend:

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

    r5525 r5566  
    38883888  </query>
    38893889
     3890  <query id="COUNT_FREE_WELLS_ON_BIOPLATE" type="HQL">
     3891    <sql>
     3892      SELECT pg.rows * pg.columns - COUNT(bm.id)
     3893      FROM BioPlateData bpl JOIN bpl.bioWells w
     3894      JOIN bpl.plateGeometry pg
     3895      LEFT JOIN w.bioMaterial bm
     3896      WHERE bpl.id = :bioPlateId
     3897      GROUP BY pg.rows, pg.columns
     3898    </sql>
     3899    <description>
     3900      A HQL query that counts the number of free wells on a given bioplate.
     3901    </description>
     3902  </query>
     3903
     3904  <query id="SET_FREE_WELLS_ON_BIOPLATE" type="HQL">
     3905    <sql>
     3906      UPDATE BioPlateData bpl
     3907      SET bpl.freeWells = :freeWells
     3908      WHERE bpl.id = :bioPlateId
     3909    </sql>
     3910    <description>
     3911      A HQL update query that sets the number of free wells for a given bioplate.
     3912    </description>
     3913  </query>
     3914
    38903915</predefined-queries>
  • trunk/src/core/net/sf/basedb/core/BioPlate.java

    r5565 r5566  
    9696    bp.setPlateGeometry(geometry);
    9797    bp.setBioPlateType(plateType);
    98     bp.setName("New bioplate");   
     98    bp.setName("New bioplate");
    9999    return bp;
    100100  }
     
    242242    plateGeometry.checkPermission(Permission.USE);
    243243    getData().setPlateGeometry(plateGeometry.getData());   
     244    getData().setFreeWells(plateGeometry.getColumns() * plateGeometry.getRows());
    244245  }
    245246
     
    400401
    401402  /**
     403    Get the number of free wells on this plate.
     404    @since 2.17
     405  */
     406  public int getFreeWells()
     407  {
     408    return getData().getFreeWells();
     409  }
     410 
     411  /**
     412    Get the number of used wells on this plate.
     413    @since 2.17
     414  */
     415  public int getUsedWells()
     416  {
     417    return getTotalWells() - getFreeWells();
     418  }
     419 
     420  /**
    402421    Get the total number of wells on this plate.
    403422    @since 2.17
     
    408427    return pg.getColumns() * pg.getRows();
    409428  }
    410  
    411   /**
    412     Get the number of used wells on this plate.
    413   */
    414   public int getUsedWells()
    415   {
    416     int counter = 0;
    417     for (BioWellData well : getData().getBioWells().values())
    418     {
    419       if (well.getBioMaterial() != null) ++counter;
    420     }
    421     return counter;
    422   }
    423  
     429
    424430  /**
    425431    Gets bio well for specific location.
  • trunk/src/core/net/sf/basedb/core/BioWell.java

    r5565 r5566  
    2626import net.sf.basedb.core.data.PlateCoordinate;
    2727import net.sf.basedb.core.data.SharedData;
    28 import net.sf.basedb.core.query.Expressions;
    2928import net.sf.basedb.core.query.Hql;
    3029import net.sf.basedb.core.query.Restrictions;
  • trunk/src/core/net/sf/basedb/core/Install.java

    r5559 r5566  
    115115    method.
    116116  */
    117   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(89).intValue();
     117  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(90).intValue();
    118118 
    119119  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • trunk/src/core/net/sf/basedb/core/MeasuredBioMaterial.java

    r5527 r5566  
    132132    else if (action == Transactional.Action.DELETE)
    133133    {
     134      if (getData().getBioWell() != null)
     135      {
     136        getData().getBioWell().getBioPlate().updateFreeWells(1);
     137      }
    134138      getCreationEvent().clearSources();
    135139      org.hibernate.Query query = HibernateUtil.getPredefinedQuery(getDbControl().getHibernateSession(),
     
    437441      lockMode.onAdd(newWell, myData);
    438442    }
    439     if (currentWell != null) currentWell.setBioMaterial(null);
    440     if (newWell != null) newWell.setBioMaterial(myData);
     443    if (currentWell != null)
     444    {
     445      currentWell.setBioMaterial(null);
     446      currentWell.getBioPlate().updateFreeWells(1);
     447    }
     448    if (newWell != null)
     449    {
     450      newWell.setBioMaterial(myData);
     451      newWell.getBioPlate().updateFreeWells(-1);
     452    }
    441453    myData.setBioWell(newWell);
    442454  }
  • trunk/src/core/net/sf/basedb/core/Update.java

    r5523 r5566  
    959959    </td>
    960960  </tr>
     961  <tr>
     962    <td>90</td>
     963    <td>
     964      Adds {@link BioPlateData#getFreeWells()}. The update will
     965      count the number of free wells on existing bio plates.
     966    </td>
     967  </tr>
    961968  </table>
    962969
     
    13161323            "--Updating schema version: " + schemaVersion + " -> 89...");
    13171324        schemaVersion = setSchemaVersionInTransaction(session, 89);
     1325      }
     1326     
     1327      if (schemaVersion < 90)
     1328      {
     1329        if (progress != null) progress.display((int)(89*progress_factor),
     1330            "--Updating schema version: " + schemaVersion + " -> 90...");
     1331        schemaVersion = updateToSchemaVersion90(session);
    13181332      }
    13191333
     
    30563070      if (tx != null) HibernateUtil.rollback(tx);
    30573071      log.error("updateToSchemaVersion86: FAILED", ex);
     3072      throw ex;
     3073    }
     3074    return schemaVersion;
     3075  }
     3076
     3077  /**
     3078    Calculate the value for BioPlateData.getFreeWells() for all existing bioplates.
     3079  */
     3080  private static int updateToSchemaVersion90(org.hibernate.Session session)
     3081    throws BaseException
     3082  {
     3083    final int schemaVersion = 90;
     3084    org.hibernate.Transaction tx = null;
     3085    try
     3086    {
     3087      tx = HibernateUtil.newTransaction(session);
     3088     
     3089      // Load bioplates with no info about free wells
     3090      org.hibernate.Query query = HibernateUtil.createQuery(session,
     3091        "SELECT bpl.id FROM BioPlateData bpl WHERE bpl.freeWells IS NULL");
     3092      List<Integer> plates = HibernateUtil.loadList(Integer.class, query, null);
     3093     
     3094      org.hibernate.Query countQuery = HibernateUtil.getPredefinedQuery(session, "COUNT_FREE_WELLS_ON_BIOPLATE");
     3095      /*
     3096        SELECT pg.rows * pg.columns - COUNT(bm.id)
     3097        FROM BioPlateData bpl JOIN bpl.bioWells w
     3098        JOIN bpl.plateGeometry pg
     3099        LEFT JOIN w.bioMaterial bm
     3100        WHERE bpl.id = :bioPlateId
     3101        GROUP BY pg.rows, pg.columns
     3102      */
     3103      org.hibernate.Query updateQuery = HibernateUtil.getPredefinedQuery(session, "SET_FREE_WELLS_ON_BIOPLATE");
     3104      /*
     3105        UPDATE BioPlateData bpl
     3106        SET bpl.freeWells = :freeWells
     3107        WHERE bpl.id = :bioPlateId
     3108       */
     3109      for (Integer plateId : plates)
     3110      {
     3111        countQuery.setInteger("bioPlateId", plateId);
     3112        Long freeWells = HibernateUtil.loadData(Long.class, countQuery);
     3113        updateQuery.setInteger("bioPlateId", plateId);
     3114        updateQuery.setInteger("freeWells", freeWells.intValue());
     3115        updateQuery.executeUpdate();
     3116      }
     3117     
     3118      // Update the schema version number
     3119      setSchemaVersion(session, schemaVersion);
     3120 
     3121      // Commit the changes
     3122      HibernateUtil.commit(tx);
     3123      log.info("updateToSchemaVersion90: OK");
     3124    }
     3125    catch (BaseException ex)
     3126    {
     3127      if (tx != null) HibernateUtil.rollback(tx);
     3128      log.error("updateToSchemaVersion90: FAILED", ex);
    30583129      throw ex;
    30593130    }
  • trunk/src/core/net/sf/basedb/core/data/BioPlateData.java

    r5525 r5566  
    141141    this.bioPlateType = bioPlateType;
    142142  }
     143 
     144  private int freeWells;
     145  /**
     146    Get the number of wells that are free on the bioplate.
     147    @since 2.17
     148    @hibernate.property column="`free_wells`" type="int" not-null="true"
     149  */
     150  public int getFreeWells()
     151  {
     152    return freeWells;
     153  }
     154  public void setFreeWells(int freeWells)
     155  {
     156    this.freeWells = freeWells;
     157  }
     158 
     159  /**
     160    Update the number of free wells with the given difference
     161    @since 2.17
     162  */
     163  public void updateFreeWells(int diff)
     164  {
     165    this.freeWells += diff;
     166  }
     167 
    143168 
    144169  private Map<PlateCoordinate, BioWellData> bioWells;
  • trunk/src/core/net/sf/basedb/core/data/BioWellData.java

    r5456 r5566  
    4141    The bioplate this well belongs to.
    4242    @see BioPlateData#getBioWells()
    43     @hibernate.many-to-one column="`bioplate_id`" not-null="true" outer-join="false" update="false"
     43    @hibernate.many-to-one column="`bioplate_id`" not-null="true" outer-join="false" update="false" cascade="all"
    4444  */
    4545  public BioPlateData getBioPlate()
  • trunk/www/biomaterials/bioplates/list_bioplates.jsp

    r5565 r5566  
    106106  geometryQuery.setCacheResult(true);
    107107 
    108   final ItemQuery<BioWell> usedWellQuery = BioWell.getQuery(null);
    109   usedWellQuery.join(Hql.innerJoin("bioMaterial", "bmt"));
    110  
    111108  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
    112109  annotationTypes = annotationTypeQuery.list(dc);
     
    512509              index++;
    513510              numListed++;
    514               int totalWells = item.getTotalWells();
    515               usedWellQuery.setEntityParameter("bioPlate", item);
    516               int usedWells = (int)usedWellQuery.count(dc);
    517511              %>
    518512              <tbl:row>
     
    560554                <tbl:cell column="barcode"><%=HTML.encodeTags(item.getBarcode())%></tbl:cell>
    561555                <tbl:cell column="destroyed"><%=item.isDestroyed()%></tbl:cell>
    562                 <tbl:cell column="freeWells"><%=totalWells - usedWells%> (<%=totalWells %>)</tbl:cell>
     556                <tbl:cell column="freeWells"><%=item.getFreeWells()%> (<%=item.getTotalWells()%>)</tbl:cell>
    563557                <tbl:cell column="owner"
    564558                  ><base:propertyvalue
  • trunk/www/biomaterials/bioplates/view_bioplate.jsp

    r5561 r5566  
    393393      </tr>
    394394      <tr>
     395        <td class="prompt">Free (total) wells</td>
     396        <td><%=bioplate.getFreeWells()%> (<%=bioplate.getTotalWells()%>)</td>
     397      </tr>
     398      <tr>
    395399        <td class="prompt">Freezer</td>
    396400        <td><base:propertyvalue item="<%=bioplate%>" property="freezer" /></td>
Note: See TracChangeset for help on using the changeset viewer.