Changeset 2497


Ignore:
Timestamp:
Aug 8, 2006, 3:43:08 PM (16 years ago)
Author:
Nicklas Nordborg
Message:

Better performance when creating a root bioassayset by fetching the reporters in
the main query.

Location:
trunk/src/core/net/sf/basedb
Files:
4 edited

Legend:

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

    r2314 r2497  
    128128  /**
    129129    Get the reporter of the feature.
    130     This property is mapped in the hibernate-properties-AbstractFeatureData.xml file since
     130    This property is mapped in the hibernate-properties-FeatureData.xml file since
    131131    it must be mapped with a cascade="evict" which is not supported by XDoclet.
    132132  */
  • trunk/src/core/net/sf/basedb/core/query/Hql.java

    r2304 r2497  
    272272 
    273273  /**
    274     Same as <code>leftJoin(null, propert, joinedAlias, null)</code>
    275     @see #leftJoin(String, String, String, Restriction)
     274    Same as <code>leftJoin(null, propert, joinedAlias, null, false)</code>
     275    @see #leftJoin(String, String, String, Restriction, boolean)
    276276  */
    277277  public static Join leftJoin(String property, String joinedAlias)
    278278    throws InvalidDataException
    279279  {
    280     return leftJoin(null, property, joinedAlias, null);
     280    return leftJoin(null, property, joinedAlias, null, false);
    281281  }
    282282
     
    304304</pre>
    305305
     306    <p>
     307    The <code>fetch</code> parameter is used to fetch the joined data in the
     308    same query. This is useful to
     309    avoid subsequent queries to the database when you know that you are
     310    going to access the joined items in your code. If you are joining a
     311    collection the {@link Query#setFirstResult(int)} and {@link Query#setMaxResults(int)}
     312    shouldn't be used since the join will create multiple rows for the same
     313    root item.
     314
     315    @param alias The alias to resolve the property against, or null to resolve the
     316      property against the root entity
     317    @param property The property name of the associated entity (required)
     318    @param joinedAlias The alias to give the joined entity (required)
     319    @param on Optional extra restriction that is used in the <code>ON</code> clause
     320      of the generated query
     321    @param fetch If the joined items should be prefetched or not
     322    @return A join query element
     323    @throws InvalidDataException If the property or joined alias parameter
     324      are null or if any of the parameters contains invalid characters
     325  */
     326  public static Join leftJoin(String alias, String property, String joinedAlias, Restriction on, boolean fetch)
     327    throws InvalidDataException
     328  {
     329    if (property == null) throw new InvalidUseOfNullException("property");
     330    if (joinedAlias == null) throw new InvalidUseOfNullException("alias");
     331    if (!PROPERTY_REGEXP.matcher(property).matches())
     332    {
     333      throw new InvalidDataException("Property '"+property+"' has one or more invalid characters. Only a-z, A-Z, 0-9 and . is allowed.");
     334    }
     335    if (alias != null && !ALIAS_REGEXP.matcher(alias).matches())
     336    {
     337      throw new InvalidDataException("Alias '"+alias+"' has one or more invalid characters. Only a-z, A-Z and 0-9 is allowed.");
     338    }
     339    if (!ALIAS_REGEXP.matcher(joinedAlias).matches())
     340    {
     341      throw new InvalidDataException("Alias '"+joinedAlias+"' has one or more invalid characters. Only a-z, A-Z and 0-9 is allowed.");
     342    }
     343    return new HqlLeftJoin(alias, property, joinedAlias, on, fetch);
     344  }
     345
     346  /**
     347    Same as <code>rightJoin(null, propert, joinedAlias, null)</code>
     348    @see #rightJoin(String, String, String, Restriction)
     349  */
     350  public static Join rightJoin(String property, String joinedAlias)
     351    throws InvalidDataException
     352  {
     353    return rightJoin(null, property, joinedAlias, null);
     354  }
     355
     356  /**
     357    Create a right join query element. A right join selects all items
     358    from the joined association even if they don't have an associated item in
     359    the root entity. The property must reference an association to another
     360    item or collection of values.
     361
    306362    @param alias The alias to resolve the property against, or null to resolve the
    307363      property against the root entity
     
    314370      are null or if any of the parameters contains invalid characters
    315371  */
    316   public static Join leftJoin(String alias, String property, String joinedAlias, Restriction on)
     372  public static Join rightJoin(String alias, String property, String joinedAlias, Restriction on)
    317373    throws InvalidDataException
    318374  {
     
    331387      throw new InvalidDataException("Alias '"+joinedAlias+"' has one or more invalid characters. Only a-z, A-Z and 0-9 is allowed.");
    332388    }
    333     return new HqlLeftJoin(alias, property, joinedAlias, on);
    334   }
    335 
    336   /**
    337     Same as <code>rightJoin(null, propert, joinedAlias, null)</code>
    338     @see #rightJoin(String, String, String, Restriction)
    339   */
    340   public static Join rightJoin(String property, String joinedAlias)
    341     throws InvalidDataException
    342   {
    343     return rightJoin(null, property, joinedAlias, null);
    344   }
    345 
    346   /**
    347     Create a right join query element. A right join selects all items
    348     from the joined association even if they don't have an associated item in
    349     the root entity. The property must reference an association to another
    350     item or collection of values.
    351 
    352     @param alias The alias to resolve the property against, or null to resolve the
    353       property against the root entity
    354     @param property The property name of the associated entity (required)
    355     @param joinedAlias The alias to give the joined entity (required)
    356     @param on Optional extra restriction that is used in the <code>ON</code> clause
    357       of the generated query
    358     @return A join query element
    359     @throws InvalidDataException If the property or joined alias parameter
    360       are null or if any of the parameters contains invalid characters
    361   */
    362   public static Join rightJoin(String alias, String property, String joinedAlias, Restriction on)
    363     throws InvalidDataException
    364   {
    365     if (property == null) throw new InvalidUseOfNullException("property");
    366     if (joinedAlias == null) throw new InvalidUseOfNullException("alias");
    367     if (!PROPERTY_REGEXP.matcher(property).matches())
    368     {
    369       throw new InvalidDataException("Property '"+property+"' has one or more invalid characters. Only a-z, A-Z, 0-9 and . is allowed.");
    370     }
    371     if (alias != null && !ALIAS_REGEXP.matcher(alias).matches())
    372     {
    373       throw new InvalidDataException("Alias '"+alias+"' has one or more invalid characters. Only a-z, A-Z and 0-9 is allowed.");
    374     }
    375     if (!ALIAS_REGEXP.matcher(joinedAlias).matches())
    376     {
    377       throw new InvalidDataException("Alias '"+joinedAlias+"' has one or more invalid characters. Only a-z, A-Z and 0-9 is allowed.");
    378     }
    379389    return new HqlRightJoin(alias, property, joinedAlias, on);
    380390  }
  • trunk/src/core/net/sf/basedb/core/query/HqlLeftJoin.java

    r2304 r2497  
    4747  private final String joinedAlias;
    4848  private final Restriction on;
     49  private final boolean fetch;
    4950
    50   HqlLeftJoin(String alias, String property, String joinedAlias, Restriction on)
     51  HqlLeftJoin(String alias, String property, String joinedAlias, Restriction on, boolean fetch)
    5152  {
    5253    assert property != null : "property == null";
     
    5657    this.joinedAlias = joinedAlias;
    5758    this.on = on;
     59    this.fetch = fetch;
    5860  }
    5961
     
    6769    if (query.getQueryType() == QueryType.HQL)
    6870    {
    69       return "LEFT JOIN "+(alias == null ? query.getRootAlias() : alias) + "." + property + " " + joinedAlias +
     71      return "LEFT JOIN " + (fetch && !query.isCounting() ? "FETCH " : "") +
     72        (alias == null ? query.getRootAlias() : alias) + "." + property + " " + joinedAlias +
    7073        (on == null ? "" : " WITH " + on.toQl(query, dc));
    7174    }
  • trunk/src/core/net/sf/basedb/util/IntensityCalculatorUtil.java

    r2492 r2497  
    2424package net.sf.basedb.util;
    2525
     26import net.sf.basedb.core.DataQuery;
    2627import net.sf.basedb.core.DbControl;
     28import net.sf.basedb.core.Item;
    2729import net.sf.basedb.core.RawDataType;
    2830import net.sf.basedb.core.ArrayDesign;
     
    4648import net.sf.basedb.core.data.RawData;
    4749import net.sf.basedb.core.data.ReporterData;
     50import net.sf.basedb.core.query.Hql;
    4851import net.sf.basedb.core.query.Selects;
    4952import net.sf.basedb.core.query.Select;
     
    275278      progress.display(10, "Generating spot intensities (0 done)...");
    276279    }
     280   
     281    /*
     282    long total = -System.nanoTime();
     283    long calc = 0;
     284    long data = 0;
     285    long cnew = 0;
     286    long chit = 0;
     287    long batt = 0;
     288    long brep = 0;
     289    long braw = 0;
     290    */
     291   
    277292    for (RawBioAssay rba : rawBioAssays)
    278293    {
     
    286301   
    287302      // Load raw data for current raw bioassay
    288       DataResultIterator<RawData> rawData = rba.getRawData().iterate(dc);
     303      DataQuery<RawData> rawQuery = rba.getRawData();
     304      rawQuery.join(Hql.leftJoin(null, "reporter", Item.REPORTER.getAlias(), null, true));
     305      if (rba.getArrayDesign() != null)
     306      {
     307        rawQuery.join(Hql.leftJoin(null, "feature", Item.REPORTER.getAlias(), null, true));
     308      }
     309     
     310      DataResultIterator<RawData> rawData = rawQuery.iterate(dc);
     311      //data -= System.nanoTime();
    289312      while (rawData.hasNext())
    290313      {
     
    292315        int position = rd.getPosition();
    293316        ReporterData reporter = rd.getReporter();
     317        //data += System.nanoTime();
    294318       
    295319        // Calculate intensities
     320        //calc -= System.nanoTime();
    296321        float[] intensities = iCalc.calculateIntensities(rd);
     322        //calc += System.nanoTime();
     323       
    297324        if (intensities != null)
    298325        {
     
    300327          if (positionCache.containsKey(position))
    301328          {
     329            //chit -= System.nanoTime();
    302330            // A mapping already exists, check if same reporter
    303331            ReporterData cached = positionCache.get(position);
    304             if ((reporter == null && cached != null) || (reporter != null && !reporter.equals(cached)))
     332            int reporterId = reporter == null ? 0 : reporter.getId();
     333            int cachedId = cached == null ? 0 : cached.getId();
     334            if (reporterId != cachedId)
    305335            {
    306336              // Same position but different reporter, must assign different position
     
    330360              positionCache.put(position, reporter);
    331361            }
     362            //chit += System.nanoTime();
    332363          }
    333364          else
    334365          {
    335366            // New position, insert reporter mapping
     367            //brep -= System.nanoTime();
    336368            posBatcher.insert(position, reporter);
     369            //brep += System.nanoTime();
     370            //cnew -= System.nanoTime();
    337371            positionCache.put(position, reporter);
     372            //cnew += System.nanoTime();
    338373          }
     374          //braw -= System.nanoTime();
    339375          // Insert mapping to raw data spot
    340376          rawBatcher.insert(column, position, rd);
     377          //braw += System.nanoTime();
    341378          // Insert intensities
     379          //batt -= System.nanoTime();
    342380          spotBatcher.insert(column, position, intensities);
     381          //batt += System.nanoTime();
    343382        }
    344383        if (progress != null)
     
    351390          }
    352391        }
    353       }
     392        //data -= System.nanoTime();
     393      }
     394      //data += System.nanoTime();
    354395    }
    355396    if (progress != null) progress.display(100, "Generating spot intensities ("+totalSpots+" done)...\n");
    356397
     398    //total += System.nanoTime();
     399
     400    /*
     401    System.out.println("Total time: " + (total / 1000000) + " ms");
     402    System.out.println("Intensity : " + (calc / 1000000) + " ms");
     403    System.out.println("Load data : " + (data / 1000000) + " ms");
     404    System.out.println("New pos   : " + (cnew / 1000000) + " ms");
     405    System.out.println("Cached pos: " + (chit / 1000000) + " ms");
     406    System.out.println("Batch data: " + (batt / 1000000) + " ms");
     407    System.out.println("Batch rep : " + (brep / 1000000) + " ms");
     408    System.out.println("Batch raw : " + (braw / 1000000) + " ms");
     409    */
     410   
    357411    // Close batchers and clean up
    358412    positionCache.clear();
Note: See TracChangeset for help on using the changeset viewer.