public Query withLimit( int limit ) { setLimit( limit ); return this; }
@Override public Results getCollection( String collectionName, UUID startResult, int count, Level resultsLevel, boolean reversed ) throws Exception { final String ql; if (startResult != null ) { // UUID timestamp is a different measure than 'created' field on entities Calendar uuidEpoch = Calendar.getInstance(TimeZone.getTimeZone("UTC")); uuidEpoch.clear(); uuidEpoch.set(1582, 9, 15, 0, 0, 0); // 9 = October long epochMillis = uuidEpoch.getTime().getTime(); long time = (startResult.timestamp() / 10000L) + epochMillis; if ( !reversed ) { ql = "select * where created > " + time; } else { ql = "select * where created < " + time; } } else { ql = "select *"; } Query query = Query.fromQL( ql ); if(query == null ){ throw new RuntimeException("Unable to get data for collection: "+collectionName); } query.setLimit( count ); query.setReversed( reversed ); return searchCollection( collectionName, query ); }
private int getConnectionCount(final Import importRoot) { try { EntityManager rootEM = emf.getEntityManager(emf.getManagementAppId()); Query query = Query.fromQL("select *"); query.setEntityType("file_import"); query.setConnectionType(IMPORT_FILE_INCLUDES_CONNECTION); query.setLimit(MAX_FILE_IMPORTS); // TODO, this won't work with more than 100 files Results entities = rootEM.searchTargetEntities(importRoot, query); return entities.size(); // see ImportConnectsTest() // Results entities = rootEM.getTargetEntities( // importRoot, "includes", null, Level.ALL_PROPERTIES ); // PagingResultsIterator itr = new PagingResultsIterator( entities ); // int count = 0; // while ( itr.hasNext() ) { // itr.next(); // count++; // } // return count; } catch (Exception e) { logger.error("application doesn't exist within the current context"); throw new RuntimeException(e); } }
protected void singleOrderByNoIntersection( IoHelper io ) throws Exception { io.doSetup(); int size = 20; int queryLimit = Query.MAX_LIMIT; // the number of entities that should be written including an intersection int secondIncrement = 9; long start = System.currentTimeMillis(); logger.info( "Writing {} entities.", size ); for ( int i = 0; i < size; i++ ) { Map<String, Object> entity = new HashMap<String, Object>(); entity.put( "name", String.valueOf( i ) ); // if we hit the increment, set this to true entity.put( "intersect", false ); entity.put( "intersect2", i % secondIncrement == 0 ); io.writeEntity( entity ); } long stop = System.currentTimeMillis(); logger.info( "Writes took {} ms", stop - start ); Query query = Query.fromQL( "select * where intersect = true AND intersect2 = true order by created" ); query.setLimit( queryLimit ); start = System.currentTimeMillis(); Results results = io.getResults( query ); // now do simple ordering, should be returned in order stop = System.currentTimeMillis(); logger.info( "Query took {} ms to return {} entities", stop - start, 0 ); assertEquals( 0, results.size() ); }
query.setLimit( queryLimit );
query.setLimit( PAGE_SIZE );
query.setLimit( queryLimit );
query.setLimit( queryLimit );
query.setLimit( PAGE_SIZE );
query.setLimit( 10 );
query.setLimit( PAGE_SIZE );
protected List<EntityRef> getNotificationReceipts(EntityRef notification) throws Exception { Query query = new Query(); query.setCollection("receipts"); query.setLimit(100); PathQuery<Receipt> pathQuery = new PathQuery<Receipt>( new SimpleEntityRef(app.getEntityManager().getApplicationRef()), query ); Iterator<Receipt> it = pathQuery.iterator(app.getEntityManager()); List<EntityRef> list =new ArrayList<EntityRef>();//get all while(it.hasNext()){ Receipt receipt =it.next(); if(receipt.getNotificationUUID().equals(notification.getUuid())) { list.add(receipt); } } return list; }
query.setLimit(limit);
query.setLimit( pageSize );
private int getConnectionCountViaSearch( final Import importRoot ) { try { EntityManager emMgmtApp = setup.getEmf() .getEntityManager(setup.getEmf().getManagementAppId() ); Query query = Query.fromQL("select *"); query.setEntityType("file_import"); query.setConnectionType("includes"); query.setLimit(10000); Results entities = emMgmtApp.searchTargetEntities(importRoot, query); return entities.size(); // PagingResultsIterator itr = new PagingResultsIterator( entities ); // int count = 0; // while ( itr.hasNext() ) { // itr.next(); // count++; // } // return count; } catch ( Exception e ) { logger.error( "application doesn't exist within the current context" ); throw new RuntimeException( e ); } } }
query.setLimit( pageSize );
@Override public ServiceResults putItemsByQuery( ServiceContext context, Query query ) throws Exception { checkPermissionsForCollection( context ); if ( context.moreParameters() ) { return getItemsByQuery( context, query ); } query = new Query( query ); query.setResultsLevel( Level.ALL_PROPERTIES ); query.setLimit( 1000 ); if ( !query.isReversedSet() ) { query.setReversed( isCollectionReversed( context ) ); } Results r = em.searchCollection( context.getOwner(), context.getCollectionName(), query ); if ( r.isEmpty() ) { throw new ServiceResourceNotFoundException( context ); } updateEntities( context, r ); return new ServiceResults( this, context, Type.COLLECTION, r, null, null ); }
query.setLimit( pageSize );
@Override public ServiceResults deleteItemsByQuery( ServiceContext context, Query query ) throws Exception { checkPermissionsForCollection( context ); if ( context.moreParameters() ) { return getItemsByQuery( context, query ); } query = new Query( query ); query.setResultsLevel( Level.ALL_PROPERTIES ); query.setLimit( query.getLimit() ); if ( !query.isReversedSet() ) { query.setReversed( isCollectionReversed( context ) ); } Results r = em.searchCollection( context.getOwner(), context.getCollectionName(), query ); importEntities( context, r ); for ( Entity entity : r ) { prepareToDelete( context, entity ); } for ( Entity entity : r ) { em.removeFromCollection( context.getOwner(), context.getCollectionName(), entity ); } return new ServiceResults( this, context, Type.COLLECTION, r, null, null ); }
query.setLimit( query.getLimit( count ) );