org.apache.usergrid.persistence.Query.fromQL()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(13.3k)|赞(0)|评价(0)|浏览(310)

本文整理了Java中org.apache.usergrid.persistence.Query.fromQL方法的一些代码示例,展示了Query.fromQL的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.fromQL方法的具体详情如下:
包路径:org.apache.usergrid.persistence.Query
类名称:Query
方法名:fromQL

Query.fromQL介绍

[英]Create a query instance from the QL. If the string is null, return an empty query
[中]从QL创建一个查询实例。如果字符串为null,则返回一个空查询

代码示例

代码示例来源:origin: apache/usergrid

  1. /**
  2. * Create a query from a property equals
  3. * @param propertyName
  4. * @param value
  5. * @return
  6. */
  7. public static Query fromEquals(final String propertyName, final String value){
  8. return fromQL( propertyName + " = '" + value + "'" );
  9. }

代码示例来源:origin: apache/usergrid

  1. public static Query all( ){
  2. return fromQL("select *");
  3. }

代码示例来源:origin: apache/usergrid

  1. /**
  2. * Create a query instance from the QL. If the string is null, return an empty query
  3. * @param ql
  4. * @return
  5. */
  6. public static Query fromQLNullSafe(final String ql){
  7. final Query query = fromQL(ql);
  8. if(query != null){
  9. return query;
  10. }
  11. return new Query();
  12. }

代码示例来源:origin: apache/usergrid

  1. private EntityRef getRoleRef( String roleName ) throws Exception {
  2. Results results = this.searchCollection( new SimpleEntityRef( Application.ENTITY_TYPE, applicationId ),
  3. Schema.defaultCollectionName( Role.ENTITY_TYPE ), Query.fromQL( "roleName = '" + roleName + "'" ) );
  4. Iterator<Entity> iterator = results.iterator();
  5. EntityRef roleRef = null;
  6. while ( iterator.hasNext() ) {
  7. roleRef = iterator.next();
  8. }
  9. return roleRef;
  10. }

代码示例来源:origin: apache/usergrid

  1. @Override
  2. public EntityRef getGroupRoleRef( UUID groupId, String roleName ) throws Exception {
  3. Results results = this.searchCollection( new SimpleEntityRef( Group.ENTITY_TYPE, groupId ),
  4. Schema.defaultCollectionName( Role.ENTITY_TYPE ), Query.fromQL( "roleName = '" + roleName + "'" ) );
  5. Iterator<Entity> iterator = results.iterator();
  6. EntityRef roleRef = null;
  7. while ( iterator.hasNext() ) {
  8. roleRef = iterator.next();
  9. }
  10. return roleRef;
  11. }

代码示例来源:origin: apache/usergrid

  1. @Override
  2. public Map<String, String> getServiceProperties() {
  3. Map<String, String> props = new HashMap<String,String>();
  4. EntityManager em = getEntityManager(getManagementAppId());
  5. Query q = Query.fromQL("select *");
  6. Results results = null;
  7. try {
  8. results = em.searchCollection( em.getApplicationRef(), "propertymaps", q);
  9. } catch (Exception ex) {
  10. logger.error("Error getting system properties", ex);
  11. }
  12. if ( results == null || results.isEmpty() ) {
  13. return props;
  14. }
  15. org.apache.usergrid.persistence.Entity e = results.getEntity();
  16. for ( String key : e.getProperties().keySet() ) {
  17. props.put( key, props.get(key).toString() );
  18. }
  19. return props;
  20. }

