本文整理了Java中org.apache.polygene.api.query.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:org.apache.polygene.api.query.Query
类名称:Query
[英]This represents a Query in an indexing system. It is created from a QueryBuilder, which decides the "where" clause in the query.
Additional limitations, such as paging, ordering, and variables, can be set on a Query before it is executed by calling one of find(), iterator(), or count().
DDD tip: typically Queries are created in the Domain Model and passed to the UI, which sets the order and paging before executing it.
[中]这表示索引系统中的查询。它是从QueryBuilder创建的,QueryBuilder决定查询中的“where”子句。
在执行查询之前,可以通过调用find()、iterator()或count()中的一个来设置其他限制,例如分页、排序和变量。
DDD提示:查询通常在域模型中创建,并传递给UI,UI在执行查询之前设置顺序和分页。
代码示例来源:origin: apache/attic-polygene-java
@Test
public void script24()
{
final QueryBuilder<Domain> qb = this.moduleInstance.newQueryBuilder( Domain.class );
final Nameable nameable = templateFor( Nameable.class );
final Query<Domain> query = unitOfWork.newQuery( qb.where( eq( nameable.name(), "Gaming" ) ) );
System.out.println( "*** script24: " + query );
assertThat( query.find().name().get(), is( equalTo( "Gaming" ) ) );
}
代码示例来源:origin: apache/attic-polygene-java
@Override
public void expect()
throws Exception
{
assertThat( query.count(), equalTo(1) );
Male male = query.find();
assertThat( male.title().get(), equalTo( Person.Title.MR ));
}
}
代码示例来源:origin: org.apache.polygene.core/org.apache.polygene.core.testsupport
@Test
public void script20()
{
Person person = templateFor( Person.class );
final Query<Person> query = unitOfWork.newQuery( this.moduleInstance
.newQueryBuilder( Person.class )
.where( queries.get( "script20" ) ) );
query.orderBy( orderBy( person.name(), OrderBy.Order.DESCENDING ) );
System.out.println( "*** script20: " + query );
verifyOrderedResults( query, "Joe Doe", "Ann Doe" );
}
代码示例来源:origin: org.apache.polygene.core/org.apache.polygene.core.testsupport
@Test
public void script17()
{
QueryBuilder<Nameable> qb = this.moduleInstance.newQueryBuilder( Nameable.class );
// should return only 3 entities starting with forth one
Nameable nameable = templateFor( Nameable.class );
Query<Nameable> query = unitOfWork.newQuery( qb );
query.orderBy( orderBy( nameable.name() ) );
query.firstResult( 3 );
query.maxResults( 2 );
System.out.println( "*** script17: " + query );
verifyOrderedResults( query, "Felix", "Gaming" );
}
代码示例来源:origin: org.apache.polygene.core/org.apache.polygene.core.testsupport
@Test
public void script24()
{
final Query<Domain> query = unitOfWork.newQuery( this.moduleInstance
.newQueryBuilder( Domain.class )
.where( queries.get( "script24" ) ) );
query.setVariable( "domain", "Gaming" );
System.out.println( "*** script24: " + query );
assertThat( query.find().name().get(), is( equalTo( "Gaming" ) ) );
}
}
代码示例来源:origin: org.apache.polygene.core/org.apache.polygene.core.testsupport
@Test
public void script16()
{
QueryBuilder<Nameable> qb = this.moduleInstance.newQueryBuilder( Nameable.class );
// should return only 2 entities
Nameable nameable = templateFor( Nameable.class );
Query<Nameable> query = unitOfWork.newQuery( qb );
query.orderBy( orderBy( nameable.name() ) );
query.maxResults( 2 );
System.out.println( "*** script16: " + query );
verifyOrderedResults( query, "Ann Doe", "Cars" );
}
代码示例来源:origin: apache/attic-polygene-java
query.orderBy( orderBy( template.methodName() ) );
Iterator<TraceRecord> result = query.iterator();
assertTrue( result.hasNext() );
TraceRecord rec1 = result.next();
代码示例来源:origin: apache/attic-polygene-java
Query<MyEntity> q = uow.newQuery( qBuilder );
assertEquals( 1, q.count() );
assertEquals( TEST_NAME, q.iterator().next().name().get() );
代码示例来源:origin: apache/attic-polygene-java
private void doRemove( int howMany )
{
Iterator<ExampleEntity> iter = this.unitOfWorkFactory.currentUnitOfWork().newQuery( this.queryBuilderFactory.newQueryBuilder( ExampleEntity.class )).maxResults( howMany ).iterator();
Integer removed = 0;
while (iter.hasNext())
{
this.unitOfWorkFactory.currentUnitOfWork().remove( iter.next() );
++removed;
}
if (removed != howMany)
{
LOG.warn( "Removed " + removed + " entities instead of " + howMany + "." );
}
}
代码示例来源:origin: apache/attic-polygene-java
private void verifyOrder( Query<TestComposite> query, String expected )
{
String actual = "";
for( TestComposite testComposite : query )
{
actual = actual + testComposite.b().get();
}
assertThat( "Query is correct", actual, equalTo( expected ) );
assertThat( "Count is correct", query.count(), equalTo( (long) expected.length() ) );
}
代码示例来源:origin: apache/attic-polygene-java
private List<ExampleEntity> doList( int howMany )
{
List<ExampleEntity> list = new ArrayList<ExampleEntity>();
UnitOfWork uow = this.unitOfWorkFactory.newUnitOfWork();
Iterator<ExampleEntity> iter = uow.newQuery( this.queryBuilderFactory.newQueryBuilder( ExampleEntity.class ) ).iterator();
int found = 0;
while (iter.hasNext())
{
found++;
ExampleEntity exampleEntity = iter.next();
if (exampleEntity != null)
list.add( exampleEntity );
}
uow.discard();
if (found != howMany)
{
LOG.warn( "Found " + found + " entities instead of " + howMany + "." );
}
return list;
}
代码示例来源:origin: apache/attic-polygene-java
@Test
public void givenPlainQueryWhenMaxedResultExpectLimitedResult()
{
Query<TestComposite> query = queryBuilderFactory.newQueryBuilder( TestComposite.class ).newQuery( composites );
query.maxResults( 5 );
verifyOrder( query, "62345" );
}
代码示例来源:origin: apache/attic-polygene-java
@Test
public void givenPlainQueryWhenFirstResultIsBeyondFirstElementExpectLimitedResult()
{
Query<TestComposite> query = queryBuilderFactory.newQueryBuilder( TestComposite.class ).newQuery( composites );
query.firstResult( 2 );
verifyOrder( query, "3451" );
}
代码示例来源:origin: apache/attic-polygene-java
@Test
public void script17()
{
QueryBuilder<Nameable> qb = this.moduleInstance.newQueryBuilder( Nameable.class );
// should return only 3 entities starting with forth one
Nameable nameable = templateFor( Nameable.class );
Query<Nameable> query = unitOfWork.newQuery( qb );
query.orderBy( orderBy( nameable.name() ) );
query.firstResult( 3 );
query.maxResults( 2 );
System.out.println( "*** script17: " + query );
verifyOrderedResults( query, "Felix", "Gaming" );
}
代码示例来源:origin: apache/attic-polygene-java
@Test
public void script16()
{
QueryBuilder<Nameable> qb = this.moduleInstance.newQueryBuilder( Nameable.class );
// should return only 2 entities
Nameable nameable = templateFor( Nameable.class );
Query<Nameable> query = unitOfWork.newQuery( qb );
query.orderBy( orderBy( nameable.name() ) );
query.maxResults( 2 );
System.out.println( "*** script16: " + query );
verifyOrderedResults( query, "Ann Doe", "Cars" );
}
代码示例来源:origin: apache/attic-polygene-java
@Test
public void script24()
{
final Query<Domain> query = unitOfWork.newQuery( this.moduleInstance
.newQueryBuilder( Domain.class )
.where( queries.get( "script24" ) ) );
query.setVariable( "domain", "Gaming" );
System.out.println( "*** script24: " + query );
assertThat( query.find().name().get(), is( equalTo( "Gaming" ) ) );
}
}
代码示例来源:origin: apache/attic-polygene-java
query.orderBy( orderBy( template.manufacturer() ), orderBy( template.model() ) );
Iterator<Car> cars = query.iterator();
Assert.assertTrue( cars.hasNext() );
Car car1 = cars.next();
代码示例来源:origin: apache/attic-polygene-java
Query<ExampleEntity> query = uow.newQuery( this.queryBuilderFactory.newQueryBuilder( ExampleEntity.class ).
where( QueryExpressions.contains( QueryExpressions.templateFor( ExampleEntity.class ).manyAssoc(), entity50) ));
System.out.println(query.count());
代码示例来源:origin: apache/attic-polygene-java
@Test
public void whenTraceOnMixinTypeMethodExpectOneEntryInEntityStore()
throws Exception
{
SomeService sc = serviceFinder.findService( SomeService.class ).get();
assertEquals( 123, sc.doSomethingImportant() );
assertEquals( 456, sc.doSomethingLessImportant() );
UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
QueryBuilder<TraceRecord> builder = queryBuilderFactory.newQueryBuilder( TraceRecord.class );
Query<TraceRecord> query = uow.newQuery( builder );
// IS sorting needed??
// TraceRecord template = templateFor( TraceRecord.class );
// query.orderBy( orderBy( template.methodName() ) );
Iterator<TraceRecord> result = query.iterator();
assertTrue( result.hasNext() );
TraceRecord rec1 = result.next();
assertEquals( "doSomethingImportant", rec1.methodName().get() );
assertFalse( result.hasNext() );
uow.complete();
}
代码示例来源:origin: org.apache.polygene.core/org.apache.polygene.core.testsupport
@Test
public void script24()
{
final QueryBuilder<Domain> qb = this.moduleInstance.newQueryBuilder( Domain.class );
final Nameable nameable = templateFor( Nameable.class );
final Query<Domain> query = unitOfWork.newQuery( qb.where( eq( nameable.name(), "Gaming" ) ) );
System.out.println( "*** script24: " + query );
assertThat( query.find().name().get(), is( equalTo( "Gaming" ) ) );
}
内容来源于网络,如有侵权,请联系作者删除!