本文整理了Java中org.apache.usergrid.persistence.Query.fromQL
方法的一些代码示例,展示了Query.fromQL
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.fromQL
方法的具体详情如下:
包路径:org.apache.usergrid.persistence.Query
类名称:Query
方法名:fromQL
[英]Create a query instance from the QL. If the string is null, return an empty query
[中]从QL创建一个查询实例。如果字符串为null,则返回一个空查询
代码示例来源:origin: apache/usergrid
/**
* Create a query from a property equals
* @param propertyName
* @param value
* @return
*/
public static Query fromEquals(final String propertyName, final String value){
return fromQL( propertyName + " = '" + value + "'" );
}
代码示例来源:origin: apache/usergrid
public static Query all( ){
return fromQL("select *");
}
代码示例来源:origin: apache/usergrid
/**
* Create a query instance from the QL. If the string is null, return an empty query
* @param ql
* @return
*/
public static Query fromQLNullSafe(final String ql){
final Query query = fromQL(ql);
if(query != null){
return query;
}
return new Query();
}
代码示例来源:origin: apache/usergrid
private EntityRef getRoleRef( String roleName ) throws Exception {
Results results = this.searchCollection( new SimpleEntityRef( Application.ENTITY_TYPE, applicationId ),
Schema.defaultCollectionName( Role.ENTITY_TYPE ), Query.fromQL( "roleName = '" + roleName + "'" ) );
Iterator<Entity> iterator = results.iterator();
EntityRef roleRef = null;
while ( iterator.hasNext() ) {
roleRef = iterator.next();
}
return roleRef;
}
代码示例来源:origin: apache/usergrid
@Override
public EntityRef getGroupRoleRef( UUID groupId, String roleName ) throws Exception {
Results results = this.searchCollection( new SimpleEntityRef( Group.ENTITY_TYPE, groupId ),
Schema.defaultCollectionName( Role.ENTITY_TYPE ), Query.fromQL( "roleName = '" + roleName + "'" ) );
Iterator<Entity> iterator = results.iterator();
EntityRef roleRef = null;
while ( iterator.hasNext() ) {
roleRef = iterator.next();
}
return roleRef;
}
代码示例来源:origin: apache/usergrid
@Override
public Map<String, String> getServiceProperties() {
Map<String, String> props = new HashMap<String,String>();
EntityManager em = getEntityManager(getManagementAppId());
Query q = Query.fromQL("select *");
Results results = null;
try {
results = em.searchCollection( em.getApplicationRef(), "propertymaps", q);
} catch (Exception ex) {
logger.error("Error getting system properties", ex);
}
if ( results == null || results.isEmpty() ) {
return props;
}
org.apache.usergrid.persistence.Entity e = results.getEntity();
for ( String key : e.getProperties().keySet() ) {
props.put( key, props.get(key).toString() );
}
return props;
}
代码示例来源:origin: apache/usergrid
@Override
public JobStat getStatsForJob( String jobName, UUID jobId ) throws Exception {
EntityManager em = emf.getEntityManager( emf.getManagementAppId() );
Query query = Query.fromQL( "select * where " + JOB_NAME + " = '" + jobName + "' AND " + JOB_ID + " = " + jobId );
Results r = em.searchCollection( em.getApplicationRef(), "job_stats", query );
if ( r.size() == 1 ) {
return ( JobStat ) r.getEntity();
}
return null;
}
代码示例来源:origin: apache/usergrid
@Test
public void testKeywordsOrQuery() throws Exception {
logger.debug( "testKeywordsOrQuery" );
EntityManager em = app.getEntityManager();
assertNotNull( em );
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "title", "Galactians 2" );
properties.put( "keywords", "Hot, Space Invaders, Classic" );
em.create( "game", properties );
properties = new LinkedHashMap<String, Object>();
properties.put( "title", "Bunnies Extreme" );
properties.put( "keywords", "Hot, New" );
em.create( "game", properties );
properties = new LinkedHashMap<String, Object>();
properties.put( "title", "Hot Shots" );
properties.put("keywords", "Action, New");
em.create( "game", properties );
app.waitForQueueDrainAndRefreshIndex();
Query query = Query.fromQL( "select * where keywords contains 'hot' or title contains 'hot'" );
Results r = em.searchCollection( em.getApplicationRef(), "games", query );
logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
assertEquals( 3, r.size() );
}
代码示例来源:origin: apache/usergrid
/**
* Go around EntityManager and execute query directly against Core Persistence.
* Results may include stale index entries.
*/
private Results queryCollectionEm( final String collName, final String query ) throws Exception {
EntityManager em = app.getEntityManager();
final Results results = em.searchCollection( em.getApplicationRef(), collName, Query.fromQL( query ).withLimit( 10000 ) );
return results;
}
}
代码示例来源:origin: apache/usergrid
@Test
public void testCreateAndDelete() throws Exception {
logger.info( "EntityDaoTest.testCreateAndDelete" );
EntityManager em = app.getEntityManager();
String name = "test.thing" + UUIDUtils.newTimeUUID();
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "name", name );
properties.put( "foo", "bar" );
logger.info( "Starting entity create" );
Entity thing = em.create( "thing", properties );
logger.info( "Entity created" );
app.waitForQueueDrainAndRefreshIndex();
logger.info( "Starting entity delete" );
em.delete( thing );
logger.info( "Entity deleted" );
app.waitForQueueDrainAndRefreshIndex();
// now search by username, no results should be returned
final Query emailQuery = Query.fromQL( "name = '" + name + "'" );
Results r = em.searchCollection( em.getApplicationRef(), "thing", emailQuery );
assertEquals( 0, r.size() );
}
代码示例来源:origin: apache/usergrid
@Test
public void stringWithSpaces() throws Exception {
EntityManager em = app.getEntityManager();
assertNotNull( em );
logger.debug( "stringWithSpaces" );
Map<String, Object> props = new HashMap<String, Object>();
props.put( "myString", "My simple string" );
Entity saved = em.create( "test", props );
app.waitForQueueDrainAndRefreshIndex();
Query query = Query.fromQL( "myString = 'My simple string'" );
Results results = em.searchCollection( em.getApplicationRef(), "tests", query );
Entity entity = results.getEntitiesMap().get( saved.getUuid() );
assertNotNull( entity );
}
代码示例来源:origin: apache/usergrid
@Test
public void testRedefineTerms() throws Exception {
logger.debug( "testRedefineTerms" );
EntityManager em = app.getEntityManager();
assertNotNull( em );
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "username", "edanuff" );
properties.put( "email", "ed@anuff.com" );
em.create( "user", properties );
app.waitForQueueDrainAndRefreshIndex();
String s = "select {name: username, email: email} where username = 'edanuff'";
Query query = Query.fromQL( s );
Results r = em.searchCollection( em.getApplicationRef(), "users", query );
assertTrue( r.size() == 1 );
// TODO: do we need selection results?
// selection results should be a list of lists
// List<Object> sr = query.getSelectionResults( r );
// assertTrue( sr.size() == 1 );
// Map firstResult = ( Map ) sr.get( 0 );
// assertTrue( "edanuff".equals( firstResult.get( "name" ) ) );
// assertTrue( "ed@anuff.com".equals( firstResult.get( "email" ) ) );
}
代码示例来源:origin: apache/usergrid
@Test
public void testSelectTerms() throws Exception {
logger.debug( "testSelectTerms" );
EntityManager em = app.getEntityManager();
assertNotNull( em );
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "username", "edanuff" );
properties.put( "email", "ed@anuff.com" );
em.create( "user", properties );
app.waitForQueueDrainAndRefreshIndex();
String s = "select username, email where username = 'edanuff'";
Query query = Query.fromQL( s );
Results r = em.searchCollection( em.getApplicationRef(), "users", query );
assertTrue( r.size() == 1 );
// selection results should be a list of lists
// List<Object> sr = query.getSelectionResults( r );
// assertTrue( sr.size() == 1 );
// List firstResult = ( List ) sr.get( 0 );
// assertTrue( "edanuff".equals( firstResult.get( 0 ) ) );
// assertTrue( "ed@anuff.com".equals( firstResult.get( 1 ) ) );
}
代码示例来源:origin: apache/usergrid
@Test
public void groupNameSearch() throws Exception {
logger.debug( "groupNameSearch" );
EntityManager em = app.getEntityManager();
assertNotNull( em );
String groupName = "groupName" + UUIDUtils.newTimeUUID();
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "title", "testTitle" );
properties.put( "path", "testPath" );
properties.put( "name", groupName );
Entity group = em.create( "group", properties );
assertNotNull( group );
app.waitForQueueDrainAndRefreshIndex();
// EntityRef
final Query query = Query.fromQL( "name = '" + groupName + "'" );
Results r = em.searchCollection( em.getApplicationRef(), "groups", query );
assertTrue( r.size() > 0 );
Entity returned = r.getEntities().get( 0 );
assertEquals( group.getUuid(), returned.getUuid() );
}
代码示例来源:origin: apache/usergrid
@Test
public void groupTitleSearch() throws Exception {
logger.debug( "groupTitleSearch" );
EntityManager em = app.getEntityManager();
assertNotNull( em );
String titleName = "groupName" + UUIDUtils.newTimeUUID();
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "title", titleName );
properties.put( "path", "testPath" );
properties.put( "name", "testName" );
Entity group = em.create( "group", properties );
assertNotNull( group );
app.waitForQueueDrainAndRefreshIndex();
// EntityRef
final Query query = Query.fromQL( "title = '" + titleName + "'" );
Results r = em.searchCollection( em.getApplicationRef(), "groups", query );
assertTrue( r.size() > 0 );
Entity returned = r.getEntities().get( 0 );
assertEquals( group.getUuid(), returned.getUuid() );
}
代码示例来源:origin: apache/usergrid
@Test
public void userLastNameSearch() throws Exception {
logger.debug( "userLastNameSearch" );
EntityManager em = app.getEntityManager();
assertNotNull( em );
String lastName = "lastName" + UUIDUtils.newTimeUUID();
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "username", "edanuff" );
properties.put( "email", "ed@anuff.com" );
properties.put( "lastname", lastName );
Entity user = em.create( "user", properties );
assertNotNull( user );
app.waitForQueueDrainAndRefreshIndex();
// EntityRef
final Query query = Query.fromQL( "lastname = '" + lastName + "'" );
Results r = em.searchCollection( em.getApplicationRef(), "users", query );
assertTrue( r.size() > 0 );
Entity returned = r.getEntities().get( 0 );
assertEquals( user.getUuid(), returned.getUuid() );
}
代码示例来源:origin: apache/usergrid
@Test
public void userMiddleNameSearch() throws Exception {
logger.debug( "userMiddleNameSearch" );
EntityManager em = app.getEntityManager();
assertNotNull( em );
String middleName = "middleName" + UUIDUtils.newTimeUUID();
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "username", "edanuff" );
properties.put( "email", "ed@anuff.com" );
properties.put( "middlename", middleName );
Entity user = em.create( "user", properties );
assertNotNull( user );
app.waitForQueueDrainAndRefreshIndex();
// EntityRef
final Query query = Query.fromQL( "middlename = '" + middleName + "'" );
Results r = em.searchCollection( em.getApplicationRef(), "users", query );
assertTrue( r.size() > 0 );
Entity returned = r.getEntities().get( 0 );
assertEquals( user.getUuid(), returned.getUuid() );
}
代码示例来源:origin: apache/usergrid
private void checkApplicationsOk( String orgName) throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("\n\nChecking applications OK\n");
}
for (int i=0; i<10; i++) {
String appName = orgName + "/application" + i;
UUID uuid = setup.getEmf().lookupApplication(appName);
assertTrue ("Should be able to get application", uuid != null );
EntityManager em = setup.getEmf().getEntityManager( uuid );
Application app = em.getApplication();
assertEquals( appName, app.getName() );
Results results = em.searchCollection(
em.getApplicationRef(), "things", Query.fromQL("select *"));
assertEquals( "Should have 10 entities", 10, results.size() );
}
}
代码示例来源:origin: apache/usergrid
private int countEntities( EntityManager em, String collectionName, int expectedEntities)
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 ) {
count += results.size();
if ( results.hasCursor() ) {
logger.info( "Counted {} : query again with cursor", count );
q.setCursor( results.getCursor() );
results = em.searchCollection( em.getApplicationRef(), collectionName, q );
}
else {
break;
}
}
assertEquals( "Did not get expected entities", expectedEntities, count );
return count;
}
代码示例来源:origin: apache/usergrid
private int countEntities( EntityManager em, String collectionName, int expectedEntities)
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 ) {
count += results.size();
if ( results.hasCursor() ) {
logger.info( "Counted {} : query again with cursor", count );
q.setCursor( results.getCursor() );
results = em.searchCollection( em.getApplicationRef(), collectionName, q );
}
else {
break;
}
}
assertEquals( "Did not get expected entities", expectedEntities, count );
return count;
}
内容来源于网络,如有侵权,请联系作者删除!