代码示例来源:origin: apache/usergrid

  1. @Override
  2. public JobStat getStatsForJob( String jobName, UUID jobId ) throws Exception {
  3. EntityManager em = emf.getEntityManager( emf.getManagementAppId() );
  4. Query query = Query.fromQL( "select * where " + JOB_NAME + " = '" + jobName + "' AND " + JOB_ID + " = " + jobId );
  5. Results r = em.searchCollection( em.getApplicationRef(), "job_stats", query );
  6. if ( r.size() == 1 ) {
  7. return ( JobStat ) r.getEntity();
  8. }
  9. return null;
  10. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void testKeywordsOrQuery() throws Exception {
  3. logger.debug( "testKeywordsOrQuery" );
  4. EntityManager em = app.getEntityManager();
  5. assertNotNull( em );
  6. Map<String, Object> properties = new LinkedHashMap<String, Object>();
  7. properties.put( "title", "Galactians 2" );
  8. properties.put( "keywords", "Hot, Space Invaders, Classic" );
  9. em.create( "game", properties );
  10. properties = new LinkedHashMap<String, Object>();
  11. properties.put( "title", "Bunnies Extreme" );
  12. properties.put( "keywords", "Hot, New" );
  13. em.create( "game", properties );
  14. properties = new LinkedHashMap<String, Object>();
  15. properties.put( "title", "Hot Shots" );
  16. properties.put("keywords", "Action, New");
  17. em.create( "game", properties );
  18. app.waitForQueueDrainAndRefreshIndex();
  19. Query query = Query.fromQL( "select * where keywords contains 'hot' or title contains 'hot'" );
  20. Results r = em.searchCollection( em.getApplicationRef(), "games", query );
  21. logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
  22. assertEquals( 3, r.size() );
  23. }

代码示例来源:origin: apache/usergrid

  1. /**
  2. * Go around EntityManager and execute query directly against Core Persistence.
  3. * Results may include stale index entries.
  4. */
  5. private Results queryCollectionEm( final String collName, final String query ) throws Exception {
  6. EntityManager em = app.getEntityManager();
  7. final Results results = em.searchCollection( em.getApplicationRef(), collName, Query.fromQL( query ).withLimit( 10000 ) );
  8. return results;
  9. }
  10. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void testCreateAndDelete() throws Exception {
  3. logger.info( "EntityDaoTest.testCreateAndDelete" );
  4. EntityManager em = app.getEntityManager();
  5. String name = "test.thing" + UUIDUtils.newTimeUUID();
  6. Map<String, Object> properties = new LinkedHashMap<String, Object>();
  7. properties.put( "name", name );
  8. properties.put( "foo", "bar" );
  9. logger.info( "Starting entity create" );
  10. Entity thing = em.create( "thing", properties );
  11. logger.info( "Entity created" );
  12. app.waitForQueueDrainAndRefreshIndex();
  13. logger.info( "Starting entity delete" );
  14. em.delete( thing );
  15. logger.info( "Entity deleted" );
  16. app.waitForQueueDrainAndRefreshIndex();
  17. // now search by username, no results should be returned
  18. final Query emailQuery = Query.fromQL( "name = '" + name + "'" );
  19. Results r = em.searchCollection( em.getApplicationRef(), "thing", emailQuery );
  20. assertEquals( 0, r.size() );
  21. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void stringWithSpaces() throws Exception {
  3. EntityManager em = app.getEntityManager();
  4. assertNotNull( em );
  5. logger.debug( "stringWithSpaces" );
  6. Map<String, Object> props = new HashMap<String, Object>();
  7. props.put( "myString", "My simple string" );
  8. Entity saved = em.create( "test", props );
  9. app.waitForQueueDrainAndRefreshIndex();
  10. Query query = Query.fromQL( "myString = 'My simple string'" );
  11. Results results = em.searchCollection( em.getApplicationRef(), "tests", query );
  12. Entity entity = results.getEntitiesMap().get( saved.getUuid() );
  13. assertNotNull( entity );
  14. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void testRedefineTerms() throws Exception {
  3. logger.debug( "testRedefineTerms" );
  4. EntityManager em = app.getEntityManager();
  5. assertNotNull( em );
  6. Map<String, Object> properties = new LinkedHashMap<String, Object>();
  7. properties.put( "username", "edanuff" );
  8. properties.put( "email", "ed@anuff.com" );
  9. em.create( "user", properties );
  10. app.waitForQueueDrainAndRefreshIndex();
  11. String s = "select {name: username, email: email} where username = 'edanuff'";
  12. Query query = Query.fromQL( s );
  13. Results r = em.searchCollection( em.getApplicationRef(), "users", query );
  14. assertTrue( r.size() == 1 );
  15. // TODO: do we need selection results?
  16. // selection results should be a list of lists
  17. // List<Object> sr = query.getSelectionResults( r );
  18. // assertTrue( sr.size() == 1 );
  19. // Map firstResult = ( Map ) sr.get( 0 );
  20. // assertTrue( "edanuff".equals( firstResult.get( "name" ) ) );
  21. // assertTrue( "ed@anuff.com".equals( firstResult.get( "email" ) ) );
  22. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void testSelectTerms() throws Exception {
  3. logger.debug( "testSelectTerms" );
  4. EntityManager em = app.getEntityManager();
  5. assertNotNull( em );
  6. Map<String, Object> properties = new LinkedHashMap<String, Object>();
  7. properties.put( "username", "edanuff" );
  8. properties.put( "email", "ed@anuff.com" );
  9. em.create( "user", properties );
  10. app.waitForQueueDrainAndRefreshIndex();
  11. String s = "select username, email where username = 'edanuff'";
  12. Query query = Query.fromQL( s );
  13. Results r = em.searchCollection( em.getApplicationRef(), "users", query );
  14. assertTrue( r.size() == 1 );
  15. // selection results should be a list of lists
  16. // List<Object> sr = query.getSelectionResults( r );
  17. // assertTrue( sr.size() == 1 );
  18. // List firstResult = ( List ) sr.get( 0 );
  19. // assertTrue( "edanuff".equals( firstResult.get( 0 ) ) );
  20. // assertTrue( "ed@anuff.com".equals( firstResult.get( 1 ) ) );
  21. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void groupNameSearch() throws Exception {
  3. logger.debug( "groupNameSearch" );
  4. EntityManager em = app.getEntityManager();
  5. assertNotNull( em );
  6. String groupName = "groupName" + UUIDUtils.newTimeUUID();
  7. Map<String, Object> properties = new LinkedHashMap<String, Object>();
  8. properties.put( "title", "testTitle" );
  9. properties.put( "path", "testPath" );
  10. properties.put( "name", groupName );
  11. Entity group = em.create( "group", properties );
  12. assertNotNull( group );
  13. app.waitForQueueDrainAndRefreshIndex();
  14. // EntityRef
  15. final Query query = Query.fromQL( "name = '" + groupName + "'" );
  16. Results r = em.searchCollection( em.getApplicationRef(), "groups", query );
  17. assertTrue( r.size() > 0 );
  18. Entity returned = r.getEntities().get( 0 );
  19. assertEquals( group.getUuid(), returned.getUuid() );
  20. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void groupTitleSearch() throws Exception {
  3. logger.debug( "groupTitleSearch" );
  4. EntityManager em = app.getEntityManager();
  5. assertNotNull( em );
  6. String titleName = "groupName" + UUIDUtils.newTimeUUID();
  7. Map<String, Object> properties = new LinkedHashMap<String, Object>();
  8. properties.put( "title", titleName );
  9. properties.put( "path", "testPath" );
  10. properties.put( "name", "testName" );
  11. Entity group = em.create( "group", properties );
  12. assertNotNull( group );
  13. app.waitForQueueDrainAndRefreshIndex();
  14. // EntityRef
  15. final Query query = Query.fromQL( "title = '" + titleName + "'" );
  16. Results r = em.searchCollection( em.getApplicationRef(), "groups", query );
  17. assertTrue( r.size() > 0 );
  18. Entity returned = r.getEntities().get( 0 );
  19. assertEquals( group.getUuid(), returned.getUuid() );
  20. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void userLastNameSearch() throws Exception {
  3. logger.debug( "userLastNameSearch" );
  4. EntityManager em = app.getEntityManager();
  5. assertNotNull( em );
  6. String lastName = "lastName" + UUIDUtils.newTimeUUID();
  7. Map<String, Object> properties = new LinkedHashMap<String, Object>();
  8. properties.put( "username", "edanuff" );
  9. properties.put( "email", "ed@anuff.com" );
  10. properties.put( "lastname", lastName );
  11. Entity user = em.create( "user", properties );
  12. assertNotNull( user );
  13. app.waitForQueueDrainAndRefreshIndex();
  14. // EntityRef
  15. final Query query = Query.fromQL( "lastname = '" + lastName + "'" );
  16. Results r = em.searchCollection( em.getApplicationRef(), "users", query );
  17. assertTrue( r.size() > 0 );
  18. Entity returned = r.getEntities().get( 0 );
  19. assertEquals( user.getUuid(), returned.getUuid() );
  20. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void userMiddleNameSearch() throws Exception {
  3. logger.debug( "userMiddleNameSearch" );
  4. EntityManager em = app.getEntityManager();
  5. assertNotNull( em );
  6. String middleName = "middleName" + UUIDUtils.newTimeUUID();
  7. Map<String, Object> properties = new LinkedHashMap<String, Object>();
  8. properties.put( "username", "edanuff" );
  9. properties.put( "email", "ed@anuff.com" );
  10. properties.put( "middlename", middleName );
  11. Entity user = em.create( "user", properties );
  12. assertNotNull( user );
  13. app.waitForQueueDrainAndRefreshIndex();
  14. // EntityRef
  15. final Query query = Query.fromQL( "middlename = '" + middleName + "'" );
  16. Results r = em.searchCollection( em.getApplicationRef(), "users", query );
  17. assertTrue( r.size() > 0 );
  18. Entity returned = r.getEntities().get( 0 );
  19. assertEquals( user.getUuid(), returned.getUuid() );
  20. }

代码示例来源:origin: apache/usergrid

  1. private void checkApplicationsOk( String orgName) throws Exception {
  2. if (logger.isDebugEnabled()) {
  3. logger.debug("\n\nChecking applications OK\n");
  4. }
  5. for (int i=0; i<10; i++) {
  6. String appName = orgName + "/application" + i;
  7. UUID uuid = setup.getEmf().lookupApplication(appName);
  8. assertTrue ("Should be able to get application", uuid != null );
  9. EntityManager em = setup.getEmf().getEntityManager( uuid );
  10. Application app = em.getApplication();
  11. assertEquals( appName, app.getName() );
  12. Results results = em.searchCollection(
  13. em.getApplicationRef(), "things", Query.fromQL("select *"));
  14. assertEquals( "Should have 10 entities", 10, results.size() );
  15. }
  16. }

代码示例来源:origin: apache/usergrid

  1. private int countEntities( EntityManager em, String collectionName, int expectedEntities)
  2. throws Exception {
  3. app.waitForQueueDrainAndRefreshIndex();
  4. Query q = Query.fromQL( "select * where key1=1000" ).withLimit( 1000 );
  5. Results results = em.searchCollectionConsistent( em.getApplicationRef(), collectionName, q, expectedEntities );
  6. int count = 0;
  7. while ( true ) {
  8. count += results.size();
  9. if ( results.hasCursor() ) {
  10. logger.info( "Counted {} : query again with cursor", count );
  11. q.setCursor( results.getCursor() );
  12. results = em.searchCollection( em.getApplicationRef(), collectionName, q );
  13. }
  14. else {
  15. break;
  16. }
  17. }
  18. assertEquals( "Did not get expected entities", expectedEntities, count );
  19. return count;
  20. }

代码示例来源:origin: apache/usergrid

  1. private int countEntities( EntityManager em, String collectionName, int expectedEntities)
  2. throws Exception {
  3. app.waitForQueueDrainAndRefreshIndex();
  4. Query q = Query.fromQL( "select * where key1=1000" ).withLimit( 1000 );
  5. Results results = em.searchCollectionConsistent( em.getApplicationRef(), collectionName, q, expectedEntities );
  6. int count = 0;
  7. while ( true ) {
  8. count += results.size();
  9. if ( results.hasCursor() ) {
  10. logger.info( "Counted {} : query again with cursor", count );
  11. q.setCursor( results.getCursor() );
  12. results = em.searchCollection( em.getApplicationRef(), collectionName, q );
  13. }
  14. else {
  15. break;
  16. }
  17. }
  18. assertEquals( "Did not get expected entities", expectedEntities, count );
  19. return count;
  20. }

相关文章