/** * Create a new Query ascending order segment for a Property. * * @param <T> type of the Property * @param property a Property * * @return a new Query ascending order segment for a Property. */ public static <T> OrderBy orderBy( final Property<T> property ) { return orderBy( property, OrderBy.Order.ASCENDING ); }
@Test public void script19() throws EntityFinderException { // should return all Nameable entities with a name > "B" sorted by name Nameable nameable = templateFor( Nameable.class ); List<String> largerThanB = new ArrayList<>(); for( String name : NameableAssert.allNames() ) { if( name.compareTo( "B" ) > 0 ) { largerThanB.add( name ); } } Collections.sort( largerThanB ); Iterable<EntityReference> entities = entityFinder.findEntities( Nameable.class, gt( nameable.name(), "B" ), new OrderBy[] { orderBy( nameable.name() ) }, NO_FIRST_RESULT, NO_MAX_RESULTS, NO_VARIABLES ); assertNames( false, entities, largerThanB.toArray( new String[ largerThanB.size() ] ) ); }
@Test public void script21() throws EntityFinderException { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); // should return all Persons sorted by name of the city they were born, and then by year they were born Person person = templateFor( Person.class ); Query<Person> query = unitOfWork.newQuery( qb ); query.orderBy( orderBy( person.placeOfBirth().get().name() ), orderBy( person.yearOfBirth() ) ); System.out.println( "*** script21: " + query ); verifyOrderedResults( query, "Ann Doe", "Joe Doe", "Jack Doe" ); }
@Test public void script20() throws EntityFinderException { Person person = templateFor( Person.class ); final Query<Person> query = unitOfWork.newQuery( this.module .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" ); }
@Test public void script21() throws EntityFinderException { // should return all Persons sorted name of the city they were born Person person = templateFor( Person.class ); Iterable<EntityReference> entities = entityFinder.findEntities( Person.class, ALL, new OrderBy[] { orderBy( person.placeOfBirth().get().name() ), orderBy( person.name() ) }, NO_FIRST_RESULT, NO_MAX_RESULTS, NO_VARIABLES ); assertNames( false, entities, ANN, JOE, JACK ); }
@Test public void script18() throws EntityFinderException { Nameable nameable = templateFor( Nameable.class ); final Query<Nameable> query = unitOfWork.newQuery( this.module .newQueryBuilder( Nameable.class ) .where( queries.get( "script18" ) ) ); query.orderBy( orderBy( nameable.name() ) ); System.out.println( "*** script18: " + query ); verifyOrderedResults( query, "Ann Doe", "Cars", "Cooking", "Gaming", "Jack Doe", "Joe Doe", "Kuala Lumpur", "Penang", "Programming" ); }
@Test public void script19() throws EntityFinderException { Nameable nameable = templateFor( Nameable.class ); final Query<Nameable> query = unitOfWork.newQuery( this.module .newQueryBuilder( Nameable.class ) .where( queries.get( "script19" ) ) ); query.orderBy( orderBy( nameable.name() ) ); System.out.println( "*** script19: " + query ); verifyOrderedResults( query, "Gaming", "Jack Doe", "Joe Doe", "Kuala Lumpur", "Penang", "Programming" ); }
@Test public void script21() throws EntityFinderException { Person person = templateFor( Person.class ); final Query<Person> query = unitOfWork.newQuery( this.module .newQueryBuilder( Person.class ) .where( queries.get( "script21" ) ) ); query.orderBy( orderBy( person.placeOfBirth().get().name() ), orderBy( person.yearOfBirth() ) ); System.out.println( "*** script21: " + query ); verifyOrderedResults( query, "Ann Doe", "Joe Doe", "Jack Doe" ); }
@Test public void script16() throws EntityFinderException { Nameable nameable = templateFor( Nameable.class ); final Query<Nameable> query = unitOfWork.newQuery( this.module .newQueryBuilder( Nameable.class ) .where( queries.get( "script16" ) ) ); query.orderBy( orderBy( nameable.name() ) ); query.maxResults( 2 ); System.out.println( "*** script16: " + query ); verifyOrderedResults( query, "Ann Doe", "Cars" ); }
@Test public void script18() throws EntityFinderException { QueryBuilder<Nameable> qb = this.module.newQueryBuilder( Nameable.class ); // should return all Nameable entities sorted by name Nameable nameable = templateFor( Nameable.class ); Query<Nameable> query = unitOfWork.newQuery( qb ); query.orderBy( orderBy( nameable.name() ) ); System.out.println( "*** script18: " + query ); verifyOrderedResults( query, "Ann Doe", "Cars", "Cooking", "Gaming", "Jack Doe", "Joe Doe", "Kuala Lumpur", "Penang", "Programming" ); }
@Test public void script18() throws EntityFinderException { // should return all Nameable entities sorted by name Nameable nameable = templateFor( Nameable.class ); final String[] allNames = NameableAssert.allNames(); Arrays.sort( allNames ); Iterable<EntityReference> entities = entityFinder.findEntities( Nameable.class, ALL, new OrderBy[] { orderBy( nameable.name() ) }, NO_FIRST_RESULT, NO_MAX_RESULTS, NO_VARIABLES ); assertNames( false, entities, allNames ); }
@Test public void script17() throws EntityFinderException { Nameable nameable = templateFor( Nameable.class ); final Query<Nameable> query = unitOfWork.newQuery( this.module .newQueryBuilder( Nameable.class ) .where( queries.get( "script17" ) ) ); query.orderBy( orderBy( nameable.name() ) ); query.firstResult( 3 ); query.maxResults( 3 ); System.out.println( "*** script17: " + query ); verifyOrderedResults( query, "Gaming", "Jack Doe", "Joe Doe" ); }
@Test public void script16() throws EntityFinderException { QueryBuilder<Nameable> qb = this.module.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" ); }
@Test public void script17() throws EntityFinderException { QueryBuilder<Nameable> qb = this.module.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, "Gaming", "Jack Doe" ); }
@Test public void script20() throws EntityFinderException { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); // should return all Persons born after 1973 (Ann and Joe Doe) sorted descending by name Person person = templateFor( Person.class ); Query<Person> query = unitOfWork.newQuery( qb.where( gt( person.yearOfBirth(), 1973 ) ) ); query.orderBy( orderBy( person.name(), OrderBy.Order.DESCENDING ) ); System.out.println( "*** script20: " + query ); verifyOrderedResults( query, "Joe Doe", "Ann Doe" ); }
@Test public void script19() throws EntityFinderException { QueryBuilder<Nameable> qb = this.module.newQueryBuilder( Nameable.class ); // should return all Nameable entities with a name > "D" sorted by name Nameable nameable = templateFor( Nameable.class ); Query<Nameable> query = unitOfWork.newQuery( qb.where( gt( nameable.name(), "D" ) ) ); query.orderBy( orderBy( nameable.name() ) ); System.out.println( "*** script19: " + query ); verifyOrderedResults( query, "Gaming", "Jack Doe", "Joe Doe", "Kuala Lumpur", "Penang", "Programming" ); }
@Test public void script20() throws EntityFinderException { // should return all Persons born after 1973 (Ann and Joe Doe) sorted descending by name Person person = templateFor( Person.class ); Iterable<EntityReference> entities = entityFinder.findEntities( Person.class, gt( person.yearOfBirth(), 1973 ), new OrderBy[] { orderBy( person.name(), OrderBy.Order.DESCENDING ) }, NO_FIRST_RESULT, NO_MAX_RESULTS, NO_VARIABLES ); assertNames( false, entities, JOE, ANN ); }