@Test public void script40_Date() { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query<Person> query = unitOfWork.newQuery( qb.where( eq( person.dateValue(), new DateTime( "2010-03-04T13:24:35", UTC ).toDate() ) ) ); System.out.println( "*** script40_Date: " + 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 ); }
@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 @SuppressWarnings( "unchecked" ) public void script08() throws EntityFinderException { Person person = templateFor( Person.class ); // should return Jack and Ann Doe Iterable<EntityReference> entities = entityFinder.findEntities( Person.class, or( eq( person.yearOfBirth(), 1970 ), eq( person.yearOfBirth(), 1975 ) ), NO_SORTING, NO_FIRST_RESULT, NO_MAX_RESULTS, NO_VARIABLES ); assertNames( entities, JACK, ANN ); }
@Test public void script10() throws EntityFinderException { Person person = templateFor( Person.class ); // should return Joe and Jack Doe Iterable<EntityReference> entities = entityFinder.findEntities( Person.class, not( eq( person.yearOfBirth(), 1975 ) ), NO_SORTING, NO_FIRST_RESULT, NO_MAX_RESULTS, NO_VARIABLES ); assertNames( entities, JOE, JACK ); }
@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 script42_Date() { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query<Person> query = unitOfWork.newQuery( qb.where( ne( person.dateValue(), new DateTime( "2010-03-04T14:24:35", forID( "CET" ) ).toDate() ) ) ); System.out.println( "*** script42_Date: " + query ); verifyUnorderedResults( query, "Joe Doe" ); }
@Test @SuppressWarnings( "unchecked" ) public void script07() throws EntityFinderException { QueryBuilder<Nameable> qb = this.module.newQueryBuilder( Nameable.class ); Person person = templateFor( Person.class ); Query<Nameable> query = unitOfWork.newQuery( qb.where( and( ge( person.yearOfBirth(), 1900 ), eq( person.placeOfBirth().get().name(), "Penang" ) ) ) ); System.out.println( "*** script07: " + query ); verifyUnorderedResults( query, "Jack Doe" ); }
@Test public void script36() { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Account anns = unitOfWork.get( Account.class, "accountOfAnnDoe" ); Query<Person> query = unitOfWork.newQuery( qb.where( contains( person.accounts(), anns ) ) ); System.out.println( "*** script36: " + query ); verifyUnorderedResults( query, "Jack Doe", "Ann Doe" ); }
@Test public void script06() throws EntityFinderException { Person person = templateFor( Person.class ); // should return Joe and Ann Doe Iterable<EntityReference> entities = entityFinder.findEntities( Person.class, ge( person.yearOfBirth(), 1973 ), NO_SORTING, NO_FIRST_RESULT, NO_MAX_RESULTS, NO_VARIABLES ); assertNames( entities, JOE, ANN ); }
@Test public void script23() throws EntityFinderException { Nameable nameable = templateFor( Nameable.class ); // Try using variables Map<String, Object> variables = new HashMap<>( 1 ); variables.put( "domain", "Gaming" ); Iterable<EntityReference> entities = entityFinder.findEntities( Domain.class, eq( nameable.name(), variable( "domain" ) ), NO_SORTING, NO_FIRST_RESULT, NO_MAX_RESULTS, variables ); assertNames( entities, "Gaming" ); }
@Test @Ignore( "Wait till 1.1?" ) // Paul: I don't understand this test @SuppressWarnings( "unchecked" ) public void script30() { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); QueryParam queryParam = null; // oneOf( person.personalWebsite().get().queryParams() ); Query<Person> query = unitOfWork.newQuery( qb.where( and( eq( queryParam.name(), "foo" ), eq( queryParam.value(), "bar" ) ) ) ); System.out.println( "*** script30: " + query ); verifyUnorderedResults( query, "Jack Doe" ); }
@Test public void script23() throws EntityFinderException { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Domain interests = oneOf( person.interests() ); Query<Person> query = unitOfWork.newQuery( qb.where( eq( interests.name(), "Cars" ) ) ); System.out.println( "*** script23: " + query ); verifyOrderedResults( query, "Jack Doe" ); }
@Test public void script09() { ValueBuilder<QueryParam> queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); QueryParam param = queryParamBuilder.prototype(); param.name().set( "user" ); param.value().set( "jackdoe" ); QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Property<Collection<QueryParam>> paramsProp = templateFor( Person.class ).personalWebsite().get().queryParams(); qb = qb.where( not( contains( paramsProp, queryParamBuilder.newInstance() ) ) ); Query<Person> query = unitOfWork.newQuery( qb ); System.out.println( "*** script09: " + query ); verifyUnorderedResults( query, ANN, JOE ); }
@Test public void script15() throws EntityFinderException { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Male person = templateFor( Male.class ); Query<Person> query = unitOfWork.newQuery( qb.where( isNull( person.wife() ) ) ); System.out.println( "*** script15: " + query ); verifyUnorderedResults( query, "Joe Doe", "Ann Doe" ); }
@Test public void script11() throws EntityFinderException { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query<Person> query = unitOfWork.newQuery( qb.where( isNotNull( person.email() ) ) ); System.out.println( "*** script11: " + query ); verifyUnorderedResults( query, "Joe Doe" ); }
@Test public void script11() { ValueBuilder<QueryParam> queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); List<QueryParam> queryParams = new ArrayList<>( 2 ); QueryParam param = queryParamBuilder.prototype(); param.name().set( "user" ); param.value().set( "jackdoe" ); queryParams.add( queryParamBuilder.newInstance() ); queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); param = queryParamBuilder.prototype(); param.name().set( "password" ); param.value().set( "somepassword" ); queryParams.add( queryParamBuilder.newInstance() ); QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Property<Collection<QueryParam>> paramsProp = templateFor( Person.class ).personalWebsite().get().queryParams(); qb = qb.where( not( containsAll( paramsProp, queryParams ) ) ); Query<Person> query = unitOfWork.newQuery( qb ); System.out.println( "*** script11: " + query ); verifyUnorderedResults( query, ANN, JOE ); } }
@Test public void script35() { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query<Person> query = unitOfWork.newQuery( qb.where( containsName( person.accounts(), "anns" ) ) ); System.out.println( "*** script35: " + query ); verifyUnorderedResults( query, "Jack Doe", "Ann Doe" ); }
@Test public void script22() throws EntityFinderException { QueryBuilder<Nameable> qb = this.module.newQueryBuilder( Nameable.class ); Nameable nameable = templateFor( Nameable.class ); // should return Jack and Joe Doe Query<Nameable> query = unitOfWork.newQuery( qb.where( matches( nameable.name(), "J.*Doe" ) ) ); System.out.println( "*** script22: " + query ); verifyUnorderedResults( query, "Jack Doe", "Joe Doe" ); }
@Test public void script10() { ValueBuilder<QueryParam> queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); List<QueryParam> queryParams = new ArrayList<>( 2 ); QueryParam param = queryParamBuilder.prototype(); param.name().set( "user" ); param.value().set( "jackdoe" ); queryParams.add( queryParamBuilder.newInstance() ); queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); param = queryParamBuilder.prototype(); param.name().set( "password" ); param.value().set( "somepassword" ); queryParams.add( queryParamBuilder.newInstance() ); QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Property<Collection<QueryParam>> paramsProp = templateFor( Person.class ).personalWebsite().get().queryParams(); qb = qb.where( containsAll( paramsProp, queryParams ) ); Query<Person> query = unitOfWork.newQuery( qb ); System.out.println( "*** script10: " + query ); verifyUnorderedResults( query, JACK ); }