@Override public Results getTargetEntities( String connectionType, String connectedEntityType, Level level ) throws Exception { //until this is refactored properly, we will delegate to a search by query Results raw = null; Preconditions.checkNotNull( connectionType, "connectionType cannot be null" ); Query query = new Query(); query.setConnectionType( connectionType ); query.setEntityType( connectedEntityType ); query.setResultsLevel( level ); return searchTargetEntities( query ); }
@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 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); } }
/** * (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.setConnectionType(IMPORT_FILE_INCLUDES_CONNECTION); query.setLimit(MAX_FILE_IMPORTS);
@Override public Results getResults( Query query ) throws Exception { app.waitForQueueDrainAndRefreshIndex(); query.setConnectionType( CONNECTION ); query.setEntityType( "test" ); return app.getEntityManager().searchTargetEntities(rootEntity, query); } }
q.setConnectionType( connection );
+ ((LinkedHashMap<String, Object>) userProperties.get("location")).get("latitude") + ", " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("longitude")).setConnectionType("likes")); assertEquals(1, emSearchResults.size()); + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("latitude") + ", " + ((LinkedHashMap<String, Object>) userProperties.get("location")).get("longitude")).setConnectionType("likes")); assertEquals(0, emSearchResults.size());
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.setConnectionType( "testconnection" ); query.setEntityType( "user" );
query = new Query(); query.setConnectionType( cType ); query.setEntityType( eType ); if ( id != null ) {
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; }
query.setConnectionType( "likes" );