@Test public void script43_Date() { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query<Person> query = unitOfWork.newQuery( qb.where( and( gt( person.dateValue(), new DateTime( "2005-03-04T13:24:35", UTC ).toDate() ), lt( person.dateValue(), new DateTime( "2015-03-04T13:24:35", UTC ).toDate() ) ) ) ); System.out.println( "*** script43_Date: " + query ); verifyUnorderedResults( query, "Jack Doe" ); }
@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 script43_DateTime() { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query<Person> query = unitOfWork.newQuery( qb.where( and( gt( person.dateTimeValue(), new DateTime( "2005-03-04T13:24:35", UTC ) ), lt( person.dateTimeValue(), new DateTime( "2015-03-04T13:24:35", UTC ) ) ) ) ); System.out.println( "*** script43_DateTime: " + query ); verifyUnorderedResults( query, "Jack Doe" ); }
@Test public void script43_LocalDate() { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query<Person> query = unitOfWork.newQuery( qb.where( and( gt( person.localDateValue(), new LocalDate( "2005-03-04", UTC ) ), lt( person.localDateValue(), new LocalDate( "2015-03-04", UTC ) ) ) ) ); System.out.println( "*** script43_LocalDate: " + query ); verifyUnorderedResults( query, "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 script43_LocalDateTime() { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query<Person> query = unitOfWork.newQuery( qb.where( and( gt( person.localDateTimeValue(), new LocalDateTime( "2005-03-04T13:24:35", UTC ) ), lt( person.localDateTimeValue(), new LocalDateTime( "2015-03-04T13:24:35", UTC ) ) ) ) ); System.out.println( "*** script43_LocalDateTime: " + query ); verifyUnorderedResults( query, "Jack Doe" ); }
@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 ); }