• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Changeset
  • Next Changeset →

Changeset 2575

Show
Ignore:
Timestamp:
07/01/08 20:02:11 (5 months ago)
Author:
jmoore
Message:

ticket:1002 - Further additions for pagination in getImages()

  • Added javadoc
  • Reworked PojosGetImagesQueryDefinition to use QueryBuilder
Location:
trunk/components
Files:
2 modified

  • common/src/ome/api/IPojos.java (modified) (2 diffs)
  • server/src/ome/services/query/PojosGetImagesQueryDefinition.java (modified) (2 diffs)

Legend:

Unmodified
Added
Removed
  • trunk/components/common/src/ome/api/IPojos.java

    r2049 r2575  
    305305    /** 
    306306     * Retrieve a user's (or all users') images within any given container. For 
    307      * example, all images in project. 
     307     * example, all images in project, applying temporal filtering or 
     308     * pagination. 
    308309     *  
    309310     * @param rootNodeType 
    … …  
    317318     *            OPTIONS: - startTime and/or endTime should be 
    318319     *            Timestamp.valueOf("YYYY-MM-DD hh:mm:ss.ms"); 
     320     *            <p> 
     321     *            "limit" and "offset" are applied at the Image-level. That is, 
     322     *            calling with Dataset.class, limit == 10 and offset == 0 will 
     323     *            first perform one query to get an effective set of 
     324     *            rootNodeIds, then getImages will be called with an effective 
     325     *            rootNodeType of Image.class and the new ids. 
     326     *            </p> 
    319327     * @return A set of images. 
     328     * @see ome.util.builders.PojoOptions#paginate(int, int) 
     329     * @see ome.util.builders.PojoOptions#startTime(java.sql.Timestamp) 
     330     * @see ome.util.builders.PojoOptions#endTime(java.sql.Timestamp) 
    320331     */ 
    321332    public <T extends IObject> Set<Image> getImages(@NotNull 
  • trunk/components/server/src/ome/services/query/PojosGetImagesQueryDefinition.java

    r2574 r2575  
    2323import ome.model.core.Image; 
    2424import ome.parameters.Parameters; 
     25import ome.tools.hibernate.QueryBuilder; 
    2526import ome.util.builders.PojoOptions; 
    2627 
    … …  
    4344        PojoOptions po = new PojoOptions((Map) value(OPTIONS)); 
    4445 
    45         StringBuilder sb = new StringBuilder(); 
    46         sb.append("select img from Image img "); 
    47         sb.append("left outer join fetch img.details.creationEvent "); 
    48         sb.append("left outer join fetch img.details.updateEvent "); 
    49         sb.append("left outer join fetch img.pixels as pix "); 
    50         sb.append("left outer join fetch pix.pixelsType as pt "); 
    51         sb.append("left outer join fetch pix.pixelsDimensions as pd "); 
    52         sb.append("left outer join fetch " 
    53                 + "img.annotationLinksCountPerOwner as i_c_ann "); 
    54         sb.append("left outer join fetch " 
    55                 + "img.datasetLinksCountPerOwner as i_c_ds "); 
    56  
    57         if (Dataset.class.isAssignableFrom(klass) 
    58                 || Project.class.isAssignableFrom(klass)) { 
    59             sb.append("join img.datasetLinks dil "); 
    60             sb.append("join dil.parent ds "); 
    61             // sb.append("left outer join fetch " 
    62             // + "ds.annotationLinksCountPerOwner as ds_c "); 
    63         } 
    64  
    65         if (Project.class.isAssignableFrom(klass)) { 
    66             sb.append("join ds.projectLinks pdl "); 
    67             sb.append("join pdl.parent prj "); 
    68             // sb.append("left outer join fetch " 
    69             // + "prj.annotationLinksCountPerOwner as prj_c "); 
    70         } 
    71  
    72         if (Category.class.isAssignableFrom(klass) 
    73                 || CategoryGroup.class.isAssignableFrom(klass)) { 
    74             sb.append("join img.categoryLinks cil "); 
    75             sb.append("join cil.parent cat "); 
    76             // sb.append("left outer join fetch " 
    77             // + "cat.annotationLinksCountPerOwner as cat_c "); 
    78         } 
    79  
    80         if (CategoryGroup.class.isAssignableFrom(klass)) { 
    81             sb.append("join cat.categoryGroupLinks cgcl "); 
    82             sb.append("join cgcl.parent cg "); 
    83             // sb.append("left outer join fetch " 
    84             // + "cgcl.annotationLinksCountPerOwner as cgcl_c "); 
    85         } 
    86  
    87         sb.append("where "); 
    88  
    89         // if PojoOptions sets START_TIME and/or END_TIME 
    90         if (po.getStartTime() != null) { 
    91             sb.append("img.details.creationEvent.time > :starttime and "); 
    92             params.put("starttime", po.getStartTime()); 
    93         } 
    94         if (po.getEndTime() != null) { 
    95             sb.append("img.details.creationEvent.time < :endtime and "); 
    96             params.put("endtime", po.getEndTime()); 
    97         } 
     46        QueryBuilder qb = new QueryBuilder(256); 
     47        qb.select("img"); 
     48        qb.from("Image", "img"); 
     49        qb.join("img.details.creationEvent", "ce", true, true); 
     50        qb.join("img.details.updateEvent", "ue", true, true); 
     51        qb.join("img.pixels", "pix", true, true); 
     52        qb.join("pix.pixelsType", "pt", true, true); 
     53        qb.join("pix.pixelsDimensions", "pd", true, true); 
     54        qb.join("img.annotationLinksCountPerOwner", "i_c_ann", true, true); 
     55        qb.join("img.datasetLinksCountPerOwner", "i_c_ds", true, true); 
    9856 
    9957        // see https://trac.openmicroscopy.org.uk/omero/ticket/296 
    10058        if (Image.class.isAssignableFrom(klass)) { 
    101             sb.append("img.id in (:ids) "); 
     59            qb.where(); 
     60            qb.and("img.id in (:ids)"); 
    10261        } else if (Dataset.class.isAssignableFrom(klass)) { 
    103             sb.append("ds.id in (:ids)"); 
     62            qb.join("img.datasetLinks", "dil", false, false); 
     63            qb.join("dil.parent", "ds", false, false); 
     64            // ds.annotationLinksCountPerOwner, ds_c 
     65            qb.where(); 
     66            qb.and("ds.id in (:ids)"); 
    10467        } else if (Project.class.isAssignableFrom(klass)) { 
    105             sb.append("prj.id in (:ids)"); 
     68            qb.join("img.datasetLinks", "dil", false, false); 
     69            qb.join("dil.parent", "ds", false, false); 
     70            qb.join("ds.projectLinks", "pdl", false, false); 
     71            qb.join("pdl.parent", "prj", false, false); 
     72            // "prj.annotationLinksCountPerOwner as prj_c " 
     73            qb.where(); 
     74            qb.and("prj.id in (:ids)"); 
    10675        } else if (Category.class.isAssignableFrom(klass)) { 
    107             sb.append("cat.id in (:ids)"); 
     76            qb.join("img.categoryLinks", "cil", false, false); 
     77            qb.join("cil.parent", "cat", false, false); 
     78            // + "cat.annotationLinksCountPerOwner as cat_c "); 
     79            qb.where(); 
     80            qb.and("cat.id in (:ids)"); 
    10881        } else if (CategoryGroup.class.isAssignableFrom(klass)) { 
    109             sb.append("cg.id in (:ids)"); 
     82            qb.join("img.categoryLinks", "cil", false, false); 
     83            qb.join("cil.parent", "cat", false, false); 
     84            qb.join("cat.categoryGroupLinks", "cgcl", false, false); 
     85            qb.join("cgcl.parent", "cg", false, false); 
     86            // + "cgcl.annotationLinksCountPerOwner as cgcl_c "); 
     87            qb.where(); 
     88            qb.and("cg.id in (:ids)"); 
    11089        } else { 
    11190            throw new ApiUsageException("Query not implemented for " + klass); 
    11291        } 
    11392 
    114         org.hibernate.Query q = session.createQuery(sb.toString()); 
    115         for (String param : params.keySet()) { 
    116             q.setParameter(param, params.get(param)); 
     93        // if PojoOptions sets START_TIME and/or END_TIME 
     94        if (po.getStartTime() != null) { 
     95            qb.and("img.details.creationEvent.time > :starttime"); 
     96            qb.param("starttime", po.getStartTime()); 
     97        } 
     98        if (po.getEndTime() != null) { 
     99            qb.and("img.details.creationEvent.time < :endtime"); 
     100            qb.param("endtime", po.getEndTime()); 
    117101        } 
    118102 
    119         q.setParameterList("ids", ids); 
     103        qb.paramList("ids", ids); 
     104        org.hibernate.Query q = qb.query(session); 
    120105        setQuery(q); 
    121106    } 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/