@Override public Results getFailedImportEntities(final UUID applicationId, final UUID importId, final UUID fileImportId, @Nullable final String ql, @Nullable final String cursor) { Preconditions.checkNotNull(applicationId, "applicationId must be specified"); Preconditions.checkNotNull(importId, "importId must be specified"); Preconditions.checkNotNull(fileImportId, "fileImportId must be specified"); try { final EntityManager rootEm = emf.getEntityManager(emf.getManagementAppId()); final FileImport importEntity = getFileImport(applicationId, importId, fileImportId); Query query = Query.fromQLNullSafe(ql); query.setCursor(cursor); query.setConnectionType(FileImportTracker.ERRORS_CONNECTION_NAME); query.setResultsLevel(Level.ALL_PROPERTIES); //set our entity type query.setEntityType(Schema.getDefaultSchema().getEntityType(FailedImportEntity.class)); return rootEm.searchTargetEntities(importEntity, query); } catch (Exception e) { throw new RuntimeException("Unable to get import entity", e); } }
@Override public Results getFileImports(final UUID applicationId, final UUID importId, @Nullable final String ql, @Nullable final String cursor) { Preconditions.checkNotNull(applicationId, "applicationId must be specified"); Preconditions.checkNotNull(importId, "importId must be specified"); try { final EntityManager rootEm = emf.getEntityManager(emf.getManagementAppId()); final Import importEntity = getImport(applicationId, importId); Query query = Query.fromQLNullSafe(ql); query.setCursor(cursor); query.setConnectionType(IMPORT_FILE_INCLUDES_CONNECTION); query.setResultsLevel(Level.ALL_PROPERTIES); //set our entity type query.setEntityType(Schema.getDefaultSchema().getEntityType(FileImport.class)); return rootEm.searchTargetEntities(importEntity, query); } catch (Exception e) { throw new RuntimeException("Unable to get import entity", e); } }
private Results getResultsFor( EntityRef ref ) { entityRef.setUUID(ref.getUuid()); entityRef.setType(ref.getType()); try { return ( query.getCollection() != null ) ? entityManager.searchCollection( entityRef, query.getCollection(), query ) : entityManager.searchTargetEntities(entityRef, query); } catch ( Exception e ) { throw new RuntimeException( e ); } }
em.searchTargetEntities(ref, 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); } }
Results r = em.searchTargetEntities(context.getOwner(), query); if ( r.isEmpty() ) { throw new ServiceResourceNotFoundException( context );
/** * (non-Javadoc) @see org.apache.usergrid.persistence.query.SingleOrderByMaxLimitCollection * .ConnectionHelper#getResults * (org.apache.usergrid.persistence.Query) */ @Override public Results getResults( Query query ) throws Exception { query.setConnectionType( CONNECTION ); // don't set it on purpose query.setEntityType( null ); return app.getEntityManager().searchTargetEntities(rootEntity, query); } }
query.setLimit(MAX_FILE_IMPORTS); Results entities = rootEM.searchTargetEntities(importEntity, query); PagingResultsIterator itr = new PagingResultsIterator(entities);
@Override public Results getResults( Query query ) throws Exception { app.waitForQueueDrainAndRefreshIndex(); query.setConnectionType( CONNECTION ); query.setEntityType( "test" ); return app.getEntityManager().searchTargetEntities(rootEntity, query); } }
return entityManager.searchTargetEntities(ref, query);
Results emSearchResults = em.searchTargetEntities(user, Query.fromQL("location within 5000 of " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("latitude") assertEquals(1, emSearchResults.size()); emSearchResults = em.searchTargetEntities(user, Query.fromQL("location within 1000 of " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("latitude")
r = em.searchTargetEntities(context.getOwner(),query); r = em.searchTargetEntities(context.getOwner(), query);
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.setEntityType( "user" ); r = em.searchTargetEntities(foo, query);
private int readData( EntityManager em, String collectionName, int expectedEntities, int expectedConnections ) throws Exception { app.waitForQueueDrainAndRefreshIndex(); Query q = Query.fromQL( "select * where key1=1000" ).withLimit( 1000 ); Results results = em.searchCollectionConsistent( em.getApplicationRef(), collectionName, q, expectedEntities ); int count = 0; while ( true ) { for ( Entity e : results.getEntities() ) { assertEquals( 2000, e.getProperty( "key2" ) ); Results catResults = em.searchTargetEntities( e, Query.fromQL( "select *" ).setConnectionType( "herds" ) ); assertEquals( expectedConnections, catResults.size() ); if ( count % 100 == 0 ) { logger.info( "read {} entities", count ); } count++; } if ( results.hasCursor() ) { logger.info( "Counted {} : query again with cursor", count ); q.setCursor( results.getCursor() ); results = em.searchCollection( em.getApplicationRef(), collectionName, q ); } else { break; } } return count; }
Results r = em.searchTargetEntities(fredEntity, query);