• 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 2574

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

ticket:1002 - Working implementation of pagination for getImage(Dataset|Project)

  • Fixes tricky mistake in PojoOptions
  • Uses two queries to handle pagination
Location:
trunk/components
Files:
2 added
3 modified

  • model/src/ome/util/builders/PojoOptions.java (modified) (1 diff)
  • server/src/ome/logic/PojosImpl.java (modified) (4 diffs)
  • server/src/ome/services/query/PojosGetImagesQueryDefinition.java (modified) (3 diffs)
  • server/test/ome/server/itests/scalability (added)
  • server/test/ome/server/itests/scalability/PaginationTest.java (added)

Legend:

Unmodified
Added
Removed
  • trunk/components/model/src/ome/util/builders/PojoOptions.java

    r2563 r2574  
    6666    protected void copy(Map map) { 
    6767        String[] s = new String[] { LEAF, EXPERIMENTER, GROUP, START_TIME, 
    68                 END_TIME }; 
     68                END_TIME, OFFSET, LIMIT }; 
    6969        for (int i = 0; i < s.length; i++) { 
    7070            if (map.containsKey(s[i])) { 
  • trunk/components/server/src/ome/logic/PojosImpl.java

    r2320 r2574  
    1616 
    1717// Java imports 
     18import java.sql.SQLException; 
    1819import java.util.Collection; 
    1920import java.util.HashMap; 
    … …  
    6061import ome.util.builders.PojoOptions; 
    6162 
     63import org.hibernate.HibernateException; 
     64import org.hibernate.Session; 
    6265import org.jboss.annotation.ejb.LocalBinding; 
    6366import org.jboss.annotation.ejb.RemoteBinding; 
    6467import org.jboss.annotation.ejb.RemoteBindings; 
     68import org.springframework.orm.hibernate3.HibernateCallback; 
    6569import org.springframework.transaction.annotation.Transactional; 
    6670 
    … …  
    346350    } 
    347351 
    348     @RolesAllowed("user") 
    349     @Transactional(readOnly = true) 
    350     public Set getImages(Class rootNodeType, Set rootNodeIds, Map options) { 
     352    static final Map<Class, String> paginationQueries = new HashMap(); 
     353    static { 
     354        paginationQueries.put(Dataset.class, 
     355                "select link.child.id from DatasetImageLink " 
     356                        + " link where link.parent.id in (:ids)" 
     357                        + "order by link.child.id"); 
     358        paginationQueries 
     359                .put( 
     360                        Project.class, 
     361                        "select distinct dil.child.id from ProjectDatasetLink pdl " 
     362                                + "join pdl.child ds join ds.imageLinks as dil " 
     363                                + "where pdl.parent.id in (:ids) order by dil.child.id"); 
     364    } 
     365 
     366    @RolesAllowed("user") 
     367    @Transactional(readOnly = true) 
     368    @SuppressWarnings("unchecked") 
     369    public Set getImages(final Class rootNodeType, final Set rootNodeIds, 
     370            final Map options) { 
    351371 
    352372        if (rootNodeIds.size() == 0) { 
    … …  
    354374        } 
    355375 
    356         PojoOptions po = new PojoOptions(options); 
     376        final PojoOptions po = new PojoOptions(options); 
     377 
     378        // Effective values 
     379        Class effType = rootNodeType; 
     380        Set<Long> effIds = rootNodeIds; 
     381 
     382        if (po.isPagination()) { 
     383            final String query = paginationQueries.get(rootNodeType); 
     384            if (query == null) { 
     385                throw new ApiUsageException(rootNodeType.getName() 
     386                        + " does not support pagination yet."); 
     387            } 
     388            effType = Image.class; 
     389            effIds = new HashSet<Long>((List<Long>) iQuery 
     390                    .execute(new HibernateCallback() { 
     391                        public Object doInHibernate(Session s) 
     392                                throws HibernateException, SQLException { 
     393                            return s.createQuery(query).setParameterList("ids", 
     394                                    rootNodeIds).setMaxResults(po.getLimit()) 
     395                                    .setFirstResult(po.getOffset()).list(); 
     396                        } 
     397                    })); 
     398            if (effIds == null || effIds.size() == 0) { 
     399                return new HashSet(); 
     400            } 
     401        } 
    357402 
    358403        Query<List<IObject>> q = getQueryFactory().lookup( 
    359404                PojosGetImagesQueryDefinition.class.getName(), 
    360                 new Parameters().addIds(rootNodeIds).addClass(rootNodeType) 
    361                         .addOptions(po.map())); 
     405                new Parameters().addIds(effIds).addClass(effType).addOptions( 
     406                        po.map())); 
    362407 
    363408        List<IObject> l = iQuery.execute(q); 
  • trunk/components/server/src/ome/services/query/PojosGetImagesQueryDefinition.java

    r2052 r2574  
    4141        Class klass = (Class) value(CLASS); 
    4242        Collection ids = (Collection) value(IDS); 
     43        PojoOptions po = new PojoOptions((Map) value(OPTIONS)); 
    4344 
    4445        StringBuilder sb = new StringBuilder(); 
    … …  
    8788 
    8889        // if PojoOptions sets START_TIME and/or END_TIME 
    89         if (check(OPTIONS)) { 
    90             PojoOptions po = new PojoOptions((Map) value(OPTIONS)); 
    91             if (po.getStartTime() != null) { 
    92                 sb.append("img.details.creationEvent.time > :starttime and "); 
    93                 params.put("starttime", po.getStartTime()); 
    94             } 
    95             if (po.getEndTime() != null) { 
    96                 sb.append("img.details.creationEvent.time < :endtime and "); 
    97                 params.put("endtime", po.getEndTime()); 
    98             } 
     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()); 
    9997        } 
    10098 
    … …  
    118116            q.setParameter(param, params.get(param)); 
    119117        } 
     118 
    120119        q.setParameterList("ids", ids); 
    121120        setQuery(q); 

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/